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 #include "tiffiop.h"
31 
32 static int
DumpFixupTags(TIFF * tif)33 DumpFixupTags(TIFF* tif)
34 {
35 	(void) tif;
36 	return (1);
37 }
38 
39 /*
40  * Encode a hunk of pixels.
41  */
42 static int
DumpModeEncode(TIFF * tif,uint8 * pp,tmsize_t cc,uint16 s)43 DumpModeEncode(TIFF* tif, uint8* pp, tmsize_t cc, uint16 s)
44 {
45 	(void) s;
46 	while (cc > 0) {
47 		tmsize_t n;
48 
49 		n = cc;
50 		if (tif->tif_rawcc + n > tif->tif_rawdatasize)
51 			n = tif->tif_rawdatasize - tif->tif_rawcc;
52 
53 		assert( n > 0 );
54 
55 		/*
56 		 * Avoid copy if client has setup raw
57 		 * data buffer to avoid extra copy.
58 		 */
59 		if (tif->tif_rawcp != pp)
60 			_TIFFmemcpy(tif->tif_rawcp, pp, n);
61 		tif->tif_rawcp += n;
62 		tif->tif_rawcc += n;
63 		pp += n;
64 		cc -= n;
65 		if (tif->tif_rawcc >= tif->tif_rawdatasize &&
66 		    !TIFFFlushData1(tif))
67 			return (0);
68 	}
69 	return (1);
70 }
71 
72 /*
73  * Decode a hunk of pixels.
74  */
75 static int
DumpModeDecode(TIFF * tif,uint8 * buf,tmsize_t cc,uint16 s)76 DumpModeDecode(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s)
77 {
78 	static const char module[] = "DumpModeDecode";
79 	(void) s;
80 	if (tif->tif_rawcc < cc) {
81 #if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))
82 		TIFFErrorExt(tif->tif_clientdata, module,
83 "Not enough data for scanline %lu, expected a request for at most %I64d bytes, got a request for %I64d bytes",
84 		             (unsigned long) tif->tif_row,
85 		             (signed __int64) tif->tif_rawcc,
86 		             (signed __int64) cc);
87 #else
88 		TIFFErrorExt(tif->tif_clientdata, module,
89 "Not enough data for scanline %lu, expected a request for at most %lld bytes, got a request for %lld bytes",
90 		             (unsigned long) tif->tif_row,
91 		             (signed long long) tif->tif_rawcc,
92 		             (signed long long) cc);
93 #endif
94 		return (0);
95 	}
96 	/*
97 	 * Avoid copy if client has setup raw
98 	 * data buffer to avoid extra copy.
99 	 */
100 	if (tif->tif_rawcp != buf)
101 		_TIFFmemcpy(buf, tif->tif_rawcp, cc);
102 	tif->tif_rawcp += cc;
103 	tif->tif_rawcc -= cc;
104 	return (1);
105 }
106 
107 /*
108  * Seek forwards nrows in the current strip.
109  */
110 static int
DumpModeSeek(TIFF * tif,uint32 nrows)111 DumpModeSeek(TIFF* tif, uint32 nrows)
112 {
113 	tif->tif_rawcp += nrows * tif->tif_scanlinesize;
114 	tif->tif_rawcc -= nrows * tif->tif_scanlinesize;
115 	return (1);
116 }
117 
118 /*
119  * Initialize dump mode.
120  */
121 int
TIFFInitDumpMode(TIFF * tif,int scheme)122 TIFFInitDumpMode(TIFF* tif, int scheme)
123 {
124 	(void) scheme;
125 	tif->tif_fixuptags = DumpFixupTags;
126 	tif->tif_decoderow = DumpModeDecode;
127 	tif->tif_decodestrip = DumpModeDecode;
128 	tif->tif_decodetile = DumpModeDecode;
129 	tif->tif_encoderow = DumpModeEncode;
130 	tif->tif_encodestrip = DumpModeEncode;
131 	tif->tif_encodetile = DumpModeEncode;
132 	tif->tif_seek = DumpModeSeek;
133 	return (1);
134 }
135 /*
136  * Local Variables:
137  * mode: c
138  * c-basic-offset: 8
139  * fill-column: 78
140  * End:
141  */
142