]>
git.saurik.com Git - wxWidgets.git/blob - src/tiff/libtiff/tif_next.c
3 * Copyright (c) 1988-1997 Sam Leffler
4 * Copyright (c) 1991-1997 Silicon Graphics, Inc.
6 * Permission to use, copy, modify, distribute, and sell this software and
7 * its documentation for any purpose is hereby granted without fee, provided
8 * that (i) the above copyright notices and this permission notice appear in
9 * all copies of the software and related documentation, and (ii) the names of
10 * Sam Leffler and Silicon Graphics may not be used in any advertising or
11 * publicity relating to the software without the specific, prior written
12 * permission of Sam Leffler and Silicon Graphics.
14 * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
15 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
16 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
18 * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
19 * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
20 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
21 * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
22 * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
31 * NeXT 2-bit Grey Scale Compression Algorithm Support
34 #define SETPIXEL(op, v) { \
35 switch (npixels++ & 3) { \
36 case 0: op[0] = (unsigned char) ((v) << 6); break; \
37 case 1: op[0] |= (v) << 4; break; \
38 case 2: op[0] |= (v) << 2; break; \
39 case 3: *op++ |= (v); break; \
43 #define LITERALROW 0x00
44 #define LITERALSPAN 0x40
45 #define WHITE ((1<<2)-1)
48 NeXTDecode(TIFF
* tif
, uint8
* buf
, tmsize_t occ
, uint16 s
)
50 static const char module[] = "NeXTDecode";
51 unsigned char *bp
, *op
;
58 * Each scanline is assumed to start off as all
59 * white (we assume a PhotometricInterpretation
60 * of ``min-is-black'').
62 for (op
= (unsigned char*) buf
, cc
= occ
; cc
-- > 0;)
65 bp
= (unsigned char *)tif
->tif_rawcp
;
67 scanline
= tif
->tif_scanlinesize
;
70 TIFFErrorExt(tif
->tif_clientdata
, module, "Fractional scanlines cannot be read");
73 for (row
= buf
; occ
> 0; occ
-= scanline
, row
+= scanline
) {
78 * The entire scanline is given as literal values.
82 _TIFFmemcpy(row
, bp
, scanline
);
89 * The scanline has a literal span that begins at some
92 off
= (bp
[0] * 256) + bp
[1];
93 n
= (bp
[2] * 256) + bp
[3];
94 if (cc
< 4+n
|| off
+n
> scanline
)
96 _TIFFmemcpy(row
+off
, bp
+4, n
);
102 uint32 npixels
= 0, grey
;
103 uint32 imagewidth
= tif
->tif_dir
.td_imagewidth
;
106 * The scanline is composed of a sequence of constant
107 * color ``runs''. We shift into ``run mode'' and
108 * interpret bytes as codes of the form
109 * <color><npixels> until we've filled the scanline.
113 grey
= (uint32
)((n
>>6) & 0x3);
116 * Ensure the run does not exceed the scanline
117 * bounds, potentially resulting in a security
120 while (n
-- > 0 && npixels
< imagewidth
)
122 if (npixels
>= imagewidth
)
132 tif
->tif_rawcp
= (uint8
*) bp
;
136 TIFFErrorExt(tif
->tif_clientdata
, module, "Not enough data for scanline %ld",
137 (long) tif
->tif_row
);
142 TIFFInitNeXT(TIFF
* tif
, int scheme
)
145 tif
->tif_decoderow
= NeXTDecode
;
146 tif
->tif_decodestrip
= NeXTDecode
;
147 tif
->tif_decodetile
= NeXTDecode
;
150 #endif /* NEXT_SUPPORT */
152 /* vim: set ts=8 sts=8 sw=8 noet: */