/
tif_ojpeg.c
2563 lines (2447 loc) · 76.6 KB
/
tif_ojpeg.c
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
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* $Id: tif_ojpeg.c,v 1.69 2017-04-27 17:29:26 erouault Exp $ */
/* WARNING: The type of JPEG encapsulation defined by the TIFF Version 6.0
specification is now totally obsolete and deprecated for new applications and
images. This file was was created solely in order to read unconverted images
still present on some users' computer systems. It will never be extended
to write such files. Writing new-style JPEG compressed TIFFs is implemented
in tif_jpeg.c.
The code is carefully crafted to robustly read all gathered JPEG-in-TIFF
testfiles, and anticipate as much as possible all other... But still, it may
fail on some. If you encounter problems, please report them on the TIFF
mailing list and/or to Joris Van Damme <info@awaresystems.be>.
Please read the file called "TIFF Technical Note #2" if you need to be
convinced this compression scheme is bad and breaks TIFF. That document
is linked to from the LibTiff site <http://www.remotesensing.org/libtiff/>
and from AWare Systems' TIFF section
<http://www.awaresystems.be/imaging/tiff.html>. It is also absorbed
in Adobe's specification supplements, marked "draft" up to this day, but
supported by the TIFF community.
This file interfaces with Release 6B of the JPEG Library written by the
Independent JPEG Group. Previous versions of this file required a hack inside
the LibJpeg library. This version no longer requires that. Remember to
remove the hack if you update from the old version.
Copyright (c) Joris Van Damme <info@awaresystems.be>
Copyright (c) AWare Systems <http://www.awaresystems.be/>
The licence agreement for this file is the same as the rest of the LibTiff
library.
IN NO EVENT SHALL JORIS VAN DAMME OR AWARE SYSTEMS BE LIABLE FOR
ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
OF THIS SOFTWARE.
Joris Van Damme and/or AWare Systems may be available for custom
development. If you like what you see, and need anything similar or related,
contact <info@awaresystems.be>.
*/
/* What is what, and what is not?
This decoder starts with an input stream, that is essentially the JpegInterchangeFormat
stream, if any, followed by the strile data, if any. This stream is read in
OJPEGReadByte and related functions.
It analyzes the start of this stream, until it encounters non-marker data, i.e.
compressed image data. Some of the header markers it sees have no actual content,
like the SOI marker, and APP/COM markers that really shouldn't even be there. Some
other markers do have content, and the valuable bits and pieces of information
in these markers are saved, checking all to verify that the stream is more or
less within expected bounds. This happens inside the OJPEGReadHeaderInfoSecStreamXxx
functions.
Some OJPEG imagery contains no valid JPEG header markers. This situation is picked
up on if we've seen no SOF marker when we're at the start of the compressed image
data. In this case, the tables are read from JpegXxxTables tags, and the other
bits and pieces of information is initialized to its most basic value. This is
implemented in the OJPEGReadHeaderInfoSecTablesXxx functions.
When this is complete, a good and valid JPEG header can be assembled, and this is
passed through to LibJpeg. When that's done, the remainder of the input stream, i.e.
the compressed image data, can be passed through unchanged. This is done in
OJPEGWriteStream functions.
LibTiff rightly expects to know the subsampling values before decompression. Just like
in new-style JPEG-in-TIFF, though, or even more so, actually, the YCbCrsubsampling
tag is notoriously unreliable. To correct these tag values with the ones inside
the JPEG stream, the first part of the input stream is pre-scanned in
OJPEGSubsamplingCorrect, making no note of any other data, reporting no warnings
or errors, up to the point where either these values are read, or it's clear they
aren't there. This means that some of the data is read twice, but we feel speed
in correcting these values is important enough to warrant this sacrifice. Although
there is currently no define or other configuration mechanism to disable this behaviour,
the actual header scanning is build to robustly respond with error report if it
should encounter an uncorrected mismatch of subsampling values. See
OJPEGReadHeaderInfoSecStreamSof.
The restart interval and restart markers are the most tricky part... The restart
interval can be specified in a tag. It can also be set inside the input JPEG stream.
It can be used inside the input JPEG stream. If reading from strile data, we've
consistently discovered the need to insert restart markers in between the different
striles, as is also probably the most likely interpretation of the original TIFF 6.0
specification. With all this setting of interval, and actual use of markers that is not
predictable at the time of valid JPEG header assembly, the restart thing may turn
out the Achilles heel of this implementation. Fortunately, most OJPEG writer vendors
succeed in reading back what they write, which may be the reason why we've been able
to discover ways that seem to work.
Some special provision is made for planarconfig separate OJPEG files. These seem
to consistently contain header info, a SOS marker, a plane, SOS marker, plane, SOS,
and plane. This may or may not be a valid JPEG configuration, we don't know and don't
care. We want LibTiff to be able to access the planes individually, without huge
buffering inside LibJpeg, anyway. So we compose headers to feed to LibJpeg, in this
case, that allow us to pass a single plane such that LibJpeg sees a valid
single-channel JPEG stream. Locating subsequent SOS markers, and thus subsequent
planes, is done inside OJPEGReadSecondarySos.
The benefit of the scheme is... that it works, basically. We know of no other that
does. It works without checking software tag, or otherwise going about things in an
OJPEG flavor specific manner. Instead, it is a single scheme, that covers the cases
with and without JpegInterchangeFormat, with and without striles, with part of
the header in JpegInterchangeFormat and remainder in first strile, etc. It is forgiving
and robust, may likely work with OJPEG flavors we've not seen yet, and makes most out
of the data.
Another nice side-effect is that a complete JPEG single valid stream is build if
planarconfig is not separate (vast majority). We may one day use that to build
converters to JPEG, and/or to new-style JPEG compression inside TIFF.
A disadvantage is the lack of random access to the individual striles. This is the
reason for much of the complicated restart-and-position stuff inside OJPEGPreDecode.
Applications would do well accessing all striles in order, as this will result in
a single sequential scan of the input stream, and no restarting of LibJpeg decoding
session.
*/
#define WIN32_LEAN_AND_MEAN
#define VC_EXTRALEAN
#include "tiffiop.h"
#ifdef OJPEG_SUPPORT
/* Configuration defines here are:
* JPEG_ENCAP_EXTERNAL: The normal way to call libjpeg, uses longjump. In some environments,
* like eg LibTiffDelphi, this is not possible. For this reason, the actual calls to
* libjpeg, with longjump stuff, are encapsulated in dedicated functions. When
* JPEG_ENCAP_EXTERNAL is defined, these encapsulating functions are declared external
* to this unit, and can be defined elsewhere to use stuff other then longjump.
* The default mode, without JPEG_ENCAP_EXTERNAL, implements the call encapsulators
* here, internally, with normal longjump.
* SETJMP, LONGJMP, JMP_BUF: On some machines/environments a longjump equivalent is
* conveniently available, but still it may be worthwhile to use _setjmp or sigsetjmp
* in place of plain setjmp. These macros will make it easier. It is useless
* to fiddle with these if you define JPEG_ENCAP_EXTERNAL.
* OJPEG_BUFFER: Define the size of the desired buffer here. Should be small enough so as to guarantee
* instant processing, optimal streaming and optimal use of processor cache, but also big
* enough so as to not result in significant call overhead. It should be at least a few
* bytes to accommodate some structures (this is verified in asserts), but it would not be
* sensible to make it this small anyway, and it should be at most 64K since it is indexed
* with uint16. We recommend 2K.
* EGYPTIANWALK: You could also define EGYPTIANWALK here, but it is not used anywhere and has
* absolutely no effect. That is why most people insist the EGYPTIANWALK is a bit silly.
*/
/* define LIBJPEG_ENCAP_EXTERNAL */
#define SETJMP(jbuf) setjmp(jbuf)
#define LONGJMP(jbuf,code) longjmp(jbuf,code)
#define JMP_BUF jmp_buf
#define OJPEG_BUFFER 2048
/* define EGYPTIANWALK */
#define JPEG_MARKER_SOF0 0xC0
#define JPEG_MARKER_SOF1 0xC1
#define JPEG_MARKER_SOF3 0xC3
#define JPEG_MARKER_DHT 0xC4
#define JPEG_MARKER_RST0 0XD0
#define JPEG_MARKER_SOI 0xD8
#define JPEG_MARKER_EOI 0xD9
#define JPEG_MARKER_SOS 0xDA
#define JPEG_MARKER_DQT 0xDB
#define JPEG_MARKER_DRI 0xDD
#define JPEG_MARKER_APP0 0xE0
#define JPEG_MARKER_COM 0xFE
#define FIELD_OJPEG_JPEGINTERCHANGEFORMAT (FIELD_CODEC+0)
#define FIELD_OJPEG_JPEGINTERCHANGEFORMATLENGTH (FIELD_CODEC+1)
#define FIELD_OJPEG_JPEGQTABLES (FIELD_CODEC+2)
#define FIELD_OJPEG_JPEGDCTABLES (FIELD_CODEC+3)
#define FIELD_OJPEG_JPEGACTABLES (FIELD_CODEC+4)
#define FIELD_OJPEG_JPEGPROC (FIELD_CODEC+5)
#define FIELD_OJPEG_JPEGRESTARTINTERVAL (FIELD_CODEC+6)
static const TIFFField ojpegFields[] = {
{TIFFTAG_JPEGIFOFFSET,1,1,TIFF_LONG8,0,TIFF_SETGET_UINT64,TIFF_SETGET_UNDEFINED,FIELD_OJPEG_JPEGINTERCHANGEFORMAT,TRUE,FALSE,"JpegInterchangeFormat",NULL},
{TIFFTAG_JPEGIFBYTECOUNT,1,1,TIFF_LONG8,0,TIFF_SETGET_UINT64,TIFF_SETGET_UNDEFINED,FIELD_OJPEG_JPEGINTERCHANGEFORMATLENGTH,TRUE,FALSE,"JpegInterchangeFormatLength",NULL},
{TIFFTAG_JPEGQTABLES,TIFF_VARIABLE2,TIFF_VARIABLE2,TIFF_LONG8,0,TIFF_SETGET_C32_UINT64,TIFF_SETGET_UNDEFINED,FIELD_OJPEG_JPEGQTABLES,FALSE,TRUE,"JpegQTables",NULL},
{TIFFTAG_JPEGDCTABLES,TIFF_VARIABLE2,TIFF_VARIABLE2,TIFF_LONG8,0,TIFF_SETGET_C32_UINT64,TIFF_SETGET_UNDEFINED,FIELD_OJPEG_JPEGDCTABLES,FALSE,TRUE,"JpegDcTables",NULL},
{TIFFTAG_JPEGACTABLES,TIFF_VARIABLE2,TIFF_VARIABLE2,TIFF_LONG8,0,TIFF_SETGET_C32_UINT64,TIFF_SETGET_UNDEFINED,FIELD_OJPEG_JPEGACTABLES,FALSE,TRUE,"JpegAcTables",NULL},
{TIFFTAG_JPEGPROC,1,1,TIFF_SHORT,0,TIFF_SETGET_UINT16,TIFF_SETGET_UNDEFINED,FIELD_OJPEG_JPEGPROC,FALSE,FALSE,"JpegProc",NULL},
{TIFFTAG_JPEGRESTARTINTERVAL,1,1,TIFF_SHORT,0,TIFF_SETGET_UINT16,TIFF_SETGET_UNDEFINED,FIELD_OJPEG_JPEGRESTARTINTERVAL,FALSE,FALSE,"JpegRestartInterval",NULL},
};
#ifndef LIBJPEG_ENCAP_EXTERNAL
#include <setjmp.h>
#endif
/* We undefine FAR to avoid conflict with JPEG definition */
#ifdef FAR
#undef FAR
#endif
/*
Libjpeg's jmorecfg.h defines INT16 and INT32, but only if XMD_H is
not defined. Unfortunately, the MinGW and Borland compilers include
a typedef for INT32, which causes a conflict. MSVC does not include
a conflicting typedef given the headers which are included.
*/
#if defined(__BORLANDC__) || defined(__MINGW32__)
# define XMD_H 1
#endif
/* Define "boolean" as unsigned char, not int, per Windows custom. */
#if defined(__WIN32__) && !defined(__MINGW32__)
# ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
typedef unsigned char boolean;
# endif
# define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
#endif
#include "jpeglib.h"
#include "jerror.h"
typedef struct jpeg_error_mgr jpeg_error_mgr;
typedef struct jpeg_common_struct jpeg_common_struct;
typedef struct jpeg_decompress_struct jpeg_decompress_struct;
typedef struct jpeg_source_mgr jpeg_source_mgr;
typedef enum {
osibsNotSetYet,
osibsJpegInterchangeFormat,
osibsStrile,
osibsEof
} OJPEGStateInBufferSource;
typedef enum {
ososSoi,
ososQTable0,ososQTable1,ososQTable2,ososQTable3,
ososDcTable0,ososDcTable1,ososDcTable2,ososDcTable3,
ososAcTable0,ososAcTable1,ososAcTable2,ososAcTable3,
ososDri,
ososSof,
ososSos,
ososCompressed,
ososRst,
ososEoi
} OJPEGStateOutState;
typedef struct {
TIFF* tif;
int decoder_ok;
#ifndef LIBJPEG_ENCAP_EXTERNAL
JMP_BUF exit_jmpbuf;
#endif
TIFFVGetMethod vgetparent;
TIFFVSetMethod vsetparent;
TIFFPrintMethod printdir;
uint64 file_size;
uint32 image_width;
uint32 image_length;
uint32 strile_width;
uint32 strile_length;
uint32 strile_length_total;
uint8 samples_per_pixel;
uint8 plane_sample_offset;
uint8 samples_per_pixel_per_plane;
uint64 jpeg_interchange_format;
uint64 jpeg_interchange_format_length;
uint8 jpeg_proc;
uint8 subsamplingcorrect;
uint8 subsamplingcorrect_done;
uint8 subsampling_tag;
uint8 subsampling_hor;
uint8 subsampling_ver;
uint8 subsampling_force_desubsampling_inside_decompression;
uint8 qtable_offset_count;
uint8 dctable_offset_count;
uint8 actable_offset_count;
uint64 qtable_offset[3];
uint64 dctable_offset[3];
uint64 actable_offset[3];
uint8* qtable[4];
uint8* dctable[4];
uint8* actable[4];
uint16 restart_interval;
uint8 restart_index;
uint8 sof_log;
uint8 sof_marker_id;
uint32 sof_x;
uint32 sof_y;
uint8 sof_c[3];
uint8 sof_hv[3];
uint8 sof_tq[3];
uint8 sos_cs[3];
uint8 sos_tda[3];
struct {
uint8 log;
OJPEGStateInBufferSource in_buffer_source;
uint32 in_buffer_next_strile;
uint64 in_buffer_file_pos;
uint64 in_buffer_file_togo;
} sos_end[3];
uint8 readheader_done;
uint8 writeheader_done;
uint16 write_cursample;
uint32 write_curstrile;
uint8 libjpeg_session_active;
uint8 libjpeg_jpeg_query_style;
jpeg_error_mgr libjpeg_jpeg_error_mgr;
jpeg_decompress_struct libjpeg_jpeg_decompress_struct;
jpeg_source_mgr libjpeg_jpeg_source_mgr;
uint8 subsampling_convert_log;
uint32 subsampling_convert_ylinelen;
uint32 subsampling_convert_ylines;
uint32 subsampling_convert_clinelen;
uint32 subsampling_convert_clines;
uint32 subsampling_convert_ybuflen;
uint32 subsampling_convert_cbuflen;
uint32 subsampling_convert_ycbcrbuflen;
uint8* subsampling_convert_ycbcrbuf;
uint8* subsampling_convert_ybuf;
uint8* subsampling_convert_cbbuf;
uint8* subsampling_convert_crbuf;
uint32 subsampling_convert_ycbcrimagelen;
uint8** subsampling_convert_ycbcrimage;
uint32 subsampling_convert_clinelenout;
uint32 subsampling_convert_state;
uint32 bytes_per_line; /* if the codec outputs subsampled data, a 'line' in bytes_per_line */
uint32 lines_per_strile; /* and lines_per_strile means subsampling_ver desubsampled rows */
OJPEGStateInBufferSource in_buffer_source;
uint32 in_buffer_next_strile;
uint32 in_buffer_strile_count;
uint64 in_buffer_file_pos;
uint8 in_buffer_file_pos_log;
uint64 in_buffer_file_togo;
uint16 in_buffer_togo;
uint8* in_buffer_cur;
uint8 in_buffer[OJPEG_BUFFER];
OJPEGStateOutState out_state;
uint8 out_buffer[OJPEG_BUFFER];
uint8* skip_buffer;
} OJPEGState;
static int OJPEGVGetField(TIFF* tif, uint32 tag, va_list ap);
static int OJPEGVSetField(TIFF* tif, uint32 tag, va_list ap);
static void OJPEGPrintDir(TIFF* tif, FILE* fd, long flags);
static int OJPEGFixupTags(TIFF* tif);
static int OJPEGSetupDecode(TIFF* tif);
static int OJPEGPreDecode(TIFF* tif, uint16 s);
static int OJPEGPreDecodeSkipRaw(TIFF* tif);
static int OJPEGPreDecodeSkipScanlines(TIFF* tif);
static int OJPEGDecode(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s);
static int OJPEGDecodeRaw(TIFF* tif, uint8* buf, tmsize_t cc);
static int OJPEGDecodeScanlines(TIFF* tif, uint8* buf, tmsize_t cc);
static void OJPEGPostDecode(TIFF* tif, uint8* buf, tmsize_t cc);
static int OJPEGSetupEncode(TIFF* tif);
static int OJPEGPreEncode(TIFF* tif, uint16 s);
static int OJPEGEncode(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s);
static int OJPEGPostEncode(TIFF* tif);
static void OJPEGCleanup(TIFF* tif);
static void OJPEGSubsamplingCorrect(TIFF* tif);
static int OJPEGReadHeaderInfo(TIFF* tif);
static int OJPEGReadSecondarySos(TIFF* tif, uint16 s);
static int OJPEGWriteHeaderInfo(TIFF* tif);
static void OJPEGLibjpegSessionAbort(TIFF* tif);
static int OJPEGReadHeaderInfoSec(TIFF* tif);
static int OJPEGReadHeaderInfoSecStreamDri(TIFF* tif);
static int OJPEGReadHeaderInfoSecStreamDqt(TIFF* tif);
static int OJPEGReadHeaderInfoSecStreamDht(TIFF* tif);
static int OJPEGReadHeaderInfoSecStreamSof(TIFF* tif, uint8 marker_id);
static int OJPEGReadHeaderInfoSecStreamSos(TIFF* tif);
static int OJPEGReadHeaderInfoSecTablesQTable(TIFF* tif);
static int OJPEGReadHeaderInfoSecTablesDcTable(TIFF* tif);
static int OJPEGReadHeaderInfoSecTablesAcTable(TIFF* tif);
static int OJPEGReadBufferFill(OJPEGState* sp);
static int OJPEGReadByte(OJPEGState* sp, uint8* byte);
static int OJPEGReadBytePeek(OJPEGState* sp, uint8* byte);
static void OJPEGReadByteAdvance(OJPEGState* sp);
static int OJPEGReadWord(OJPEGState* sp, uint16* word);
static int OJPEGReadBlock(OJPEGState* sp, uint16 len, void* mem);
static void OJPEGReadSkip(OJPEGState* sp, uint16 len);
static int OJPEGWriteStream(TIFF* tif, void** mem, uint32* len);
static void OJPEGWriteStreamSoi(TIFF* tif, void** mem, uint32* len);
static void OJPEGWriteStreamQTable(TIFF* tif, uint8 table_index, void** mem, uint32* len);
static void OJPEGWriteStreamDcTable(TIFF* tif, uint8 table_index, void** mem, uint32* len);
static void OJPEGWriteStreamAcTable(TIFF* tif, uint8 table_index, void** mem, uint32* len);
static void OJPEGWriteStreamDri(TIFF* tif, void** mem, uint32* len);
static void OJPEGWriteStreamSof(TIFF* tif, void** mem, uint32* len);
static void OJPEGWriteStreamSos(TIFF* tif, void** mem, uint32* len);
static int OJPEGWriteStreamCompressed(TIFF* tif, void** mem, uint32* len);
static void OJPEGWriteStreamRst(TIFF* tif, void** mem, uint32* len);
static void OJPEGWriteStreamEoi(TIFF* tif, void** mem, uint32* len);
#ifdef LIBJPEG_ENCAP_EXTERNAL
extern int jpeg_create_decompress_encap(OJPEGState* sp, jpeg_decompress_struct* cinfo);
extern int jpeg_read_header_encap(OJPEGState* sp, jpeg_decompress_struct* cinfo, uint8 require_image);
extern int jpeg_start_decompress_encap(OJPEGState* sp, jpeg_decompress_struct* cinfo);
extern int jpeg_read_scanlines_encap(OJPEGState* sp, jpeg_decompress_struct* cinfo, void* scanlines, uint32 max_lines);
extern int jpeg_read_raw_data_encap(OJPEGState* sp, jpeg_decompress_struct* cinfo, void* data, uint32 max_lines);
extern void jpeg_encap_unwind(TIFF* tif);
#else
static int jpeg_create_decompress_encap(OJPEGState* sp, jpeg_decompress_struct* j);
static int jpeg_read_header_encap(OJPEGState* sp, jpeg_decompress_struct* cinfo, uint8 require_image);
static int jpeg_start_decompress_encap(OJPEGState* sp, jpeg_decompress_struct* cinfo);
static int jpeg_read_scanlines_encap(OJPEGState* sp, jpeg_decompress_struct* cinfo, void* scanlines, uint32 max_lines);
static int jpeg_read_raw_data_encap(OJPEGState* sp, jpeg_decompress_struct* cinfo, void* data, uint32 max_lines);
static void jpeg_encap_unwind(TIFF* tif);
#endif
static void OJPEGLibjpegJpegErrorMgrOutputMessage(jpeg_common_struct* cinfo);
static void OJPEGLibjpegJpegErrorMgrErrorExit(jpeg_common_struct* cinfo);
static void OJPEGLibjpegJpegSourceMgrInitSource(jpeg_decompress_struct* cinfo);
static boolean OJPEGLibjpegJpegSourceMgrFillInputBuffer(jpeg_decompress_struct* cinfo);
static void OJPEGLibjpegJpegSourceMgrSkipInputData(jpeg_decompress_struct* cinfo, long num_bytes);
static boolean OJPEGLibjpegJpegSourceMgrResyncToRestart(jpeg_decompress_struct* cinfo, int desired);
static void OJPEGLibjpegJpegSourceMgrTermSource(jpeg_decompress_struct* cinfo);
int
TIFFInitOJPEG(TIFF* tif, int scheme)
{
static const char module[]="TIFFInitOJPEG";
OJPEGState* sp;
assert(scheme==COMPRESSION_OJPEG);
/*
* Merge codec-specific tag information.
*/
if (!_TIFFMergeFields(tif, ojpegFields, TIFFArrayCount(ojpegFields))) {
TIFFErrorExt(tif->tif_clientdata, module,
"Merging Old JPEG codec-specific tags failed");
return 0;
}
/* state block */
sp=_TIFFmalloc(sizeof(OJPEGState));
if (sp==NULL)
{
TIFFErrorExt(tif->tif_clientdata,module,"No space for OJPEG state block");
return(0);
}
_TIFFmemset(sp,0,sizeof(OJPEGState));
sp->tif=tif;
sp->jpeg_proc=1;
sp->subsampling_hor=2;
sp->subsampling_ver=2;
TIFFSetField(tif,TIFFTAG_YCBCRSUBSAMPLING,2,2);
/* tif codec methods */
tif->tif_fixuptags=OJPEGFixupTags;
tif->tif_setupdecode=OJPEGSetupDecode;
tif->tif_predecode=OJPEGPreDecode;
tif->tif_postdecode=OJPEGPostDecode;
tif->tif_decoderow=OJPEGDecode;
tif->tif_decodestrip=OJPEGDecode;
tif->tif_decodetile=OJPEGDecode;
tif->tif_setupencode=OJPEGSetupEncode;
tif->tif_preencode=OJPEGPreEncode;
tif->tif_postencode=OJPEGPostEncode;
tif->tif_encoderow=OJPEGEncode;
tif->tif_encodestrip=OJPEGEncode;
tif->tif_encodetile=OJPEGEncode;
tif->tif_cleanup=OJPEGCleanup;
tif->tif_data=(uint8*)sp;
/* tif tag methods */
sp->vgetparent=tif->tif_tagmethods.vgetfield;
tif->tif_tagmethods.vgetfield=OJPEGVGetField;
sp->vsetparent=tif->tif_tagmethods.vsetfield;
tif->tif_tagmethods.vsetfield=OJPEGVSetField;
sp->printdir=tif->tif_tagmethods.printdir;
tif->tif_tagmethods.printdir=OJPEGPrintDir;
/* Some OJPEG files don't have strip or tile offsets or bytecounts tags.
Some others do, but have totally meaningless or corrupt values
in these tags. In these cases, the JpegInterchangeFormat stream is
reliable. In any case, this decoder reads the compressed data itself,
from the most reliable locations, and we need to notify encapsulating
LibTiff not to read raw strips or tiles for us. */
tif->tif_flags|=TIFF_NOREADRAW;
return(1);
}
static int
OJPEGVGetField(TIFF* tif, uint32 tag, va_list ap)
{
OJPEGState* sp=(OJPEGState*)tif->tif_data;
switch(tag)
{
case TIFFTAG_JPEGIFOFFSET:
*va_arg(ap,uint64*)=(uint64)sp->jpeg_interchange_format;
break;
case TIFFTAG_JPEGIFBYTECOUNT:
*va_arg(ap,uint64*)=(uint64)sp->jpeg_interchange_format_length;
break;
case TIFFTAG_YCBCRSUBSAMPLING:
if (sp->subsamplingcorrect_done==0)
OJPEGSubsamplingCorrect(tif);
*va_arg(ap,uint16*)=(uint16)sp->subsampling_hor;
*va_arg(ap,uint16*)=(uint16)sp->subsampling_ver;
break;
case TIFFTAG_JPEGQTABLES:
*va_arg(ap,uint32*)=(uint32)sp->qtable_offset_count;
*va_arg(ap,void**)=(void*)sp->qtable_offset;
break;
case TIFFTAG_JPEGDCTABLES:
*va_arg(ap,uint32*)=(uint32)sp->dctable_offset_count;
*va_arg(ap,void**)=(void*)sp->dctable_offset;
break;
case TIFFTAG_JPEGACTABLES:
*va_arg(ap,uint32*)=(uint32)sp->actable_offset_count;
*va_arg(ap,void**)=(void*)sp->actable_offset;
break;
case TIFFTAG_JPEGPROC:
*va_arg(ap,uint16*)=(uint16)sp->jpeg_proc;
break;
case TIFFTAG_JPEGRESTARTINTERVAL:
*va_arg(ap,uint16*)=sp->restart_interval;
break;
default:
return (*sp->vgetparent)(tif,tag,ap);
}
return (1);
}
static int
OJPEGVSetField(TIFF* tif, uint32 tag, va_list ap)
{
static const char module[]="OJPEGVSetField";
OJPEGState* sp=(OJPEGState*)tif->tif_data;
uint32 ma;
uint64* mb;
uint32 n;
const TIFFField* fip;
switch(tag)
{
case TIFFTAG_JPEGIFOFFSET:
sp->jpeg_interchange_format=(uint64)va_arg(ap,uint64);
break;
case TIFFTAG_JPEGIFBYTECOUNT:
sp->jpeg_interchange_format_length=(uint64)va_arg(ap,uint64);
break;
case TIFFTAG_YCBCRSUBSAMPLING:
sp->subsampling_tag=1;
sp->subsampling_hor=(uint8)va_arg(ap,uint16_vap);
sp->subsampling_ver=(uint8)va_arg(ap,uint16_vap);
tif->tif_dir.td_ycbcrsubsampling[0]=sp->subsampling_hor;
tif->tif_dir.td_ycbcrsubsampling[1]=sp->subsampling_ver;
break;
case TIFFTAG_JPEGQTABLES:
ma=(uint32)va_arg(ap,uint32);
if (ma!=0)
{
if (ma>3)
{
TIFFErrorExt(tif->tif_clientdata,module,"JpegQTables tag has incorrect count");
return(0);
}
sp->qtable_offset_count=(uint8)ma;
mb=(uint64*)va_arg(ap,uint64*);
for (n=0; n<ma; n++)
sp->qtable_offset[n]=mb[n];
}
break;
case TIFFTAG_JPEGDCTABLES:
ma=(uint32)va_arg(ap,uint32);
if (ma!=0)
{
if (ma>3)
{
TIFFErrorExt(tif->tif_clientdata,module,"JpegDcTables tag has incorrect count");
return(0);
}
sp->dctable_offset_count=(uint8)ma;
mb=(uint64*)va_arg(ap,uint64*);
for (n=0; n<ma; n++)
sp->dctable_offset[n]=mb[n];
}
break;
case TIFFTAG_JPEGACTABLES:
ma=(uint32)va_arg(ap,uint32);
if (ma!=0)
{
if (ma>3)
{
TIFFErrorExt(tif->tif_clientdata,module,"JpegAcTables tag has incorrect count");
return(0);
}
sp->actable_offset_count=(uint8)ma;
mb=(uint64*)va_arg(ap,uint64*);
for (n=0; n<ma; n++)
sp->actable_offset[n]=mb[n];
}
break;
case TIFFTAG_JPEGPROC:
sp->jpeg_proc=(uint8)va_arg(ap,uint16_vap);
break;
case TIFFTAG_JPEGRESTARTINTERVAL:
sp->restart_interval=(uint16)va_arg(ap,uint16_vap);
break;
default:
return (*sp->vsetparent)(tif,tag,ap);
}
fip = TIFFFieldWithTag(tif,tag);
if( fip == NULL ) /* shouldn't happen */
return(0);
TIFFSetFieldBit(tif,fip->field_bit);
tif->tif_flags|=TIFF_DIRTYDIRECT;
return(1);
}
static void
OJPEGPrintDir(TIFF* tif, FILE* fd, long flags)
{
OJPEGState* sp=(OJPEGState*)tif->tif_data;
uint8 m;
(void)flags;
assert(sp!=NULL);
if (TIFFFieldSet(tif,FIELD_OJPEG_JPEGINTERCHANGEFORMAT))
fprintf(fd," JpegInterchangeFormat: " TIFF_UINT64_FORMAT "\n",(TIFF_UINT64_T)sp->jpeg_interchange_format);
if (TIFFFieldSet(tif,FIELD_OJPEG_JPEGINTERCHANGEFORMATLENGTH))
fprintf(fd," JpegInterchangeFormatLength: " TIFF_UINT64_FORMAT "\n",(TIFF_UINT64_T)sp->jpeg_interchange_format_length);
if (TIFFFieldSet(tif,FIELD_OJPEG_JPEGQTABLES))
{
fprintf(fd," JpegQTables:");
for (m=0; m<sp->qtable_offset_count; m++)
fprintf(fd," " TIFF_UINT64_FORMAT,(TIFF_UINT64_T)sp->qtable_offset[m]);
fprintf(fd,"\n");
}
if (TIFFFieldSet(tif,FIELD_OJPEG_JPEGDCTABLES))
{
fprintf(fd," JpegDcTables:");
for (m=0; m<sp->dctable_offset_count; m++)
fprintf(fd," " TIFF_UINT64_FORMAT,(TIFF_UINT64_T)sp->dctable_offset[m]);
fprintf(fd,"\n");
}
if (TIFFFieldSet(tif,FIELD_OJPEG_JPEGACTABLES))
{
fprintf(fd," JpegAcTables:");
for (m=0; m<sp->actable_offset_count; m++)
fprintf(fd," " TIFF_UINT64_FORMAT,(TIFF_UINT64_T)sp->actable_offset[m]);
fprintf(fd,"\n");
}
if (TIFFFieldSet(tif,FIELD_OJPEG_JPEGPROC))
fprintf(fd," JpegProc: %u\n",(unsigned int)sp->jpeg_proc);
if (TIFFFieldSet(tif,FIELD_OJPEG_JPEGRESTARTINTERVAL))
fprintf(fd," JpegRestartInterval: %u\n",(unsigned int)sp->restart_interval);
if (sp->printdir)
(*sp->printdir)(tif, fd, flags);
}
static int
OJPEGFixupTags(TIFF* tif)
{
(void) tif;
return(1);
}
static int
OJPEGSetupDecode(TIFF* tif)
{
static const char module[]="OJPEGSetupDecode";
TIFFWarningExt(tif->tif_clientdata,module,"Depreciated and troublesome old-style JPEG compression mode, please convert to new-style JPEG compression and notify vendor of writing software");
return(1);
}
static int
OJPEGPreDecode(TIFF* tif, uint16 s)
{
OJPEGState* sp=(OJPEGState*)tif->tif_data;
uint32 m;
if (sp->subsamplingcorrect_done==0)
OJPEGSubsamplingCorrect(tif);
if (sp->readheader_done==0)
{
if (OJPEGReadHeaderInfo(tif)==0)
return(0);
}
if (sp->sos_end[s].log==0)
{
if (OJPEGReadSecondarySos(tif,s)==0)
return(0);
}
if isTiled(tif)
m=tif->tif_curtile;
else
m=tif->tif_curstrip;
if ((sp->writeheader_done!=0) && ((sp->write_cursample!=s) || (sp->write_curstrile>m)))
{
if (sp->libjpeg_session_active!=0)
OJPEGLibjpegSessionAbort(tif);
sp->writeheader_done=0;
}
if (sp->writeheader_done==0)
{
sp->plane_sample_offset=(uint8)s;
sp->write_cursample=s;
sp->write_curstrile=s*tif->tif_dir.td_stripsperimage;
if ((sp->in_buffer_file_pos_log==0) ||
(sp->in_buffer_file_pos-sp->in_buffer_togo!=sp->sos_end[s].in_buffer_file_pos))
{
sp->in_buffer_source=sp->sos_end[s].in_buffer_source;
sp->in_buffer_next_strile=sp->sos_end[s].in_buffer_next_strile;
sp->in_buffer_file_pos=sp->sos_end[s].in_buffer_file_pos;
sp->in_buffer_file_pos_log=0;
sp->in_buffer_file_togo=sp->sos_end[s].in_buffer_file_togo;
sp->in_buffer_togo=0;
sp->in_buffer_cur=0;
}
if (OJPEGWriteHeaderInfo(tif)==0)
return(0);
}
while (sp->write_curstrile<m)
{
if (sp->libjpeg_jpeg_query_style==0)
{
if (OJPEGPreDecodeSkipRaw(tif)==0)
return(0);
}
else
{
if (OJPEGPreDecodeSkipScanlines(tif)==0)
return(0);
}
sp->write_curstrile++;
}
sp->decoder_ok = 1;
return(1);
}
static int
OJPEGPreDecodeSkipRaw(TIFF* tif)
{
OJPEGState* sp=(OJPEGState*)tif->tif_data;
uint32 m;
m=sp->lines_per_strile;
if (sp->subsampling_convert_state!=0)
{
if (sp->subsampling_convert_clines-sp->subsampling_convert_state>=m)
{
sp->subsampling_convert_state+=m;
if (sp->subsampling_convert_state==sp->subsampling_convert_clines)
sp->subsampling_convert_state=0;
return(1);
}
m-=sp->subsampling_convert_clines-sp->subsampling_convert_state;
sp->subsampling_convert_state=0;
}
while (m>=sp->subsampling_convert_clines)
{
if (jpeg_read_raw_data_encap(sp,&(sp->libjpeg_jpeg_decompress_struct),sp->subsampling_convert_ycbcrimage,sp->subsampling_ver*8)==0)
return(0);
m-=sp->subsampling_convert_clines;
}
if (m>0)
{
if (jpeg_read_raw_data_encap(sp,&(sp->libjpeg_jpeg_decompress_struct),sp->subsampling_convert_ycbcrimage,sp->subsampling_ver*8)==0)
return(0);
sp->subsampling_convert_state=m;
}
return(1);
}
static int
OJPEGPreDecodeSkipScanlines(TIFF* tif)
{
static const char module[]="OJPEGPreDecodeSkipScanlines";
OJPEGState* sp=(OJPEGState*)tif->tif_data;
uint32 m;
if (sp->skip_buffer==NULL)
{
sp->skip_buffer=_TIFFmalloc(sp->bytes_per_line);
if (sp->skip_buffer==NULL)
{
TIFFErrorExt(tif->tif_clientdata,module,"Out of memory");
return(0);
}
}
for (m=0; m<sp->lines_per_strile; m++)
{
if (jpeg_read_scanlines_encap(sp,&(sp->libjpeg_jpeg_decompress_struct),&sp->skip_buffer,1)==0)
return(0);
}
return(1);
}
static int
OJPEGDecode(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s)
{
static const char module[]="OJPEGDecode";
OJPEGState* sp=(OJPEGState*)tif->tif_data;
(void)s;
if( !sp->decoder_ok )
{
TIFFErrorExt(tif->tif_clientdata,module,"Cannot decode: decoder not correctly initialized");
return 0;
}
if (sp->libjpeg_jpeg_query_style==0)
{
if (OJPEGDecodeRaw(tif,buf,cc)==0)
return(0);
}
else
{
if (OJPEGDecodeScanlines(tif,buf,cc)==0)
return(0);
}
return(1);
}
static int
OJPEGDecodeRaw(TIFF* tif, uint8* buf, tmsize_t cc)
{
static const char module[]="OJPEGDecodeRaw";
OJPEGState* sp=(OJPEGState*)tif->tif_data;
uint8* m;
tmsize_t n;
uint8* oy;
uint8* ocb;
uint8* ocr;
uint8* p;
uint32 q;
uint8* r;
uint8 sx,sy;
if (cc%sp->bytes_per_line!=0)
{
TIFFErrorExt(tif->tif_clientdata,module,"Fractional scanline not read");
return(0);
}
assert(cc>0);
m=buf;
n=cc;
do
{
if (sp->subsampling_convert_state==0)
{
if (jpeg_read_raw_data_encap(sp,&(sp->libjpeg_jpeg_decompress_struct),sp->subsampling_convert_ycbcrimage,sp->subsampling_ver*8)==0)
return(0);
}
oy=sp->subsampling_convert_ybuf+sp->subsampling_convert_state*sp->subsampling_ver*sp->subsampling_convert_ylinelen;
ocb=sp->subsampling_convert_cbbuf+sp->subsampling_convert_state*sp->subsampling_convert_clinelen;
ocr=sp->subsampling_convert_crbuf+sp->subsampling_convert_state*sp->subsampling_convert_clinelen;
p=m;
for (q=0; q<sp->subsampling_convert_clinelenout; q++)
{
r=oy;
for (sy=0; sy<sp->subsampling_ver; sy++)
{
for (sx=0; sx<sp->subsampling_hor; sx++)
*p++=*r++;
r+=sp->subsampling_convert_ylinelen-sp->subsampling_hor;
}
oy+=sp->subsampling_hor;
*p++=*ocb++;
*p++=*ocr++;
}
sp->subsampling_convert_state++;
if (sp->subsampling_convert_state==sp->subsampling_convert_clines)
sp->subsampling_convert_state=0;
m+=sp->bytes_per_line;
n-=sp->bytes_per_line;
} while(n>0);
return(1);
}
static int
OJPEGDecodeScanlines(TIFF* tif, uint8* buf, tmsize_t cc)
{
static const char module[]="OJPEGDecodeScanlines";
OJPEGState* sp=(OJPEGState*)tif->tif_data;
uint8* m;
tmsize_t n;
if (cc%sp->bytes_per_line!=0)
{
TIFFErrorExt(tif->tif_clientdata,module,"Fractional scanline not read");
return(0);
}
assert(cc>0);
m=buf;
n=cc;
do
{
if (jpeg_read_scanlines_encap(sp,&(sp->libjpeg_jpeg_decompress_struct),&m,1)==0)
return(0);
m+=sp->bytes_per_line;
n-=sp->bytes_per_line;
} while(n>0);
return(1);
}
static void
OJPEGPostDecode(TIFF* tif, uint8* buf, tmsize_t cc)
{
OJPEGState* sp=(OJPEGState*)tif->tif_data;
(void)buf;
(void)cc;
sp->write_curstrile++;
if (sp->write_curstrile%tif->tif_dir.td_stripsperimage==0)
{
assert(sp->libjpeg_session_active!=0);
OJPEGLibjpegSessionAbort(tif);
sp->writeheader_done=0;
}
}
static int
OJPEGSetupEncode(TIFF* tif)
{
static const char module[]="OJPEGSetupEncode";
TIFFErrorExt(tif->tif_clientdata,module,"OJPEG encoding not supported; use new-style JPEG compression instead");
return(0);
}
static int
OJPEGPreEncode(TIFF* tif, uint16 s)
{
static const char module[]="OJPEGPreEncode";
(void)s;
TIFFErrorExt(tif->tif_clientdata,module,"OJPEG encoding not supported; use new-style JPEG compression instead");
return(0);
}
static int
OJPEGEncode(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s)
{
static const char module[]="OJPEGEncode";
(void)buf;
(void)cc;
(void)s;
TIFFErrorExt(tif->tif_clientdata,module,"OJPEG encoding not supported; use new-style JPEG compression instead");
return(0);
}
static int
OJPEGPostEncode(TIFF* tif)
{
static const char module[]="OJPEGPostEncode";
TIFFErrorExt(tif->tif_clientdata,module,"OJPEG encoding not supported; use new-style JPEG compression instead");
return(0);
}
static void
OJPEGCleanup(TIFF* tif)
{
OJPEGState* sp=(OJPEGState*)tif->tif_data;
if (sp!=0)
{
tif->tif_tagmethods.vgetfield=sp->vgetparent;
tif->tif_tagmethods.vsetfield=sp->vsetparent;
tif->tif_tagmethods.printdir=sp->printdir;
if (sp->qtable[0]!=0)
_TIFFfree(sp->qtable[0]);
if (sp->qtable[1]!=0)
_TIFFfree(sp->qtable[1]);
if (sp->qtable[2]!=0)
_TIFFfree(sp->qtable[2]);
if (sp->qtable[3]!=0)
_TIFFfree(sp->qtable[3]);
if (sp->dctable[0]!=0)
_TIFFfree(sp->dctable[0]);
if (sp->dctable[1]!=0)
_TIFFfree(sp->dctable[1]);
if (sp->dctable[2]!=0)
_TIFFfree(sp->dctable[2]);
if (sp->dctable[3]!=0)
_TIFFfree(sp->dctable[3]);
if (sp->actable[0]!=0)
_TIFFfree(sp->actable[0]);
if (sp->actable[1]!=0)
_TIFFfree(sp->actable[1]);
if (sp->actable[2]!=0)
_TIFFfree(sp->actable[2]);
if (sp->actable[3]!=0)
_TIFFfree(sp->actable[3]);
if (sp->libjpeg_session_active!=0)
OJPEGLibjpegSessionAbort(tif);
if (sp->subsampling_convert_ycbcrbuf!=0)
_TIFFfree(sp->subsampling_convert_ycbcrbuf);
if (sp->subsampling_convert_ycbcrimage!=0)
_TIFFfree(sp->subsampling_convert_ycbcrimage);
if (sp->skip_buffer!=0)
_TIFFfree(sp->skip_buffer);
_TIFFfree(sp);
tif->tif_data=NULL;
_TIFFSetDefaultCompressionState(tif);
}
}
static void
OJPEGSubsamplingCorrect(TIFF* tif)
{
static const char module[]="OJPEGSubsamplingCorrect";
OJPEGState* sp=(OJPEGState*)tif->tif_data;
uint8 mh;
uint8 mv;
_TIFFFillStriles( tif );
assert(sp->subsamplingcorrect_done==0);
if ((tif->tif_dir.td_samplesperpixel!=3) || ((tif->tif_dir.td_photometric!=PHOTOMETRIC_YCBCR) &&
(tif->tif_dir.td_photometric!=PHOTOMETRIC_ITULAB)))
{