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