xref: /reactos/dll/3rdparty/libtiff/tif_dumpmode.c (revision 743951ec)
1*c2c66affSColin Finck /*
2*c2c66affSColin Finck  * Copyright (c) 1988-1997 Sam Leffler
3*c2c66affSColin Finck  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
4*c2c66affSColin Finck  *
5*c2c66affSColin Finck  * Permission to use, copy, modify, distribute, and sell this software and
6*c2c66affSColin Finck  * its documentation for any purpose is hereby granted without fee, provided
7*c2c66affSColin Finck  * that (i) the above copyright notices and this permission notice appear in
8*c2c66affSColin Finck  * all copies of the software and related documentation, and (ii) the names of
9*c2c66affSColin Finck  * Sam Leffler and Silicon Graphics may not be used in any advertising or
10*c2c66affSColin Finck  * publicity relating to the software without the specific, prior written
11*c2c66affSColin Finck  * permission of Sam Leffler and Silicon Graphics.
12*c2c66affSColin Finck  *
13*c2c66affSColin Finck  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
14*c2c66affSColin Finck  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
15*c2c66affSColin Finck  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
16*c2c66affSColin Finck  *
17*c2c66affSColin Finck  * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
18*c2c66affSColin Finck  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
19*c2c66affSColin Finck  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
20*c2c66affSColin Finck  * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
21*c2c66affSColin Finck  * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
22*c2c66affSColin Finck  * OF THIS SOFTWARE.
23*c2c66affSColin Finck  */
24*c2c66affSColin Finck 
25*c2c66affSColin Finck /*
26*c2c66affSColin Finck  * TIFF Library.
27*c2c66affSColin Finck  *
28*c2c66affSColin Finck  * "Null" Compression Algorithm Support.
29*c2c66affSColin Finck  */
30*c2c66affSColin Finck 
31*c2c66affSColin Finck #include <precomp.h>
32*c2c66affSColin Finck 
33*c2c66affSColin Finck static int
DumpFixupTags(TIFF * tif)34*c2c66affSColin Finck DumpFixupTags(TIFF* tif)
35*c2c66affSColin Finck {
36*c2c66affSColin Finck 	(void) tif;
37*c2c66affSColin Finck 	return (1);
38*c2c66affSColin Finck }
39*c2c66affSColin Finck 
40*c2c66affSColin Finck /*
41*c2c66affSColin Finck  * Encode a hunk of pixels.
42*c2c66affSColin Finck  */
43*c2c66affSColin Finck static int
DumpModeEncode(TIFF * tif,uint8 * pp,tmsize_t cc,uint16 s)44*c2c66affSColin Finck DumpModeEncode(TIFF* tif, uint8* pp, tmsize_t cc, uint16 s)
45*c2c66affSColin Finck {
46*c2c66affSColin Finck 	(void) s;
47*c2c66affSColin Finck 	while (cc > 0) {
48*c2c66affSColin Finck 		tmsize_t n;
49*c2c66affSColin Finck 
50*c2c66affSColin Finck 		n = cc;
51*c2c66affSColin Finck 		if (tif->tif_rawcc + n > tif->tif_rawdatasize)
52*c2c66affSColin Finck 			n = tif->tif_rawdatasize - tif->tif_rawcc;
53*c2c66affSColin Finck 
54*c2c66affSColin Finck 		assert( n > 0 );
55*c2c66affSColin Finck 
56*c2c66affSColin Finck 		/*
57*c2c66affSColin Finck 		 * Avoid copy if client has setup raw
58*c2c66affSColin Finck 		 * data buffer to avoid extra copy.
59*c2c66affSColin Finck 		 */
60*c2c66affSColin Finck 		if (tif->tif_rawcp != pp)
61*c2c66affSColin Finck 			_TIFFmemcpy(tif->tif_rawcp, pp, n);
62*c2c66affSColin Finck 		tif->tif_rawcp += n;
63*c2c66affSColin Finck 		tif->tif_rawcc += n;
64*c2c66affSColin Finck 		pp += n;
65*c2c66affSColin Finck 		cc -= n;
66*c2c66affSColin Finck 		if (tif->tif_rawcc >= tif->tif_rawdatasize &&
67*c2c66affSColin Finck 		    !TIFFFlushData1(tif))
68*c2c66affSColin Finck 			return (0);
69*c2c66affSColin Finck 	}
70*c2c66affSColin Finck 	return (1);
71*c2c66affSColin Finck }
72*c2c66affSColin Finck 
73*c2c66affSColin Finck /*
74*c2c66affSColin Finck  * Decode a hunk of pixels.
75*c2c66affSColin Finck  */
76*c2c66affSColin Finck static int
DumpModeDecode(TIFF * tif,uint8 * buf,tmsize_t cc,uint16 s)77*c2c66affSColin Finck DumpModeDecode(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s)
78*c2c66affSColin Finck {
79*c2c66affSColin Finck 	static const char module[] = "DumpModeDecode";
80*c2c66affSColin Finck 	(void) s;
81*c2c66affSColin Finck 	if (tif->tif_rawcc < cc) {
82*c2c66affSColin Finck #if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))
83*c2c66affSColin Finck 		TIFFErrorExt(tif->tif_clientdata, module,
84*c2c66affSColin Finck "Not enough data for scanline %lu, expected a request for at most %I64d bytes, got a request for %I64d bytes",
85*c2c66affSColin Finck 		             (unsigned long) tif->tif_row,
86*c2c66affSColin Finck 		             (signed __int64) tif->tif_rawcc,
87*c2c66affSColin Finck 		             (signed __int64) cc);
88*c2c66affSColin Finck #else
89*c2c66affSColin Finck 		TIFFErrorExt(tif->tif_clientdata, module,
90*c2c66affSColin Finck "Not enough data for scanline %lu, expected a request for at most %lld bytes, got a request for %lld bytes",
91*c2c66affSColin Finck 		             (unsigned long) tif->tif_row,
92*c2c66affSColin Finck 		             (signed long long) tif->tif_rawcc,
93*c2c66affSColin Finck 		             (signed long long) cc);
94*c2c66affSColin Finck #endif
95*c2c66affSColin Finck 		return (0);
96*c2c66affSColin Finck 	}
97*c2c66affSColin Finck 	/*
98*c2c66affSColin Finck 	 * Avoid copy if client has setup raw
99*c2c66affSColin Finck 	 * data buffer to avoid extra copy.
100*c2c66affSColin Finck 	 */
101*c2c66affSColin Finck 	if (tif->tif_rawcp != buf)
102*c2c66affSColin Finck 		_TIFFmemcpy(buf, tif->tif_rawcp, cc);
103*c2c66affSColin Finck 	tif->tif_rawcp += cc;
104*c2c66affSColin Finck 	tif->tif_rawcc -= cc;
105*c2c66affSColin Finck 	return (1);
106*c2c66affSColin Finck }
107*c2c66affSColin Finck 
108*c2c66affSColin Finck /*
109*c2c66affSColin Finck  * Seek forwards nrows in the current strip.
110*c2c66affSColin Finck  */
111*c2c66affSColin Finck static int
DumpModeSeek(TIFF * tif,uint32 nrows)112*c2c66affSColin Finck DumpModeSeek(TIFF* tif, uint32 nrows)
113*c2c66affSColin Finck {
114*c2c66affSColin Finck 	tif->tif_rawcp += nrows * tif->tif_scanlinesize;
115*c2c66affSColin Finck 	tif->tif_rawcc -= nrows * tif->tif_scanlinesize;
116*c2c66affSColin Finck 	return (1);
117*c2c66affSColin Finck }
118*c2c66affSColin Finck 
119*c2c66affSColin Finck /*
120*c2c66affSColin Finck  * Initialize dump mode.
121*c2c66affSColin Finck  */
122*c2c66affSColin Finck int
TIFFInitDumpMode(TIFF * tif,int scheme)123*c2c66affSColin Finck TIFFInitDumpMode(TIFF* tif, int scheme)
124*c2c66affSColin Finck {
125*c2c66affSColin Finck 	(void) scheme;
126*c2c66affSColin Finck 	tif->tif_fixuptags = DumpFixupTags;
127*c2c66affSColin Finck 	tif->tif_decoderow = DumpModeDecode;
128*c2c66affSColin Finck 	tif->tif_decodestrip = DumpModeDecode;
129*c2c66affSColin Finck 	tif->tif_decodetile = DumpModeDecode;
130*c2c66affSColin Finck 	tif->tif_encoderow = DumpModeEncode;
131*c2c66affSColin Finck 	tif->tif_encodestrip = DumpModeEncode;
132*c2c66affSColin Finck 	tif->tif_encodetile = DumpModeEncode;
133*c2c66affSColin Finck 	tif->tif_seek = DumpModeSeek;
134*c2c66affSColin Finck 	return (1);
135*c2c66affSColin Finck }
136*c2c66affSColin Finck /*
137*c2c66affSColin Finck  * Local Variables:
138*c2c66affSColin Finck  * mode: c
139*c2c66affSColin Finck  * c-basic-offset: 8
140*c2c66affSColin Finck  * fill-column: 78
141*c2c66affSColin Finck  * End:
142*c2c66affSColin Finck  */
143