forked from tpgit/Leptonica
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbmpio_8c_source.html
759 lines (753 loc) · 77.2 KB
/
bmpio_8c_source.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>Leptonica: src/bmpio.c Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript">
$(document).ready(initResizable);
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body onload='searchBox.OnSelectItem(0);'>
<!-- Generated by Doxygen 1.7.3 -->
<script type="text/javascript"><!--
var searchBox = new SearchBox("searchBox", "search",false,'Search');
--></script>
<script type="text/javascript">
function hasClass(ele,cls) {
return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
}
function addClass(ele,cls) {
if (!this.hasClass(ele,cls)) ele.className += " "+cls;
}
function removeClass(ele,cls) {
if (hasClass(ele,cls)) {
var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
ele.className=ele.className.replace(reg,' ');
}
}
function toggleVisibility(linkObj) {
var base = linkObj.getAttribute('id');
var summary = document.getElementById(base + '-summary');
var content = document.getElementById(base + '-content');
var trigger = document.getElementById(base + '-trigger');
if ( hasClass(linkObj,'closed') ) {
summary.style.display = 'none';
content.style.display = 'block';
trigger.src = 'open.png';
removeClass(linkObj,'closed');
addClass(linkObj,'opened');
} else if ( hasClass(linkObj,'opened') ) {
summary.style.display = 'block';
content.style.display = 'none';
trigger.src = 'closed.png';
removeClass(linkObj,'opened');
addClass(linkObj,'closed');
}
return false;
}
</script>
<div id="top">
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td id="projectlogo"><img alt="Logo" src="moller52-tiny.jpg"></td>
<td style="padding-left: 0.5em;">
<div id="projectname">Leptonica <span id="projectnumber">1.68</span></div>
<div id="projectbrief">C Image Processing Library</div>
</td>
</tr>
</tbody>
</table>
</div>
<div id="navrow1" class="tabs">
<ul class="tablist">
<li><a href="index.html"><span>Main Page</span></a></li>
<li><a href="annotated.html"><span>Data Structures</span></a></li>
<li class="current"><a href="files.html"><span>Files</span></a></li>
<li><a href="dirs.html"><span>Directories</span></a></li>
<li id="searchli">
<div id="MSearchBox" class="MSearchBoxInactive">
<span class="left">
<img id="MSearchSelect" src="search/mag_sel.png"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
alt=""/>
<input type="text" id="MSearchField" value="Search" accesskey="S"
onfocus="searchBox.OnSearchFieldFocus(true)"
onblur="searchBox.OnSearchFieldFocus(false)"
onkeyup="searchBox.OnSearchFieldChange(event)"/>
</span><span class="right">
<a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
</span>
</div>
</li>
</ul>
</div>
<div id="navrow2" class="tabs2">
<ul class="tablist">
<li><a href="files.html"><span>File List</span></a></li>
<li><a href="globals.html"><span>Globals</span></a></li>
</ul>
</div>
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
<div id="nav-tree">
<div id="nav-tree-contents">
</div>
</div>
<div id="splitbar" style="-moz-user-select:none;"
class="ui-resizable-handle">
</div>
</div>
<script type="text/javascript">
initNavTree('bmpio_8c.html','');
</script>
<div id="doc-content">
<div class="header">
<div class="headertitle">
<h1>bmpio.c</h1> </div>
</div>
<div class="contents">
<a href="bmpio_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*====================================================================*</span>
<a name="l00002"></a>00002 <span class="comment"> - Copyright (C) 2001 Leptonica. All rights reserved.</span>
<a name="l00003"></a>00003 <span class="comment"> - This software is distributed in the hope that it will be</span>
<a name="l00004"></a>00004 <span class="comment"> - useful, but with NO WARRANTY OF ANY KIND.</span>
<a name="l00005"></a>00005 <span class="comment"> - No author or distributor accepts responsibility to anyone for the</span>
<a name="l00006"></a>00006 <span class="comment"> - consequences of using this software, or for whether it serves any</span>
<a name="l00007"></a>00007 <span class="comment"> - particular purpose or works at all, unless he or she says so in</span>
<a name="l00008"></a>00008 <span class="comment"> - writing. Everyone is granted permission to copy, modify and</span>
<a name="l00009"></a>00009 <span class="comment"> - redistribute this source code, for commercial or non-commercial</span>
<a name="l00010"></a>00010 <span class="comment"> - purposes, with the following restrictions: (1) the origin of this</span>
<a name="l00011"></a>00011 <span class="comment"> - source code must not be misrepresented; (2) modified versions must</span>
<a name="l00012"></a>00012 <span class="comment"> - be plainly marked as such; and (3) this notice may not be removed</span>
<a name="l00013"></a>00013 <span class="comment"> - or altered from any source or modified source distribution.</span>
<a name="l00014"></a>00014 <span class="comment"> *====================================================================*/</span>
<a name="l00015"></a>00015
<a name="l00016"></a>00016 <span class="comment">/*</span>
<a name="l00017"></a>00017 <span class="comment"> * bmpio.c</span>
<a name="l00018"></a>00018 <span class="comment"> *</span>
<a name="l00019"></a>00019 <span class="comment"> * Read bmp from file</span>
<a name="l00020"></a>00020 <span class="comment"> * PIX *pixReadStreamBmp()</span>
<a name="l00021"></a>00021 <span class="comment"> *</span>
<a name="l00022"></a>00022 <span class="comment"> * Write bmp to file</span>
<a name="l00023"></a>00023 <span class="comment"> * l_int32 pixWriteStreamBmp()</span>
<a name="l00024"></a>00024 <span class="comment"> *</span>
<a name="l00025"></a>00025 <span class="comment"> * Read/write to memory [only on linux]</span>
<a name="l00026"></a>00026 <span class="comment"> * PIX *pixReadMemBmp()</span>
<a name="l00027"></a>00027 <span class="comment"> * l_int32 pixWriteMemBmp()</span>
<a name="l00028"></a>00028 <span class="comment"> */</span>
<a name="l00029"></a>00029
<a name="l00030"></a>00030 <span class="preprocessor">#include <string.h></span>
<a name="l00031"></a>00031 <span class="preprocessor">#include "<a class="code" href="allheaders_8h.html" title="Includes all required Leptonica header files.">allheaders.h</a>"</span>
<a name="l00032"></a>00032 <span class="preprocessor">#include "<a class="code" href="bmp_8h.html" title="Structs for bmp file format (uncompressed)">bmp.h</a>"</span>
<a name="l00033"></a>00033
<a name="l00034"></a>00034 <span class="comment">/* --------------------------------------------*/</span>
<a name="l00035"></a>00035 <span class="preprocessor">#if USE_BMPIO </span><span class="comment">/* defined in environ.h */</span>
<a name="l00036"></a>00036 <span class="comment">/* --------------------------------------------*/</span>
<a name="l00037"></a>00037
<a name="l00038"></a><a class="code" href="bmpio_8c.html#ad518de84c6ad97174674d26b45f721b7">00038</a> <a class="code" href="struct_r_g_b_a___quad.html">RGBA_QUAD</a> <a class="code" href="bmpio_8c.html#ad518de84c6ad97174674d26b45f721b7">bwmap</a>[2] = { {255,255,255,0}, {0,0,0,0} };
<a name="l00039"></a>00039
<a name="l00040"></a>00040 <span class="preprocessor">#ifndef NO_CONSOLE_IO</span>
<a name="l00041"></a><a class="code" href="bmpio_8c.html#ad72dbcf6d0153db1b8d8a58001feed83">00041</a> <span class="preprocessor"></span><span class="preprocessor">#define DEBUG 0</span>
<a name="l00042"></a>00042 <span class="preprocessor"></span><span class="preprocessor">#endif </span><span class="comment">/* ~NO_CONSOLE_IO */</span>
<a name="l00043"></a>00043
<a name="l00044"></a>00044 <span class="comment"></span>
<a name="l00045"></a>00045 <span class="comment">/*!</span>
<a name="l00046"></a>00046 <span class="comment"> * pixReadStreamBmp()</span>
<a name="l00047"></a>00047 <span class="comment"> *</span>
<a name="l00048"></a>00048 <span class="comment"> * Input: stream opened for read</span>
<a name="l00049"></a>00049 <span class="comment"> * Return: pix, or null on error</span>
<a name="l00050"></a>00050 <span class="comment"> *</span>
<a name="l00051"></a>00051 <span class="comment"> * Notes:</span>
<a name="l00052"></a>00052 <span class="comment"> * (1) Here are references on the bmp file format:</span>
<a name="l00053"></a>00053 <span class="comment"> * http://en.wikipedia.org/wiki/BMP_file_format</span>
<a name="l00054"></a>00054 <span class="comment"> * http://www.fortunecity.com/skyscraper/windows/364/bmpffrmt.html</span>
<a name="l00055"></a>00055 <span class="comment"> */</span>
<a name="l00056"></a>00056 <a class="code" href="struct_pix.html">PIX</a> *
<a name="l00057"></a><a class="code" href="leptprotos_8h.html#a7c8e60fba3edd3ccbe59984fc75f1201">00057</a> <a class="code" href="bmpio_8c.html#a657bc3de2cab48f6e93d7536f007635b">pixReadStreamBmp</a>(FILE *fp)
<a name="l00058"></a>00058 {
<a name="l00059"></a>00059 <a class="code" href="environ_8h.html#a44325897ae2a352c62931134b7c7b6a2">l_uint16</a> sval;
<a name="l00060"></a>00060 <a class="code" href="environ_8h.html#a4d4d7254020fc95aef5dde8884405358">l_uint32</a> ival;
<a name="l00061"></a>00061 <a class="code" href="environ_8h.html#ac0279732ead4d541b153d77fc4a030d7">l_int16</a> bfType, bfSize, bfFill1, bfReserved1, bfReserved2;
<a name="l00062"></a>00062 <a class="code" href="environ_8h.html#ac0279732ead4d541b153d77fc4a030d7">l_int16</a> offset, bfFill2, <a class="code" href="struct_b_m_p___info_header.html#a83ca8da2fa3cc805ac0688c221c72497">biPlanes</a>, depth, d;
<a name="l00063"></a>00063 <a class="code" href="environ_8h.html#a9085c7874153c280a4171244aa052e4e">l_int32</a> <a class="code" href="struct_b_m_p___info_header.html#a5cee27ee266374552d052464f17960c3">biSize</a>, width, height, xres, yres, compression, ignore;
<a name="l00064"></a>00064 <a class="code" href="environ_8h.html#a9085c7874153c280a4171244aa052e4e">l_int32</a> imagebytes, <a class="code" href="struct_b_m_p___info_header.html#a5903468949bd7f80255cef93090ce359">biClrUsed</a>, <a class="code" href="struct_b_m_p___info_header.html#a4849b4b9fe3cba4546f562f25f747365">biClrImportant</a>;
<a name="l00065"></a>00065 <a class="code" href="environ_8h.html#a7ed60554e7d6dd89aca643189b1e70ad">l_uint8</a> *colormapBuf;
<a name="l00066"></a>00066 <a class="code" href="environ_8h.html#a9085c7874153c280a4171244aa052e4e">l_int32</a> colormapEntries;
<a name="l00067"></a>00067 <a class="code" href="environ_8h.html#a9085c7874153c280a4171244aa052e4e">l_int32</a> fileBpl, extrabytes, readerror;
<a name="l00068"></a>00068 <a class="code" href="environ_8h.html#a9085c7874153c280a4171244aa052e4e">l_int32</a> pixWpl, pixBpl;
<a name="l00069"></a>00069 <a class="code" href="environ_8h.html#a9085c7874153c280a4171244aa052e4e">l_int32</a> i, j, k;
<a name="l00070"></a>00070 <a class="code" href="environ_8h.html#a7ed60554e7d6dd89aca643189b1e70ad">l_uint8</a> pel[4];
<a name="l00071"></a>00071 <a class="code" href="environ_8h.html#a7ed60554e7d6dd89aca643189b1e70ad">l_uint8</a> *data;
<a name="l00072"></a>00072 <a class="code" href="environ_8h.html#a4d4d7254020fc95aef5dde8884405358">l_uint32</a> *line, *pword;
<a name="l00073"></a>00073 <a class="code" href="struct_pix.html">PIX</a> *pix, *pixt;
<a name="l00074"></a>00074 <a class="code" href="struct_pix_colormap.html">PIXCMAP</a> *cmap;
<a name="l00075"></a>00075
<a name="l00076"></a>00076 <a class="code" href="environ_8h.html#a1a16952819bcbc526c998e3ac86f2e78">PROCNAME</a>(<span class="stringliteral">"pixReadStreamBmp"</span>);
<a name="l00077"></a>00077
<a name="l00078"></a>00078 <span class="keywordflow">if</span> (!fp)
<a name="l00079"></a>00079 <span class="keywordflow">return</span> (<a class="code" href="struct_pix.html">PIX</a> *)<a class="code" href="environ_8h.html#a38a8310a83847948c9ce6620983be468">ERROR_PTR</a>(<span class="stringliteral">"fp not defined"</span>, procName, <a class="code" href="environ_8h.html#a070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>);
<a name="l00080"></a>00080
<a name="l00081"></a>00081 <span class="comment">/* Read bitmap file header */</span>
<a name="l00082"></a>00082 ignore = fread((<span class="keywordtype">char</span> *)&sval, 1, 2, fp);
<a name="l00083"></a>00083 bfType = <a class="code" href="leptprotos_8h.html#a40491aa07db4319c7619ffaa0bc26a89">convertOnBigEnd16</a>(sval);
<a name="l00084"></a>00084 <span class="keywordflow">if</span> (bfType != <a class="code" href="imageio_8h.html#a0411cd49bb5b71852cecd93bcbf0ca2da5e1a56e4cb61aac4e5e7a99e981aa00d">BMP_ID</a>)
<a name="l00085"></a>00085 <span class="keywordflow">return</span> (<a class="code" href="struct_pix.html">PIX</a> *)<a class="code" href="environ_8h.html#a38a8310a83847948c9ce6620983be468">ERROR_PTR</a>(<span class="stringliteral">"not bmf format"</span>, procName, <a class="code" href="environ_8h.html#a070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>);
<a name="l00086"></a>00086
<a name="l00087"></a>00087 ignore = fread((<span class="keywordtype">char</span> *)&sval, 1, 2, fp);
<a name="l00088"></a>00088 bfSize = <a class="code" href="leptprotos_8h.html#a40491aa07db4319c7619ffaa0bc26a89">convertOnBigEnd16</a>(sval);
<a name="l00089"></a>00089 ignore = fread((<span class="keywordtype">char</span> *)&sval, 1, 2, fp);
<a name="l00090"></a>00090 bfFill1 = <a class="code" href="leptprotos_8h.html#a40491aa07db4319c7619ffaa0bc26a89">convertOnBigEnd16</a>(sval);
<a name="l00091"></a>00091 ignore = fread((<span class="keywordtype">char</span> *)&sval, 1, 2, fp);
<a name="l00092"></a>00092 bfReserved1 = <a class="code" href="leptprotos_8h.html#a40491aa07db4319c7619ffaa0bc26a89">convertOnBigEnd16</a>(sval);
<a name="l00093"></a>00093 ignore = fread((<span class="keywordtype">char</span> *)&sval, 1, 2, fp);
<a name="l00094"></a>00094 bfReserved2 = <a class="code" href="leptprotos_8h.html#a40491aa07db4319c7619ffaa0bc26a89">convertOnBigEnd16</a>(sval);
<a name="l00095"></a>00095 ignore = fread((<span class="keywordtype">char</span> *)&sval, 1, 2, fp);
<a name="l00096"></a>00096 offset = <a class="code" href="leptprotos_8h.html#a40491aa07db4319c7619ffaa0bc26a89">convertOnBigEnd16</a>(sval);
<a name="l00097"></a>00097 ignore = fread((<span class="keywordtype">char</span> *)&sval, 1, 2, fp);
<a name="l00098"></a>00098 bfFill2 = <a class="code" href="leptprotos_8h.html#a40491aa07db4319c7619ffaa0bc26a89">convertOnBigEnd16</a>(sval);
<a name="l00099"></a>00099
<a name="l00100"></a>00100 <span class="comment">/* Read bitmap info header */</span>
<a name="l00101"></a>00101 ignore = fread((<span class="keywordtype">char</span> *)&ival, 1, 4, fp);
<a name="l00102"></a>00102 biSize = <a class="code" href="leptprotos_8h.html#af93e9578057fc644074cd408cc8c52ed">convertOnBigEnd32</a>(ival);
<a name="l00103"></a>00103 ignore = fread((<span class="keywordtype">char</span> *)&ival, 1, 4, fp);
<a name="l00104"></a>00104 width = <a class="code" href="leptprotos_8h.html#af93e9578057fc644074cd408cc8c52ed">convertOnBigEnd32</a>(ival);
<a name="l00105"></a>00105 ignore = fread((<span class="keywordtype">char</span> *)&ival, 1, 4, fp);
<a name="l00106"></a>00106 height = <a class="code" href="leptprotos_8h.html#af93e9578057fc644074cd408cc8c52ed">convertOnBigEnd32</a>(ival);
<a name="l00107"></a>00107 ignore = fread((<span class="keywordtype">char</span> *)&sval, 1, 2, fp);
<a name="l00108"></a>00108 biPlanes = <a class="code" href="leptprotos_8h.html#a40491aa07db4319c7619ffaa0bc26a89">convertOnBigEnd16</a>(sval);
<a name="l00109"></a>00109 ignore = fread((<span class="keywordtype">char</span> *)&sval, 1, 2, fp);
<a name="l00110"></a>00110 depth = <a class="code" href="leptprotos_8h.html#a40491aa07db4319c7619ffaa0bc26a89">convertOnBigEnd16</a>(sval);
<a name="l00111"></a>00111 ignore = fread((<span class="keywordtype">char</span> *)&ival, 1, 4, fp);
<a name="l00112"></a>00112 compression = <a class="code" href="leptprotos_8h.html#af93e9578057fc644074cd408cc8c52ed">convertOnBigEnd32</a>(ival);
<a name="l00113"></a>00113 ignore = fread((<span class="keywordtype">char</span> *)&ival, 1, 4, fp);
<a name="l00114"></a>00114 imagebytes = <a class="code" href="leptprotos_8h.html#af93e9578057fc644074cd408cc8c52ed">convertOnBigEnd32</a>(ival);
<a name="l00115"></a>00115 ignore = fread((<span class="keywordtype">char</span> *)&ival, 1, 4, fp);
<a name="l00116"></a>00116 xres = <a class="code" href="leptprotos_8h.html#af93e9578057fc644074cd408cc8c52ed">convertOnBigEnd32</a>(ival);
<a name="l00117"></a>00117 ignore = fread((<span class="keywordtype">char</span> *)&ival, 1, 4, fp);
<a name="l00118"></a>00118 yres = <a class="code" href="leptprotos_8h.html#af93e9578057fc644074cd408cc8c52ed">convertOnBigEnd32</a>(ival);
<a name="l00119"></a>00119 ignore = fread((<span class="keywordtype">char</span> *)&ival, 1, 4, fp);
<a name="l00120"></a>00120 biClrUsed = <a class="code" href="leptprotos_8h.html#af93e9578057fc644074cd408cc8c52ed">convertOnBigEnd32</a>(ival);
<a name="l00121"></a>00121 ignore = fread((<span class="keywordtype">char</span> *)&ival, 1, 4, fp);
<a name="l00122"></a>00122 biClrImportant = <a class="code" href="leptprotos_8h.html#af93e9578057fc644074cd408cc8c52ed">convertOnBigEnd32</a>(ival);
<a name="l00123"></a>00123
<a name="l00124"></a>00124 <span class="keywordflow">if</span> (compression != 0)
<a name="l00125"></a>00125 <span class="keywordflow">return</span> (<a class="code" href="struct_pix.html">PIX</a> *)<a class="code" href="environ_8h.html#a38a8310a83847948c9ce6620983be468">ERROR_PTR</a>(<span class="stringliteral">"cannot read compressed BMP files"</span>,
<a name="l00126"></a>00126 procName,<a class="code" href="environ_8h.html#a070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>);
<a name="l00127"></a>00127
<a name="l00128"></a>00128 <span class="comment">/* A little sanity checking. It would be nice to check</span>
<a name="l00129"></a>00129 <span class="comment"> * if the number of bytes in the file equals the offset to</span>
<a name="l00130"></a>00130 <span class="comment"> * the data plus the imagedata, but this won't work when</span>
<a name="l00131"></a>00131 <span class="comment"> * reading from memory, because fmemopen() doesn't implement</span>
<a name="l00132"></a>00132 <span class="comment"> * ftell(). So we can't do that check. The imagebytes for</span>
<a name="l00133"></a>00133 <span class="comment"> * uncompressed images is either 0 or the size of the file data.</span>
<a name="l00134"></a>00134 <span class="comment"> * (The fact that it can be 0 is perhaps some legacy glitch). */</span>
<a name="l00135"></a>00135 <span class="keywordflow">if</span> (width < 1)
<a name="l00136"></a>00136 <span class="keywordflow">return</span> (<a class="code" href="struct_pix.html">PIX</a> *)<a class="code" href="environ_8h.html#a38a8310a83847948c9ce6620983be468">ERROR_PTR</a>(<span class="stringliteral">"width < 1"</span>, procName,<a class="code" href="environ_8h.html#a070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>);
<a name="l00137"></a>00137 <span class="keywordflow">if</span> (height < 1)
<a name="l00138"></a>00138 <span class="keywordflow">return</span> (<a class="code" href="struct_pix.html">PIX</a> *)<a class="code" href="environ_8h.html#a38a8310a83847948c9ce6620983be468">ERROR_PTR</a>(<span class="stringliteral">"height < 1"</span>, procName,<a class="code" href="environ_8h.html#a070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>);
<a name="l00139"></a>00139 <span class="keywordflow">if</span> (depth < 1 || depth > 32)
<a name="l00140"></a>00140 <span class="keywordflow">return</span> (<a class="code" href="struct_pix.html">PIX</a> *)<a class="code" href="environ_8h.html#a38a8310a83847948c9ce6620983be468">ERROR_PTR</a>(<span class="stringliteral">"depth not in [1 ... 32]"</span>, procName,<a class="code" href="environ_8h.html#a070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>);
<a name="l00141"></a>00141 fileBpl = 4 * ((width * depth + 31)/32);
<a name="l00142"></a>00142 <span class="keywordflow">if</span> (imagebytes != 0 && imagebytes != fileBpl * height)
<a name="l00143"></a>00143 <span class="keywordflow">return</span> (<a class="code" href="struct_pix.html">PIX</a> *)<a class="code" href="environ_8h.html#a38a8310a83847948c9ce6620983be468">ERROR_PTR</a>(<span class="stringliteral">"invalid imagebytes"</span>, procName,<a class="code" href="environ_8h.html#a070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>);
<a name="l00144"></a>00144 <span class="keywordflow">if</span> (offset < <a class="code" href="bmp_8h.html#a90aeed1cb2bc4d1ab703c222dd6d68fe">BMP_FHBYTES</a> + <a class="code" href="bmp_8h.html#a53928f289637b030bb034eab53a28eff">BMP_IHBYTES</a>)
<a name="l00145"></a>00145 <span class="keywordflow">return</span> (<a class="code" href="struct_pix.html">PIX</a> *)<a class="code" href="environ_8h.html#a38a8310a83847948c9ce6620983be468">ERROR_PTR</a>(<span class="stringliteral">"invalid offset: too small"</span>, procName,<a class="code" href="environ_8h.html#a070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>);
<a name="l00146"></a>00146 <span class="keywordflow">if</span> (offset > <a class="code" href="bmp_8h.html#a90aeed1cb2bc4d1ab703c222dd6d68fe">BMP_FHBYTES</a> + <a class="code" href="bmp_8h.html#a53928f289637b030bb034eab53a28eff">BMP_IHBYTES</a> + 4 * 256)
<a name="l00147"></a>00147 <span class="keywordflow">return</span> (<a class="code" href="struct_pix.html">PIX</a> *)<a class="code" href="environ_8h.html#a38a8310a83847948c9ce6620983be468">ERROR_PTR</a>(<span class="stringliteral">"invalid offset: too large"</span>, procName,<a class="code" href="environ_8h.html#a070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>);
<a name="l00148"></a>00148
<a name="l00149"></a>00149 <span class="comment">/* Handle the colormap */</span>
<a name="l00150"></a>00150 colormapEntries = (offset - <a class="code" href="bmp_8h.html#a90aeed1cb2bc4d1ab703c222dd6d68fe">BMP_FHBYTES</a> - <a class="code" href="bmp_8h.html#a53928f289637b030bb034eab53a28eff">BMP_IHBYTES</a>) / <span class="keyword">sizeof</span>(<a class="code" href="struct_r_g_b_a___quad.html">RGBA_QUAD</a>);
<a name="l00151"></a>00151 <span class="keywordflow">if</span> (colormapEntries > 0) {
<a name="l00152"></a>00152 <span class="keywordflow">if</span> ((colormapBuf = (<a class="code" href="environ_8h.html#a7ed60554e7d6dd89aca643189b1e70ad">l_uint8</a> *)<a class="code" href="environ_8h.html#abc24891c647be0bd23e233d013175da0">CALLOC</a>(colormapEntries,
<a name="l00153"></a>00153 <span class="keyword">sizeof</span>(<a class="code" href="struct_r_g_b_a___quad.html">RGBA_QUAD</a>))) == <a class="code" href="environ_8h.html#a070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>)
<a name="l00154"></a>00154 <span class="keywordflow">return</span> (<a class="code" href="struct_pix.html">PIX</a> *)<a class="code" href="environ_8h.html#a38a8310a83847948c9ce6620983be468">ERROR_PTR</a>(<span class="stringliteral">"colormapBuf alloc fail"</span>, procName, <a class="code" href="environ_8h.html#a070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a> );
<a name="l00155"></a>00155
<a name="l00156"></a>00156 <span class="comment">/* Read colormap */</span>
<a name="l00157"></a>00157 <span class="keywordflow">if</span> (fread(colormapBuf, <span class="keyword">sizeof</span>(<a class="code" href="struct_r_g_b_a___quad.html">RGBA_QUAD</a>), colormapEntries, fp)
<a name="l00158"></a>00158 != colormapEntries) {
<a name="l00159"></a>00159 <a class="code" href="environ_8h.html#a105949c59c998e38aad80266afac92bf">FREE</a>(colormapBuf);
<a name="l00160"></a>00160 <span class="keywordflow">return</span> (<a class="code" href="struct_pix.html">PIX</a> *)<a class="code" href="environ_8h.html#a38a8310a83847948c9ce6620983be468">ERROR_PTR</a>( <span class="stringliteral">"colormap read fail"</span>, procName, <a class="code" href="environ_8h.html#a070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>);
<a name="l00161"></a>00161 }
<a name="l00162"></a>00162 }
<a name="l00163"></a>00163
<a name="l00164"></a>00164 <span class="comment">/* Make a 32 bpp pix if depth is 24 bpp */</span>
<a name="l00165"></a>00165 d = depth;
<a name="l00166"></a>00166 <span class="keywordflow">if</span> (depth == 24)
<a name="l00167"></a>00167 d = 32;
<a name="l00168"></a>00168 <span class="keywordflow">if</span> ((pix = <a class="code" href="leptprotos_8h.html#a009df4671d39f94b50a0368af210aebe">pixCreate</a>(width, height, d)) == <a class="code" href="environ_8h.html#a070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>)
<a name="l00169"></a>00169 <span class="keywordflow">return</span> (<a class="code" href="struct_pix.html">PIX</a> *)<a class="code" href="environ_8h.html#a38a8310a83847948c9ce6620983be468">ERROR_PTR</a>( <span class="stringliteral">"pix not made"</span>, procName, <a class="code" href="environ_8h.html#a070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>);
<a name="l00170"></a>00170 <a class="code" href="leptprotos_8h.html#af04bd949cef6d6f3443994dc337c6ec0">pixSetXRes</a>(pix, (<a class="code" href="environ_8h.html#a9085c7874153c280a4171244aa052e4e">l_int32</a>)((<a class="code" href="environ_8h.html#af59419416d96ecf5fca70c8d05adb456">l_float32</a>)xres / 39.37 + 0.5)); <span class="comment">/* to ppi */</span>
<a name="l00171"></a>00171 <a class="code" href="leptprotos_8h.html#a9b07625ad6bc1f488426e082454b311d">pixSetYRes</a>(pix, (<a class="code" href="environ_8h.html#a9085c7874153c280a4171244aa052e4e">l_int32</a>)((<a class="code" href="environ_8h.html#af59419416d96ecf5fca70c8d05adb456">l_float32</a>)yres / 39.37 + 0.5)); <span class="comment">/* to ppi */</span>
<a name="l00172"></a>00172 pixWpl = <a class="code" href="leptprotos_8h.html#af0b490472ab7999f208098dd37167d73">pixGetWpl</a>(pix);
<a name="l00173"></a>00173 pixBpl = 4 * pixWpl;
<a name="l00174"></a>00174
<a name="l00175"></a>00175 cmap = <a class="code" href="environ_8h.html#a070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>;
<a name="l00176"></a>00176 <span class="keywordflow">if</span> (colormapEntries > 256)
<a name="l00177"></a>00177 <a class="code" href="environ_8h.html#a80ea4add6888dc55f0f6af9c488f1f21">L_WARNING</a>(<span class="stringliteral">"more than 256 colormap entries!"</span>, procName);
<a name="l00178"></a>00178 <span class="keywordflow">if</span> (colormapEntries > 0) { <span class="comment">/* import the colormap to the pix cmap */</span>
<a name="l00179"></a>00179 cmap = <a class="code" href="colormap_8c.html#a41b80672f852c84d4867952c820ac00e">pixcmapCreate</a>(<a class="code" href="environ_8h.html#a67d588ee5ca71be19990efb07fa2ce72">L_MIN</a>(d, 8));
<a name="l00180"></a>00180 <a class="code" href="environ_8h.html#a105949c59c998e38aad80266afac92bf">FREE</a>(cmap-><a class="code" href="struct_pix_colormap.html#a2a14164dbec38ebab11eee1bea569cbc">array</a>); <span class="comment">/* remove generated cmap array */</span>
<a name="l00181"></a>00181 cmap-><a class="code" href="struct_pix_colormap.html#a2a14164dbec38ebab11eee1bea569cbc">array</a> = (<span class="keywordtype">void</span> *)colormapBuf; <span class="comment">/* and replace */</span>
<a name="l00182"></a>00182 cmap-><a class="code" href="struct_pix_colormap.html#a99005f6c729d84e55143a208b61f99bf">n</a> = <a class="code" href="environ_8h.html#a67d588ee5ca71be19990efb07fa2ce72">L_MIN</a>(colormapEntries, 256);
<a name="l00183"></a>00183 }
<a name="l00184"></a>00184 <a class="code" href="leptprotos_8h.html#a6015decaf96da4e73708bc34527df065">pixSetColormap</a>(pix, cmap);
<a name="l00185"></a>00185
<a name="l00186"></a>00186 <span class="comment">/* Seek to the start of the bitmap in the file */</span>
<a name="l00187"></a>00187 fseek(fp, offset, 0);
<a name="l00188"></a>00188
<a name="l00189"></a>00189 <span class="keywordflow">if</span> (depth != 24) { <span class="comment">/* typ. 1 or 8 bpp */</span>
<a name="l00190"></a>00190 data = (<a class="code" href="environ_8h.html#a7ed60554e7d6dd89aca643189b1e70ad">l_uint8</a> *)<a class="code" href="leptprotos_8h.html#a44546f758f2cf71bb109bfc114e3ca7f">pixGetData</a>(pix) + pixBpl * (height - 1);
<a name="l00191"></a>00191 <span class="keywordflow">for</span> (i = 0; i < height; i++) {
<a name="l00192"></a>00192 <span class="keywordflow">if</span> (fread(data, 1, fileBpl, fp) != fileBpl) {
<a name="l00193"></a>00193 <a class="code" href="leptprotos_8h.html#a1b238e61b64e4e5c62f44849cddb9658">pixDestroy</a>(&pix);
<a name="l00194"></a>00194 <span class="keywordflow">return</span> (<a class="code" href="struct_pix.html">PIX</a> *)<a class="code" href="environ_8h.html#a38a8310a83847948c9ce6620983be468">ERROR_PTR</a>(<span class="stringliteral">"BMP read fail"</span>, procName, <a class="code" href="environ_8h.html#a070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>);
<a name="l00195"></a>00195 }
<a name="l00196"></a>00196 data -= pixBpl;
<a name="l00197"></a>00197 }
<a name="l00198"></a>00198 }
<a name="l00199"></a>00199 <span class="keywordflow">else</span> { <span class="comment">/* 24 bpp file; 32 bpp pix</span>
<a name="l00200"></a>00200 <span class="comment"> * Note: for bmp files, pel[0] is blue, pel[1] is green,</span>
<a name="l00201"></a>00201 <span class="comment"> * and pel[2] is red. This is opposite to the storage</span>
<a name="l00202"></a>00202 <span class="comment"> * in the pix, which puts the red pixel in the 0 byte,</span>
<a name="l00203"></a>00203 <span class="comment"> * the green in the 1 byte and the blue in the 2 byte.</span>
<a name="l00204"></a>00204 <span class="comment"> * Note also that all words are endian flipped after</span>
<a name="l00205"></a>00205 <span class="comment"> * assignment on L_LITTLE_ENDIAN platforms.</span>
<a name="l00206"></a>00206 <span class="comment"> *</span>
<a name="l00207"></a>00207 <span class="comment"> * We can then make these assignments for little endians:</span>
<a name="l00208"></a>00208 <span class="comment"> * SET_DATA_BYTE(pword, 1, pel[0]); blue</span>
<a name="l00209"></a>00209 <span class="comment"> * SET_DATA_BYTE(pword, 2, pel[1]); green</span>
<a name="l00210"></a>00210 <span class="comment"> * SET_DATA_BYTE(pword, 3, pel[2]); red</span>
<a name="l00211"></a>00211 <span class="comment"> * This looks like:</span>
<a name="l00212"></a>00212 <span class="comment"> * 3 (R) 2 (G) 1 (B) 0</span>
<a name="l00213"></a>00213 <span class="comment"> * |-----------|------------|-----------|-----------|</span>
<a name="l00214"></a>00214 <span class="comment"> * and after byte flipping:</span>
<a name="l00215"></a>00215 <span class="comment"> * 3 2 (B) 1 (G) 0 (R)</span>
<a name="l00216"></a>00216 <span class="comment"> * |-----------|------------|-----------|-----------|</span>
<a name="l00217"></a>00217 <span class="comment"> *</span>
<a name="l00218"></a>00218 <span class="comment"> * For big endians we set:</span>
<a name="l00219"></a>00219 <span class="comment"> * SET_DATA_BYTE(pword, 2, pel[0]); blue</span>
<a name="l00220"></a>00220 <span class="comment"> * SET_DATA_BYTE(pword, 1, pel[1]); green</span>
<a name="l00221"></a>00221 <span class="comment"> * SET_DATA_BYTE(pword, 0, pel[2]); red</span>
<a name="l00222"></a>00222 <span class="comment"> * This looks like:</span>
<a name="l00223"></a>00223 <span class="comment"> * 0 (R) 1 (G) 2 (B) 3</span>
<a name="l00224"></a>00224 <span class="comment"> * |-----------|------------|-----------|-----------|</span>
<a name="l00225"></a>00225 <span class="comment"> * so in both cases we get the correct assignment in the PIX.</span>
<a name="l00226"></a>00226 <span class="comment"> *</span>
<a name="l00227"></a>00227 <span class="comment"> * Can we do a platform-independent assignment?</span>
<a name="l00228"></a>00228 <span class="comment"> * Yes, set the bytes without using macros:</span>
<a name="l00229"></a>00229 <span class="comment"> * *((l_uint8 *)pword) = pel[2]; red</span>
<a name="l00230"></a>00230 <span class="comment"> * *((l_uint8 *)pword + 1) = pel[1]; green</span>
<a name="l00231"></a>00231 <span class="comment"> * *((l_uint8 *)pword + 2) = pel[0]; blue</span>
<a name="l00232"></a>00232 <span class="comment"> * For little endians, before flipping, this looks again like:</span>
<a name="l00233"></a>00233 <span class="comment"> * 3 (R) 2 (G) 1 (B) 0</span>
<a name="l00234"></a>00234 <span class="comment"> * |-----------|------------|-----------|-----------|</span>
<a name="l00235"></a>00235 <span class="comment"> */</span>
<a name="l00236"></a>00236 readerror = 0;
<a name="l00237"></a>00237 extrabytes = fileBpl - 3 * width;
<a name="l00238"></a>00238 line = <a class="code" href="leptprotos_8h.html#a44546f758f2cf71bb109bfc114e3ca7f">pixGetData</a>(pix) + pixWpl * (height - 1);
<a name="l00239"></a>00239 <span class="keywordflow">for</span> (i = 0; i < height; i++) {
<a name="l00240"></a>00240 <span class="keywordflow">for</span> (j = 0; j < width; j++) {
<a name="l00241"></a>00241 pword = line + j;
<a name="l00242"></a>00242 <span class="keywordflow">if</span> (fread(&pel, 1, 3, fp) != 3)
<a name="l00243"></a>00243 readerror = 1;
<a name="l00244"></a>00244 *((<a class="code" href="environ_8h.html#a7ed60554e7d6dd89aca643189b1e70ad">l_uint8</a> *)pword + <a class="code" href="pix_8h.html#a7ff5f2dff38e7639981794c43dc9167ba592503b9434c1e751a92f3fc536d7950">COLOR_RED</a>) = pel[2];
<a name="l00245"></a>00245 *((<a class="code" href="environ_8h.html#a7ed60554e7d6dd89aca643189b1e70ad">l_uint8</a> *)pword + <a class="code" href="pix_8h.html#a7ff5f2dff38e7639981794c43dc9167bacfa9d8bbffc418447ed826f286abca02">COLOR_GREEN</a>) = pel[1];
<a name="l00246"></a>00246 *((<a class="code" href="environ_8h.html#a7ed60554e7d6dd89aca643189b1e70ad">l_uint8</a> *)pword + <a class="code" href="pix_8h.html#a7ff5f2dff38e7639981794c43dc9167ba1340428efccb140dcbdb71aa6176f696">COLOR_BLUE</a>) = pel[0];
<a name="l00247"></a>00247 }
<a name="l00248"></a>00248 <span class="keywordflow">if</span> (extrabytes) {
<a name="l00249"></a>00249 <span class="keywordflow">for</span> (k = 0; k < extrabytes; k++)
<a name="l00250"></a>00250 ignore = fread(&pel, 1, 1, fp);
<a name="l00251"></a>00251 }
<a name="l00252"></a>00252 line -= pixWpl;
<a name="l00253"></a>00253 }
<a name="l00254"></a>00254 <span class="keywordflow">if</span> (readerror) {
<a name="l00255"></a>00255 <a class="code" href="leptprotos_8h.html#a1b238e61b64e4e5c62f44849cddb9658">pixDestroy</a>(&pix);
<a name="l00256"></a>00256 <span class="keywordflow">return</span> (<a class="code" href="struct_pix.html">PIX</a> *)<a class="code" href="environ_8h.html#a38a8310a83847948c9ce6620983be468">ERROR_PTR</a>(<span class="stringliteral">"BMP read fail"</span>, procName, <a class="code" href="environ_8h.html#a070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>);
<a name="l00257"></a>00257 }
<a name="l00258"></a>00258 }
<a name="l00259"></a>00259
<a name="l00260"></a>00260 <a class="code" href="leptprotos_8h.html#a3c2ace8f3051e291a9accec2e4213275">pixEndianByteSwap</a>(pix);
<a name="l00261"></a>00261
<a name="l00262"></a>00262 <span class="comment">/* ----------------------------------------------</span>
<a name="l00263"></a>00263 <span class="comment"> * The bmp colormap determines the values of black</span>
<a name="l00264"></a>00264 <span class="comment"> * and white pixels for binary in the following way:</span>
<a name="l00265"></a>00265 <span class="comment"> * if black = 1 (255), white = 0</span>
<a name="l00266"></a>00266 <span class="comment"> * 255, 255, 255, 0, 0, 0, 0, 0</span>
<a name="l00267"></a>00267 <span class="comment"> * if black = 0, white = 1 (255)</span>
<a name="l00268"></a>00268 <span class="comment"> * 0, 0, 0, 0, 255, 255, 255, 0</span>
<a name="l00269"></a>00269 <span class="comment"> * We have no need for a 1 bpp pix with a colormap!</span>
<a name="l00270"></a>00270 <span class="comment"> * ---------------------------------------------- */</span>
<a name="l00271"></a>00271 <span class="keywordflow">if</span> (depth == 1 && cmap) {
<a name="l00272"></a>00272 <span class="comment">/* L_INFO("Removing colormap", procName); */</span>
<a name="l00273"></a>00273 pixt = <a class="code" href="leptprotos_8h.html#a422b2e45ac5ed1185c1804fdca9f7528">pixRemoveColormap</a>(pix, <a class="code" href="pix_8h.html#aabfcbcb5ac86a1edac4035264bc7d2b8a928326b36824c842a5b94c680eab098c">REMOVE_CMAP_BASED_ON_SRC</a>);
<a name="l00274"></a>00274 <a class="code" href="leptprotos_8h.html#a1b238e61b64e4e5c62f44849cddb9658">pixDestroy</a>(&pix);
<a name="l00275"></a>00275 pix = pixt; <span class="comment">/* rename */</span>
<a name="l00276"></a>00276 }
<a name="l00277"></a>00277
<a name="l00278"></a>00278 <span class="keywordflow">return</span> pix;
<a name="l00279"></a>00279 }
<a name="l00280"></a>00280
<a name="l00281"></a>00281
<a name="l00282"></a>00282 <span class="comment"></span>
<a name="l00283"></a>00283 <span class="comment">/*!</span>
<a name="l00284"></a>00284 <span class="comment"> * pixWriteStreamBmp()</span>
<a name="l00285"></a>00285 <span class="comment"> *</span>
<a name="l00286"></a>00286 <span class="comment"> * Input: stream opened for write</span>
<a name="l00287"></a>00287 <span class="comment"> * pix (1, 4, 8, 32 bpp)</span>
<a name="l00288"></a>00288 <span class="comment"> * Return: 0 if OK, 1 on error</span>
<a name="l00289"></a>00289 <span class="comment"> *</span>
<a name="l00290"></a>00290 <span class="comment"> * Notes:</span>
<a name="l00291"></a>00291 <span class="comment"> * (1) We position fp at the beginning of the stream, so it</span>
<a name="l00292"></a>00292 <span class="comment"> * truncates any existing data</span>
<a name="l00293"></a>00293 <span class="comment"> * (2) 2 bpp Bmp files are apparently not valid!. We can</span>
<a name="l00294"></a>00294 <span class="comment"> * write and read them, but nobody else can read ours.</span>
<a name="l00295"></a>00295 <span class="comment"> */</span>
<a name="l00296"></a>00296 <a class="code" href="environ_8h.html#a9085c7874153c280a4171244aa052e4e">l_int32</a>
<a name="l00297"></a><a class="code" href="leptprotos_8h.html#afd637398fd0dc3f606f95a3855fdd02f">00297</a> <a class="code" href="bmpio_8c.html#a223012d6d4376e683c92acc9687ba337">pixWriteStreamBmp</a>(FILE *fp,
<a name="l00298"></a>00298 <a class="code" href="struct_pix.html">PIX</a> *pix)
<a name="l00299"></a>00299 {
<a name="l00300"></a>00300 <a class="code" href="environ_8h.html#a4d4d7254020fc95aef5dde8884405358">l_uint32</a> offbytes, filebytes, fileimagebytes;
<a name="l00301"></a>00301 <a class="code" href="environ_8h.html#a9085c7874153c280a4171244aa052e4e">l_int32</a> width, height, depth, d, xres, yres;
<a name="l00302"></a>00302 <a class="code" href="environ_8h.html#a44325897ae2a352c62931134b7c7b6a2">l_uint16</a> bfType, bfSize, bfFill1, bfReserved1, bfReserved2;
<a name="l00303"></a>00303 <a class="code" href="environ_8h.html#a44325897ae2a352c62931134b7c7b6a2">l_uint16</a> bfOffBits, bfFill2, <a class="code" href="struct_b_m_p___info_header.html#a83ca8da2fa3cc805ac0688c221c72497">biPlanes</a>, <a class="code" href="struct_b_m_p___info_header.html#ab9fe6b2af21b4e5a16b7e6f5fa174cfd">biBitCount</a>;
<a name="l00304"></a>00304 <a class="code" href="environ_8h.html#a44325897ae2a352c62931134b7c7b6a2">l_uint16</a> sval;
<a name="l00305"></a>00305 <a class="code" href="environ_8h.html#a4d4d7254020fc95aef5dde8884405358">l_uint32</a> <a class="code" href="struct_b_m_p___info_header.html#a5cee27ee266374552d052464f17960c3">biSize</a>, <a class="code" href="struct_b_m_p___info_header.html#ab22342475e273acf6f965e445918be7a">biWidth</a>, <a class="code" href="struct_b_m_p___info_header.html#ad3d3c730e85167ec8c20cf6c3b04346a">biHeight</a>, <a class="code" href="struct_b_m_p___info_header.html#aeae7345a06168eb2070a6c3e8a3d883f">biCompression</a>, <a class="code" href="struct_b_m_p___info_header.html#a17518d5a5cfa25b031f4f0b46e116578">biSizeImage</a>;
<a name="l00306"></a>00306 <a class="code" href="environ_8h.html#a4d4d7254020fc95aef5dde8884405358">l_uint32</a> <a class="code" href="struct_b_m_p___info_header.html#a3479ea3002de95417ef69b7ec45b4a82">biXPelsPerMeter</a>, <a class="code" href="struct_b_m_p___info_header.html#a70d2c999b9679c27f8906028c4949607">biYPelsPerMeter</a>, <a class="code" href="struct_b_m_p___info_header.html#a5903468949bd7f80255cef93090ce359">biClrUsed</a>, <a class="code" href="struct_b_m_p___info_header.html#a4849b4b9fe3cba4546f562f25f747365">biClrImportant</a>;
<a name="l00307"></a>00307 <a class="code" href="environ_8h.html#a9085c7874153c280a4171244aa052e4e">l_int32</a> pixWpl, pixBpl, extrabytes, writeerror;
<a name="l00308"></a>00308 <a class="code" href="environ_8h.html#a9085c7874153c280a4171244aa052e4e">l_int32</a> fileBpl, fileWpl;
<a name="l00309"></a>00309 <a class="code" href="environ_8h.html#a9085c7874153c280a4171244aa052e4e">l_int32</a> i, j, k;
<a name="l00310"></a>00310 <a class="code" href="environ_8h.html#a9085c7874153c280a4171244aa052e4e">l_int32</a> heapcm; <span class="comment">/* extra copy of cta on the heap ? 1 : 0 */</span>
<a name="l00311"></a>00311 <a class="code" href="environ_8h.html#a7ed60554e7d6dd89aca643189b1e70ad">l_uint8</a> *data;
<a name="l00312"></a>00312 <a class="code" href="environ_8h.html#a7ed60554e7d6dd89aca643189b1e70ad">l_uint8</a> pel[4];
<a name="l00313"></a>00313 <a class="code" href="environ_8h.html#a4d4d7254020fc95aef5dde8884405358">l_uint32</a> *line, *pword;
<a name="l00314"></a>00314 <a class="code" href="struct_pix_colormap.html">PIXCMAP</a> *cmap;
<a name="l00315"></a>00315 <a class="code" href="environ_8h.html#a7ed60554e7d6dd89aca643189b1e70ad">l_uint8</a> *cta; <span class="comment">/* address of the bmp color table array */</span>
<a name="l00316"></a>00316 <a class="code" href="environ_8h.html#a9085c7874153c280a4171244aa052e4e">l_int32</a> cmaplen; <span class="comment">/* number of bytes in the bmp colormap */</span>
<a name="l00317"></a>00317 <a class="code" href="environ_8h.html#a9085c7874153c280a4171244aa052e4e">l_int32</a> ncolors, val, stepsize;
<a name="l00318"></a>00318 <a class="code" href="struct_r_g_b_a___quad.html">RGBA_QUAD</a> *pquad;
<a name="l00319"></a>00319
<a name="l00320"></a>00320 <a class="code" href="environ_8h.html#a1a16952819bcbc526c998e3ac86f2e78">PROCNAME</a>(<span class="stringliteral">"pixWriteStreamBmp"</span>);
<a name="l00321"></a>00321
<a name="l00322"></a>00322 <span class="keywordflow">if</span> (!fp)
<a name="l00323"></a>00323 <span class="keywordflow">return</span> <a class="code" href="environ_8h.html#a8b17fe871312c2e1613fa694bb78a963">ERROR_INT</a>(<span class="stringliteral">"stream not defined"</span>, procName, 1);
<a name="l00324"></a>00324 <span class="keywordflow">if</span> (!pix)
<a name="l00325"></a>00325 <span class="keywordflow">return</span> <a class="code" href="environ_8h.html#a8b17fe871312c2e1613fa694bb78a963">ERROR_INT</a>(<span class="stringliteral">"pix not defined"</span>, procName, 1);
<a name="l00326"></a>00326
<a name="l00327"></a>00327 width = <a class="code" href="leptprotos_8h.html#aa71e0b02548a56e723c76996ab145257">pixGetWidth</a>(pix);
<a name="l00328"></a>00328 height = <a class="code" href="leptprotos_8h.html#a511e60efcf1d9f3f59b5308ef5f49a06">pixGetHeight</a>(pix);
<a name="l00329"></a>00329 d = <a class="code" href="leptprotos_8h.html#a1646270a1eae38cd7af74c68351ce513">pixGetDepth</a>(pix);
<a name="l00330"></a>00330 <span class="keywordflow">if</span> (d == 2)
<a name="l00331"></a>00331 <a class="code" href="environ_8h.html#a80ea4add6888dc55f0f6af9c488f1f21">L_WARNING</a>(<span class="stringliteral">"writing 2 bpp bmp file; nobody else can read"</span>, procName);
<a name="l00332"></a>00332 depth = d;
<a name="l00333"></a>00333 <span class="keywordflow">if</span> (d == 32)
<a name="l00334"></a>00334 depth = 24;
<a name="l00335"></a>00335 xres = (<a class="code" href="environ_8h.html#a9085c7874153c280a4171244aa052e4e">l_int32</a>)(39.37 * (<a class="code" href="environ_8h.html#af59419416d96ecf5fca70c8d05adb456">l_float32</a>)<a class="code" href="leptprotos_8h.html#ab47b081faee7f1193117ece8178daaee">pixGetXRes</a>(pix) + 0.5); <span class="comment">/* to ppm */</span>
<a name="l00336"></a>00336 yres = (<a class="code" href="environ_8h.html#a9085c7874153c280a4171244aa052e4e">l_int32</a>)(39.37 * (<a class="code" href="environ_8h.html#af59419416d96ecf5fca70c8d05adb456">l_float32</a>)<a class="code" href="leptprotos_8h.html#a0af66aa6035deb8e431e79cb3aeb645d">pixGetYRes</a>(pix) + 0.5); <span class="comment">/* to ppm */</span>
<a name="l00337"></a>00337
<a name="l00338"></a>00338 pixWpl = <a class="code" href="leptprotos_8h.html#af0b490472ab7999f208098dd37167d73">pixGetWpl</a>(pix);
<a name="l00339"></a>00339 pixBpl = 4 * pixWpl;
<a name="l00340"></a>00340 fileWpl = (width * depth + 31) / 32;
<a name="l00341"></a>00341 fileBpl = 4 * fileWpl;
<a name="l00342"></a>00342 fileimagebytes = height * fileBpl;
<a name="l00343"></a>00343
<a name="l00344"></a>00344 heapcm = 0;
<a name="l00345"></a>00345 <span class="keywordflow">if</span> (d == 32) { <span class="comment">/* 24 bpp rgb; no colormap */</span>
<a name="l00346"></a>00346 ncolors = 0;
<a name="l00347"></a>00347 cmaplen = 0;
<a name="l00348"></a>00348 }
<a name="l00349"></a>00349 <span class="keywordflow">else</span> <span class="keywordflow">if</span> ((cmap = <a class="code" href="leptprotos_8h.html#a6c959f1c381ebe5a4abc867a3d8ae1e6">pixGetColormap</a>(pix))) { <span class="comment">/* existing colormap */</span>
<a name="l00350"></a>00350 ncolors = <a class="code" href="colormap_8c.html#a29729fdc7efb3d4b7103696eb86be42f">pixcmapGetCount</a>(cmap);
<a name="l00351"></a>00351 cmaplen = ncolors * <span class="keyword">sizeof</span>(<a class="code" href="pix_8h.html#ac4b7ee5b0e033dd9df33e464059cdf87">RGBA_QUAD</a>);
<a name="l00352"></a>00352 cta = (<a class="code" href="environ_8h.html#a7ed60554e7d6dd89aca643189b1e70ad">l_uint8</a> *)cmap-><a class="code" href="struct_pix_colormap.html#a2a14164dbec38ebab11eee1bea569cbc">array</a>;
<a name="l00353"></a>00353 }
<a name="l00354"></a>00354 <span class="keywordflow">else</span> { <span class="comment">/* no existing colormap; make a binary or gray one */</span>
<a name="l00355"></a>00355 <span class="keywordflow">if</span> (d == 1) {
<a name="l00356"></a>00356 cmaplen = <span class="keyword">sizeof</span>(<a class="code" href="bmpio_8c.html#ad518de84c6ad97174674d26b45f721b7">bwmap</a>);
<a name="l00357"></a>00357 ncolors = 2;
<a name="l00358"></a>00358 cta = (<a class="code" href="environ_8h.html#a7ed60554e7d6dd89aca643189b1e70ad">l_uint8</a> *)bwmap;
<a name="l00359"></a>00359 }
<a name="l00360"></a>00360 <span class="keywordflow">else</span> { <span class="comment">/* d != 32; output grayscale version */</span>
<a name="l00361"></a>00361 ncolors = 1 << depth;
<a name="l00362"></a>00362 cmaplen = ncolors * <span class="keyword">sizeof</span>(<a class="code" href="pix_8h.html#ac4b7ee5b0e033dd9df33e464059cdf87">RGBA_QUAD</a>);
<a name="l00363"></a>00363
<a name="l00364"></a>00364 heapcm = 1;
<a name="l00365"></a>00365 <span class="keywordflow">if</span> ((cta = (<a class="code" href="environ_8h.html#a7ed60554e7d6dd89aca643189b1e70ad">l_uint8</a> *)<a class="code" href="environ_8h.html#abc24891c647be0bd23e233d013175da0">CALLOC</a>(cmaplen, 1)) == <a class="code" href="environ_8h.html#a070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>)
<a name="l00366"></a>00366 <span class="keywordflow">return</span> <a class="code" href="environ_8h.html#a8b17fe871312c2e1613fa694bb78a963">ERROR_INT</a>(<span class="stringliteral">"colormap alloc fail"</span>, procName, 1);
<a name="l00367"></a>00367
<a name="l00368"></a>00368 stepsize = 255 / (ncolors - 1);
<a name="l00369"></a>00369 <span class="keywordflow">for</span> (i = 0, val = 0, pquad = (<a class="code" href="struct_r_g_b_a___quad.html">RGBA_QUAD</a> *)cta;
<a name="l00370"></a>00370 i < ncolors;
<a name="l00371"></a>00371 i++, val += stepsize, pquad++) {
<a name="l00372"></a>00372 pquad-><a class="code" href="struct_r_g_b_a___quad.html#a57ceb621e5e83bc2d8b9d78cc426cefd">blue</a> = pquad-><a class="code" href="struct_r_g_b_a___quad.html#a32f8a3f2225995fcedfb6d80bb480c05">green</a> = pquad-><a class="code" href="struct_r_g_b_a___quad.html#a9ad88fbc3a671fbe8406e608b59563fa">red</a> = val;
<a name="l00373"></a>00373 }
<a name="l00374"></a>00374 }
<a name="l00375"></a>00375 }
<a name="l00376"></a>00376
<a name="l00377"></a>00377 <span class="preprocessor">#if DEBUG</span>
<a name="l00378"></a>00378 <span class="preprocessor"></span> {<a class="code" href="environ_8h.html#a7ed60554e7d6dd89aca643189b1e70ad">l_uint8</a> *pcmptr;
<a name="l00379"></a>00379 pcmptr = (<a class="code" href="environ_8h.html#a7ed60554e7d6dd89aca643189b1e70ad">l_uint8</a> *)<a class="code" href="leptprotos_8h.html#a6c959f1c381ebe5a4abc867a3d8ae1e6">pixGetColormap</a>(pix)-><a class="code" href="struct_pix_colormap.html#a2a14164dbec38ebab11eee1bea569cbc">array</a>;
<a name="l00380"></a>00380 fprintf(stderr, <span class="stringliteral">"Pix colormap[0] = %c%c%c%d\n"</span>,
<a name="l00381"></a>00381 pcmptr[0], pcmptr[1], pcmptr[2], pcmptr[3]);
<a name="l00382"></a>00382 fprintf(stderr, <span class="stringliteral">"Pix colormap[1] = %c%c%c%d\n"</span>,
<a name="l00383"></a>00383 pcmptr[4], pcmptr[5], pcmptr[6], pcmptr[7]);
<a name="l00384"></a>00384 }
<a name="l00385"></a>00385 <span class="preprocessor">#endif </span><span class="comment">/* DEBUG */</span>
<a name="l00386"></a>00386
<a name="l00387"></a>00387 fseek(fp, 0L, 0);
<a name="l00388"></a>00388
<a name="l00389"></a>00389 <span class="comment">/* Convert to little-endian and write the file header data */</span>
<a name="l00390"></a>00390 bfType = <a class="code" href="leptprotos_8h.html#a40491aa07db4319c7619ffaa0bc26a89">convertOnBigEnd16</a>(<a class="code" href="imageio_8h.html#a0411cd49bb5b71852cecd93bcbf0ca2da5e1a56e4cb61aac4e5e7a99e981aa00d">BMP_ID</a>);
<a name="l00391"></a>00391 offbytes = <a class="code" href="bmp_8h.html#a90aeed1cb2bc4d1ab703c222dd6d68fe">BMP_FHBYTES</a> + <a class="code" href="bmp_8h.html#a53928f289637b030bb034eab53a28eff">BMP_IHBYTES</a> + cmaplen;
<a name="l00392"></a>00392 filebytes = offbytes + fileimagebytes;
<a name="l00393"></a>00393 sval = filebytes & 0x0000ffff;
<a name="l00394"></a>00394 bfSize = <a class="code" href="leptprotos_8h.html#a40491aa07db4319c7619ffaa0bc26a89">convertOnBigEnd16</a>(sval);
<a name="l00395"></a>00395 sval = (filebytes >> 16) & 0x0000ffff;
<a name="l00396"></a>00396 bfFill1 = <a class="code" href="leptprotos_8h.html#a40491aa07db4319c7619ffaa0bc26a89">convertOnBigEnd16</a>(sval);
<a name="l00397"></a>00397 bfReserved1 = 0;
<a name="l00398"></a>00398 bfReserved2 = 0;
<a name="l00399"></a>00399 sval = offbytes & 0x0000ffff;
<a name="l00400"></a>00400 bfOffBits = <a class="code" href="leptprotos_8h.html#a40491aa07db4319c7619ffaa0bc26a89">convertOnBigEnd16</a>(sval);
<a name="l00401"></a>00401 sval = (offbytes >> 16) & 0x0000ffff;
<a name="l00402"></a>00402 bfFill2 = <a class="code" href="leptprotos_8h.html#a40491aa07db4319c7619ffaa0bc26a89">convertOnBigEnd16</a>(sval);
<a name="l00403"></a>00403 fwrite(&bfType, 1, 2, fp);
<a name="l00404"></a>00404 fwrite(&bfSize, 1, 2, fp);
<a name="l00405"></a>00405 fwrite(&bfFill1, 1, 2, fp);
<a name="l00406"></a>00406 fwrite(&bfReserved1, 1, 2, fp);
<a name="l00407"></a>00407 fwrite(&bfReserved1, 1, 2, fp);
<a name="l00408"></a>00408 fwrite(&bfOffBits, 1, 2, fp);
<a name="l00409"></a>00409 fwrite(&bfFill2, 1, 2, fp);
<a name="l00410"></a>00410
<a name="l00411"></a>00411 <span class="comment">/* Convert to little-endian and write the info header data */</span>
<a name="l00412"></a>00412 biSize = <a class="code" href="leptprotos_8h.html#af93e9578057fc644074cd408cc8c52ed">convertOnBigEnd32</a>(<a class="code" href="bmp_8h.html#a53928f289637b030bb034eab53a28eff">BMP_IHBYTES</a>);
<a name="l00413"></a>00413 biWidth = <a class="code" href="leptprotos_8h.html#af93e9578057fc644074cd408cc8c52ed">convertOnBigEnd32</a>(width);
<a name="l00414"></a>00414 biHeight = <a class="code" href="leptprotos_8h.html#af93e9578057fc644074cd408cc8c52ed">convertOnBigEnd32</a>(height);
<a name="l00415"></a>00415 biPlanes = <a class="code" href="leptprotos_8h.html#a40491aa07db4319c7619ffaa0bc26a89">convertOnBigEnd16</a>(1);
<a name="l00416"></a>00416 biBitCount = <a class="code" href="leptprotos_8h.html#a40491aa07db4319c7619ffaa0bc26a89">convertOnBigEnd16</a>(depth);
<a name="l00417"></a>00417 biCompression = 0;
<a name="l00418"></a>00418 biSizeImage = <a class="code" href="leptprotos_8h.html#af93e9578057fc644074cd408cc8c52ed">convertOnBigEnd32</a>(fileimagebytes);
<a name="l00419"></a>00419 biXPelsPerMeter = <a class="code" href="leptprotos_8h.html#af93e9578057fc644074cd408cc8c52ed">convertOnBigEnd32</a>(xres);
<a name="l00420"></a>00420 biYPelsPerMeter = <a class="code" href="leptprotos_8h.html#af93e9578057fc644074cd408cc8c52ed">convertOnBigEnd32</a>(yres);
<a name="l00421"></a>00421 biClrUsed = <a class="code" href="leptprotos_8h.html#af93e9578057fc644074cd408cc8c52ed">convertOnBigEnd32</a>(ncolors);
<a name="l00422"></a>00422 biClrImportant = <a class="code" href="leptprotos_8h.html#af93e9578057fc644074cd408cc8c52ed">convertOnBigEnd32</a>(ncolors);
<a name="l00423"></a>00423 fwrite(&biSize, 1, 4, fp);
<a name="l00424"></a>00424 fwrite(&biWidth, 1, 4, fp);
<a name="l00425"></a>00425 fwrite(&biHeight, 1, 4, fp);
<a name="l00426"></a>00426 fwrite(&biPlanes, 1, 2, fp);
<a name="l00427"></a>00427 fwrite(&biBitCount, 1, 2, fp);
<a name="l00428"></a>00428 fwrite(&biCompression, 1, 4, fp);
<a name="l00429"></a>00429 fwrite(&biSizeImage, 1, 4, fp);
<a name="l00430"></a>00430 fwrite(&biXPelsPerMeter, 1, 4, fp);
<a name="l00431"></a>00431 fwrite(&biYPelsPerMeter, 1, 4, fp);
<a name="l00432"></a>00432 fwrite(&biClrUsed, 1, 4, fp);
<a name="l00433"></a>00433 fwrite(&biClrImportant, 1, 4, fp);
<a name="l00434"></a>00434
<a name="l00435"></a>00435 <span class="comment">/* Write the colormap data */</span>
<a name="l00436"></a>00436 <span class="keywordflow">if</span> (ncolors > 0) {
<a name="l00437"></a>00437 <span class="keywordflow">if</span> (fwrite(cta, 1, cmaplen, fp) != cmaplen) {
<a name="l00438"></a>00438 <span class="keywordflow">if</span> (heapcm)
<a name="l00439"></a>00439 <a class="code" href="environ_8h.html#a105949c59c998e38aad80266afac92bf">FREE</a>(cta);
<a name="l00440"></a>00440 <span class="keywordflow">return</span> <a class="code" href="environ_8h.html#a8b17fe871312c2e1613fa694bb78a963">ERROR_INT</a>(<span class="stringliteral">"colormap write fail"</span>, procName, 1);
<a name="l00441"></a>00441 }
<a name="l00442"></a>00442 <span class="keywordflow">if</span> (heapcm)
<a name="l00443"></a>00443 <a class="code" href="environ_8h.html#a105949c59c998e38aad80266afac92bf">FREE</a>(cta);
<a name="l00444"></a>00444 }
<a name="l00445"></a>00445
<a name="l00446"></a>00446 <span class="comment">/* When you write a binary image with a colormap</span>
<a name="l00447"></a>00447 <span class="comment"> * that sets BLACK to 0, you must invert the data */</span>
<a name="l00448"></a>00448 <span class="keywordflow">if</span> (depth == 1 && cmap && ((<a class="code" href="environ_8h.html#a7ed60554e7d6dd89aca643189b1e70ad">l_uint8</a> *)(cmap-><a class="code" href="struct_pix_colormap.html#a2a14164dbec38ebab11eee1bea569cbc">array</a>))[0] == 0<a class="code" href="maze__reg_8c.html#ae3c674b4ae0bbed35e9c46c83addb90c">x0</a>) {
<a name="l00449"></a>00449 <a class="code" href="leptprotos_8h.html#a6f0dcf6a1fb094a9354b2ec890d46f0c">pixInvert</a>(pix, pix);
<a name="l00450"></a>00450 }
<a name="l00451"></a>00451
<a name="l00452"></a>00452 <a class="code" href="leptprotos_8h.html#a3c2ace8f3051e291a9accec2e4213275">pixEndianByteSwap</a>(pix);
<a name="l00453"></a>00453
<a name="l00454"></a>00454 writeerror = 0;
<a name="l00455"></a>00455 <span class="keywordflow">if</span> (depth != 24) { <span class="comment">/* typ 1 or 8 bpp */</span>
<a name="l00456"></a>00456 data = (<a class="code" href="environ_8h.html#a7ed60554e7d6dd89aca643189b1e70ad">l_uint8</a> *)<a class="code" href="leptprotos_8h.html#a44546f758f2cf71bb109bfc114e3ca7f">pixGetData</a>(pix) + pixBpl * (height - 1);
<a name="l00457"></a>00457 <span class="keywordflow">for</span> (i = 0; i < height; i++) {
<a name="l00458"></a>00458 <span class="keywordflow">if</span> (fwrite(data, 1, fileBpl, fp) != fileBpl)
<a name="l00459"></a>00459 writeerror = 1;
<a name="l00460"></a>00460 data -= pixBpl;
<a name="l00461"></a>00461 }
<a name="l00462"></a>00462 }
<a name="l00463"></a>00463 <span class="keywordflow">else</span> { <span class="comment">/* 32 bpp pix; 24 bpp file</span>
<a name="l00464"></a>00464 <span class="comment"> * See the comments in pixReadStreamBMP() to</span>
<a name="l00465"></a>00465 <span class="comment"> * understand the logic behind the pixel ordering below.</span>
<a name="l00466"></a>00466 <span class="comment"> * Note that we have again done an endian swap on</span>
<a name="l00467"></a>00467 <span class="comment"> * little endian machines before arriving here, so that</span>
<a name="l00468"></a>00468 <span class="comment"> * the bytes are ordered on both platforms as:</span>
<a name="l00469"></a>00469 <span class="comment"> Red Green Blue --</span>
<a name="l00470"></a>00470 <span class="comment"> |-----------|------------|-----------|-----------|</span>
<a name="l00471"></a>00471 <span class="comment"> */</span>
<a name="l00472"></a>00472 extrabytes = fileBpl - 3 * width;
<a name="l00473"></a>00473 line = <a class="code" href="leptprotos_8h.html#a44546f758f2cf71bb109bfc114e3ca7f">pixGetData</a>(pix) + pixWpl * (height - 1);
<a name="l00474"></a>00474 <span class="keywordflow">for</span> (i = 0; i < height; i++) {
<a name="l00475"></a>00475 <span class="keywordflow">for</span> (j = 0; j < width; j++) {
<a name="l00476"></a>00476 pword = line + j;
<a name="l00477"></a>00477 pel[2] = *((<a class="code" href="environ_8h.html#a7ed60554e7d6dd89aca643189b1e70ad">l_uint8</a> *)pword + <a class="code" href="pix_8h.html#a7ff5f2dff38e7639981794c43dc9167ba592503b9434c1e751a92f3fc536d7950">COLOR_RED</a>);
<a name="l00478"></a>00478 pel[1] = *((<a class="code" href="environ_8h.html#a7ed60554e7d6dd89aca643189b1e70ad">l_uint8</a> *)pword + <a class="code" href="pix_8h.html#a7ff5f2dff38e7639981794c43dc9167bacfa9d8bbffc418447ed826f286abca02">COLOR_GREEN</a>);
<a name="l00479"></a>00479 pel[0] = *((<a class="code" href="environ_8h.html#a7ed60554e7d6dd89aca643189b1e70ad">l_uint8</a> *)pword + <a class="code" href="pix_8h.html#a7ff5f2dff38e7639981794c43dc9167ba1340428efccb140dcbdb71aa6176f696">COLOR_BLUE</a>);
<a name="l00480"></a>00480 <span class="keywordflow">if</span> (fwrite(&pel, 1, 3, fp) != 3)
<a name="l00481"></a>00481 writeerror = 1;
<a name="l00482"></a>00482 }
<a name="l00483"></a>00483 <span class="keywordflow">if</span> (extrabytes) {
<a name="l00484"></a>00484 <span class="keywordflow">for</span> (k = 0; k < extrabytes; k++)
<a name="l00485"></a>00485 fwrite(&pel, 1, 1, fp);
<a name="l00486"></a>00486 }
<a name="l00487"></a>00487 line -= pixWpl;
<a name="l00488"></a>00488 }
<a name="l00489"></a>00489 }
<a name="l00490"></a>00490
<a name="l00491"></a>00491 <span class="comment">/* Restore to original state */</span>
<a name="l00492"></a>00492 <a class="code" href="leptprotos_8h.html#a3c2ace8f3051e291a9accec2e4213275">pixEndianByteSwap</a>(pix);
<a name="l00493"></a>00493 <span class="keywordflow">if</span> (depth == 1 && cmap && ((<a class="code" href="environ_8h.html#a7ed60554e7d6dd89aca643189b1e70ad">l_uint8</a> *)(cmap-><a class="code" href="struct_pix_colormap.html#a2a14164dbec38ebab11eee1bea569cbc">array</a>))[0] == 0<a class="code" href="maze__reg_8c.html#ae3c674b4ae0bbed35e9c46c83addb90c">x0</a>)
<a name="l00494"></a>00494 <a class="code" href="leptprotos_8h.html#a6f0dcf6a1fb094a9354b2ec890d46f0c">pixInvert</a>(pix, pix);
<a name="l00495"></a>00495
<a name="l00496"></a>00496 <span class="keywordflow">if</span> (writeerror)
<a name="l00497"></a>00497 <span class="keywordflow">return</span> <a class="code" href="environ_8h.html#a8b17fe871312c2e1613fa694bb78a963">ERROR_INT</a>(<span class="stringliteral">"image write fail"</span>, procName, 1);
<a name="l00498"></a>00498
<a name="l00499"></a>00499 <span class="keywordflow">return</span> 0;
<a name="l00500"></a>00500 }
<a name="l00501"></a>00501
<a name="l00502"></a>00502
<a name="l00503"></a>00503 <span class="comment">/*---------------------------------------------------------------------*</span>
<a name="l00504"></a>00504 <span class="comment"> * Read/write to memory *</span>
<a name="l00505"></a>00505 <span class="comment"> *---------------------------------------------------------------------*/</span>
<a name="l00506"></a>00506 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
<a name="l00507"></a>00507 <span class="preprocessor"></span><span class="preprocessor">#include "config_auto.h"</span>
<a name="l00508"></a>00508 <span class="preprocessor">#endif </span><span class="comment">/* HAVE_CONFIG_H */</span>
<a name="l00509"></a>00509
<a name="l00510"></a>00510 <span class="preprocessor">#if HAVE_FMEMOPEN</span>
<a name="l00511"></a>00511 <span class="preprocessor"></span>
<a name="l00512"></a>00512 <span class="keyword">extern</span> FILE *open_memstream(<span class="keywordtype">char</span> **data, <span class="keywordtype">size_t</span> *<a class="code" href="warper__reg_8c.html#a711275dc7bbe85bb6fa721bc60b8637c">size</a>);
<a name="l00513"></a>00513 <span class="keyword">extern</span> FILE *fmemopen(<span class="keywordtype">void</span> *data, <span class="keywordtype">size_t</span> <a class="code" href="warper__reg_8c.html#a711275dc7bbe85bb6fa721bc60b8637c">size</a>, <span class="keyword">const</span> <span class="keywordtype">char</span> *mode);
<a name="l00514"></a>00514 <span class="comment"></span>
<a name="l00515"></a>00515 <span class="comment">/*!</span>
<a name="l00516"></a>00516 <span class="comment"> * pixReadMemBmp()</span>
<a name="l00517"></a>00517 <span class="comment"> *</span>
<a name="l00518"></a>00518 <span class="comment"> * Input: cdata (const; bmp-encoded)</span>
<a name="l00519"></a>00519 <span class="comment"> * size (of data)</span>
<a name="l00520"></a>00520 <span class="comment"> * Return: pix, or null on error</span>
<a name="l00521"></a>00521 <span class="comment"> *</span>
<a name="l00522"></a>00522 <span class="comment"> * Notes:</span>
<a name="l00523"></a>00523 <span class="comment"> * (1) The @size byte of @data must be a null character.</span>
<a name="l00524"></a>00524 <span class="comment"> */</span>
<a name="l00525"></a>00525 <a class="code" href="struct_pix.html">PIX</a> *
<a name="l00526"></a>00526 <a class="code" href="bmpio_8c.html#a4ae1d381ec4abb36c539f484a69fb417">pixReadMemBmp</a>(<span class="keyword">const</span> <a class="code" href="environ_8h.html#a7ed60554e7d6dd89aca643189b1e70ad">l_uint8</a> *cdata,
<a name="l00527"></a>00527 <span class="keywordtype">size_t</span> <a class="code" href="warper__reg_8c.html#a711275dc7bbe85bb6fa721bc60b8637c">size</a>)
<a name="l00528"></a>00528 {
<a name="l00529"></a>00529 <a class="code" href="environ_8h.html#a7ed60554e7d6dd89aca643189b1e70ad">l_uint8</a> *data;
<a name="l00530"></a>00530 FILE *fp;
<a name="l00531"></a>00531 <a class="code" href="struct_pix.html">PIX</a> *pix;
<a name="l00532"></a>00532
<a name="l00533"></a>00533 <a class="code" href="environ_8h.html#a1a16952819bcbc526c998e3ac86f2e78">PROCNAME</a>(<span class="stringliteral">"pixReadMemBmp"</span>);
<a name="l00534"></a>00534
<a name="l00535"></a>00535 <span class="keywordflow">if</span> (!cdata)
<a name="l00536"></a>00536 <span class="keywordflow">return</span> (<a class="code" href="struct_pix.html">PIX</a> *)<a class="code" href="environ_8h.html#a38a8310a83847948c9ce6620983be468">ERROR_PTR</a>(<span class="stringliteral">"cdata not defined"</span>, procName, <a class="code" href="environ_8h.html#a070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>);
<a name="l00537"></a>00537
<a name="l00538"></a>00538 data = (<a class="code" href="environ_8h.html#a7ed60554e7d6dd89aca643189b1e70ad">l_uint8</a> *)cdata; <span class="comment">/* we're really not going to change this */</span>
<a name="l00539"></a>00539 <span class="keywordflow">if</span> ((fp = fmemopen(data, size, <span class="stringliteral">"r"</span>)) == <a class="code" href="environ_8h.html#a070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>)
<a name="l00540"></a>00540 <span class="keywordflow">return</span> (<a class="code" href="struct_pix.html">PIX</a> *)<a class="code" href="environ_8h.html#a38a8310a83847948c9ce6620983be468">ERROR_PTR</a>(<span class="stringliteral">"stream not opened"</span>, procName, <a class="code" href="environ_8h.html#a070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>);
<a name="l00541"></a>00541 pix = <a class="code" href="bmpio_8c.html#a657bc3de2cab48f6e93d7536f007635b">pixReadStreamBmp</a>(fp);
<a name="l00542"></a>00542 fclose(fp);
<a name="l00543"></a>00543 <span class="keywordflow">return</span> pix;
<a name="l00544"></a>00544 }
<a name="l00545"></a>00545
<a name="l00546"></a>00546 <span class="comment"></span>
<a name="l00547"></a>00547 <span class="comment">/*!</span>
<a name="l00548"></a>00548 <span class="comment"> * pixWriteMemBmp()</span>
<a name="l00549"></a>00549 <span class="comment"> *</span>
<a name="l00550"></a>00550 <span class="comment"> * Input: &data (<return> data of tiff compressed image)</span>
<a name="l00551"></a>00551 <span class="comment"> * &size (<return> size of returned data)</span>
<a name="l00552"></a>00552 <span class="comment"> * pix</span>
<a name="l00553"></a>00553 <span class="comment"> * Return: 0 if OK, 1 on error</span>
<a name="l00554"></a>00554 <span class="comment"> *</span>
<a name="l00555"></a>00555 <span class="comment"> * Notes:</span>
<a name="l00556"></a>00556 <span class="comment"> * (1) See pixWriteStreamBmp() for usage. This version writes to</span>
<a name="l00557"></a>00557 <span class="comment"> * memory instead of to a file stream.</span>
<a name="l00558"></a>00558 <span class="comment"> */</span>
<a name="l00559"></a>00559 <a class="code" href="environ_8h.html#a9085c7874153c280a4171244aa052e4e">l_int32</a>
<a name="l00560"></a>00560 <a class="code" href="bmpio_8c.html#adc2d7d49277594af003631ee18fde2bd">pixWriteMemBmp</a>(<a class="code" href="environ_8h.html#a7ed60554e7d6dd89aca643189b1e70ad">l_uint8</a> **pdata,
<a name="l00561"></a>00561 <span class="keywordtype">size_t</span> *psize,
<a name="l00562"></a>00562 <a class="code" href="struct_pix.html">PIX</a> *pix)
<a name="l00563"></a>00563 {
<a name="l00564"></a>00564 <a class="code" href="environ_8h.html#a9085c7874153c280a4171244aa052e4e">l_int32</a> ret;
<a name="l00565"></a>00565 FILE *fp;
<a name="l00566"></a>00566
<a name="l00567"></a>00567 <a class="code" href="environ_8h.html#a1a16952819bcbc526c998e3ac86f2e78">PROCNAME</a>(<span class="stringliteral">"pixWriteMemBmp"</span>);
<a name="l00568"></a>00568
<a name="l00569"></a>00569 <span class="keywordflow">if</span> (!pdata)
<a name="l00570"></a>00570 <span class="keywordflow">return</span> <a class="code" href="environ_8h.html#a8b17fe871312c2e1613fa694bb78a963">ERROR_INT</a>(<span class="stringliteral">"&data not defined"</span>, procName, 1 );
<a name="l00571"></a>00571 <span class="keywordflow">if</span> (!psize)
<a name="l00572"></a>00572 <span class="keywordflow">return</span> <a class="code" href="environ_8h.html#a8b17fe871312c2e1613fa694bb78a963">ERROR_INT</a>(<span class="stringliteral">"&size not defined"</span>, procName, 1 );
<a name="l00573"></a>00573 <span class="keywordflow">if</span> (!pix)
<a name="l00574"></a>00574 <span class="keywordflow">return</span> <a class="code" href="environ_8h.html#a8b17fe871312c2e1613fa694bb78a963">ERROR_INT</a>(<span class="stringliteral">"&pix not defined"</span>, procName, 1 );
<a name="l00575"></a>00575
<a name="l00576"></a>00576 <span class="keywordflow">if</span> ((fp = open_memstream((<span class="keywordtype">char</span> **)pdata, psize)) == <a class="code" href="environ_8h.html#a070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>)
<a name="l00577"></a>00577 <span class="keywordflow">return</span> <a class="code" href="environ_8h.html#a8b17fe871312c2e1613fa694bb78a963">ERROR_INT</a>(<span class="stringliteral">"stream not opened"</span>, procName, 1);
<a name="l00578"></a>00578 ret = <a class="code" href="bmpio_8c.html#a223012d6d4376e683c92acc9687ba337">pixWriteStreamBmp</a>(fp, pix);
<a name="l00579"></a>00579 fclose(fp);
<a name="l00580"></a>00580 <span class="keywordflow">return</span> ret;
<a name="l00581"></a>00581 }
<a name="l00582"></a>00582
<a name="l00583"></a>00583 <span class="preprocessor">#else</span>
<a name="l00584"></a>00584 <span class="preprocessor"></span>
<a name="l00585"></a>00585 <a class="code" href="struct_pix.html">PIX</a> *
<a name="l00586"></a><a class="code" href="leptprotos_8h.html#a6a9d0b88b6abb4e7ae3dd198c07f0f8f">00586</a> <a class="code" href="bmpio_8c.html#a4ae1d381ec4abb36c539f484a69fb417">pixReadMemBmp</a>(<span class="keyword">const</span> <a class="code" href="environ_8h.html#a7ed60554e7d6dd89aca643189b1e70ad">l_uint8</a> *cdata,
<a name="l00587"></a>00587 <span class="keywordtype">size_t</span> size)
<a name="l00588"></a>00588 {
<a name="l00589"></a>00589 <span class="keywordflow">return</span> (<a class="code" href="struct_pix.html">PIX</a> *)<a class="code" href="environ_8h.html#a38a8310a83847948c9ce6620983be468">ERROR_PTR</a>(
<a name="l00590"></a>00590 <span class="stringliteral">"bmp read from memory not implemented on this platform"</span>,
<a name="l00591"></a>00591 <span class="stringliteral">"pixReadMemBmp"</span>, <a class="code" href="environ_8h.html#a070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>);
<a name="l00592"></a>00592 }
<a name="l00593"></a>00593
<a name="l00594"></a>00594
<a name="l00595"></a>00595 <a class="code" href="environ_8h.html#a9085c7874153c280a4171244aa052e4e">l_int32</a>
<a name="l00596"></a><a class="code" href="leptprotos_8h.html#a8e60c873d67a29b8e1895799f4de967f">00596</a> <a class="code" href="bmpio_8c.html#adc2d7d49277594af003631ee18fde2bd">pixWriteMemBmp</a>(<a class="code" href="environ_8h.html#a7ed60554e7d6dd89aca643189b1e70ad">l_uint8</a> **pdata,
<a name="l00597"></a>00597 <span class="keywordtype">size_t</span> *psize,
<a name="l00598"></a>00598 <a class="code" href="struct_pix.html">PIX</a> *pix)
<a name="l00599"></a>00599 {
<a name="l00600"></a>00600 <span class="keywordflow">return</span> <a class="code" href="environ_8h.html#a8b17fe871312c2e1613fa694bb78a963">ERROR_INT</a>(
<a name="l00601"></a>00601 <span class="stringliteral">"bmp write to memory not implemented on this platform"</span>,
<a name="l00602"></a>00602 <span class="stringliteral">"pixWriteMemBmp"</span>, 1);
<a name="l00603"></a>00603 }
<a name="l00604"></a>00604
<a name="l00605"></a>00605 <span class="preprocessor">#endif </span><span class="comment">/* HAVE_FMEMOPEN */</span>
<a name="l00606"></a>00606
<a name="l00607"></a>00607 <span class="comment">/* --------------------------------------------*/</span>
<a name="l00608"></a>00608 <span class="preprocessor">#endif </span><span class="comment">/* USE_BMPIO */</span>
<a name="l00609"></a>00609 <span class="comment">/* --------------------------------------------*/</span>
<a name="l00610"></a>00610
</pre></div></div>
</div>
<div id="nav-path" class="navpath">
<ul>
<li class="navelem"><a class="el" href="bmpio_8c.html">bmpio.c</a> </li>
<li class="footer">Generated by 
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.3 </li>
</ul>
</div>
<!--- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark"> </span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark"> </span>Data Structures</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark"> </span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark"> </span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark"> </span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark"> </span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark"> </span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark"> </span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark"> </span>Defines</a></div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
</body>
</html>