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