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