LibTIFF 4.7.2
TIFF library public API and implementation reference
Loading...
Searching...
No Matches
tif_dumpmode.c
Go to the documentation of this file.
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 */
35#include "tiffiop.h"
36
46static int DumpFixupTags(TIFF *tif)
47{
48 (void)tif;
49 return (1);
50}
51
52/*
53 * Encode a hunk of pixels.
54 */
73static int DumpModeEncode(TIFF *tif, uint8_t *pp, tmsize_t cc, uint16_t s)
74{
75 (void)s;
76 while (cc > 0)
77 {
78 tmsize_t n;
79
80 n = cc;
81 if (tif->tif_rawcc + n > tif->tif_rawdatasize)
82 n = tif->tif_rawdatasize - tif->tif_rawcc;
83
84 assert(n > 0);
85
86 /*
87 * Avoid copy if client has setup raw
88 * data buffer to avoid extra copy.
89 */
90 if (tif->tif_rawcp != pp)
91 _TIFFmemcpy(tif->tif_rawcp, pp, n);
92 tif->tif_rawcp += n;
93 tif->tif_rawcc += n;
94 pp += n;
95 cc -= n;
96 if (tif->tif_rawcc >= tif->tif_rawdatasize && !TIFFFlushData1(tif))
97 return (0);
98 }
99 return (1);
100}
101
102/*
103 * Decode a hunk of pixels.
104 */
124static int DumpModeDecode(TIFF *tif, uint8_t *buf, tmsize_t cc, uint16_t s)
125{
126 static const char module[] = "DumpModeDecode";
127 (void)s;
128 if (tif->tif_rawcc < cc)
129 {
130 /* Clear the part of the buffer that is not written. */
131 memset(buf, 0, (size_t)cc);
132 TIFFErrorExtR(tif, module,
133 "Not enough data for scanline %" PRIu32
134 ", expected a request for at most %" TIFF_SSIZE_FORMAT
135 " bytes, got a request for %" TIFF_SSIZE_FORMAT " bytes",
136 tif->tif_dir.td_row, tif->tif_rawcc, cc);
137 return (0);
138 }
139 /*
140 * Avoid copy if client has setup raw
141 * data buffer to avoid extra copy.
142 */
143 if (tif->tif_rawcp != buf)
144 _TIFFmemcpy(buf, tif->tif_rawcp, cc);
145 tif->tif_rawcp += cc;
146 tif->tif_rawcc -= cc;
147 return (1);
148}
149
150/*
151 * Seek forwards nrows in the current strip.
152 */
167static int DumpModeSeek(TIFF *tif, uint32_t nrows)
168{
169 tmsize_t seek_size;
170 if (nrows > 0 &&
172 {
173 TIFFErrorExtR(tif, "DumpModeSeek",
174 "Integer overflow computing seek size");
175 return (0);
176 }
177 seek_size = (tmsize_t)nrows * tif->tif_dir.td_scanlinesize;
178 if (seek_size > tif->tif_rawcc)
179 {
180 TIFFErrorExtR(tif, "DumpModeSeek",
181 "Seek beyond end of raw data buffer");
182 return (0);
183 }
184 tif->tif_rawcp += seek_size;
185 tif->tif_rawcc -= seek_size;
186 return (1);
187}
188
189/*
190 * Initialize dump mode.
191 */
192int TIFFInitDumpMode(TIFF *tif, int scheme)
193{
194 (void)scheme;
202 tif->tif_seek = DumpModeSeek;
203 return (1);
204}
int TIFFInitDumpMode(TIFF *tif, int scheme)
Install uncompressed transfer callbacks.
static int DumpModeSeek(TIFF *tif, uint32_t nrows)
Advance uncompressed raw input by complete scanlines.
static int DumpModeDecode(TIFF *tif, uint8_t *buf, tmsize_t cc, uint16_t s)
Copy uncompressed raw input into decoded output.
static int DumpFixupTags(TIFF *tif)
Accept uncompressed tag fixup without changes.
static int DumpModeEncode(TIFF *tif, uint8_t *pp, tmsize_t cc, uint16_t s)
Copy uncompressed bytes into the raw output buffer.
#define TIFF_SSIZE_FORMAT
Provide the printf conversion fragment for tmsize_t, without a percent sign.
Definition tif_config.h:294
int TIFFFlushData1(TIFF *tif)
Append buffered encoded bytes without invoking postencode recursively.
Definition tif_write.c:1213
void TIFFErrorExtR(TIFF *tif, const char *module, const char *fmt,...)
Dispatch a error diagnostic to the configured handlers.
Definition tif_error.c:112
void _TIFFmemcpy(void *d, const void *s, tmsize_t c)
Copy a non-overlapping byte range.
Definition tif_unix.c:497
TIFF_SSIZE_T tmsize_t
Represent a signed memory or I/O size in bytes.
Definition tiffio.h:89
#define TIFF_TMSIZE_T_MAX
Define the largest positive size representable by tmsize_t.
Definition tiffio.h:91
tmsize_t td_scanlinesize
Cached decoded scanline size in bytes; zero when not computed.
Definition tif_dir.h:245
uint32_t td_row
Current scanline index; UINT32_MAX before traversal starts.
Definition tif_dir.h:240
Hold private state for one open TIFF library instance.
Definition tiffiop.h:389
TIFFCodeMethod tif_encodestrip
Codec callback encoding strip data.
Definition tiffiop.h:649
TIFFSeekMethod tif_seek
Codec callback advancing within a strip.
Definition tiffiop.h:659
TIFFCodeMethod tif_encodetile
Codec callback encoding tile data.
Definition tiffiop.h:653
TIFFBoolMethod tif_fixuptags
Codec callback for directory-dependent tag corrections.
Definition tiffiop.h:626
tmsize_t tif_rawcc
Raw-buffer byte count interpreted according to read/write state.
Definition tiffiop.h:696
TIFFCodeMethod tif_decodestrip
Codec callback decoding strip data.
Definition tiffiop.h:647
TIFFCodeMethod tif_decoderow
Codec callback decoding a scanline.
Definition tiffiop.h:643
TIFFDirectory tif_dir
Inline representation of the current image directory.
Definition tiffiop.h:572
TIFFCodeMethod tif_encoderow
Codec callback encoding a scanline.
Definition tiffiop.h:645
uint8_t * tif_rawcp
Borrowed current-position pointer into the raw buffer.
Definition tiffiop.h:692
tmsize_t tif_rawdatasize
Raw-buffer capacity in bytes; kept in step with tif_rawdata, including zero whenever tif_rawdata is N...
Definition tiffiop.h:686
TIFFCodeMethod tif_decodetile
Codec callback decoding tile data.
Definition tiffiop.h:651
Declare private library state, callbacks, and implementation helpers.