41 #define TIFF_MAX_ENTRY 32
96 static void tnput(uint8_t ** p,
int n,
const uint8_t * val,
enum TiffTypes type,
101 flip ^= ((
int[]) {0, 0, 0, 1, 3, 3})[type];
104 *(*p)++ = val[i ^
flip];
123 bytestream_put_le16(&entries_ptr, tag);
124 bytestream_put_le16(&entries_ptr, type);
125 bytestream_put_le32(&entries_ptr, count);
128 tnput(&entries_ptr, count, ptr_val, type, 0);
130 bytestream_put_le32(&entries_ptr, *s->
buf - s->
buf_start);
132 tnput(s->
buf, count, ptr_val, type, 0);
156 uint8_t * dst,
int n,
int compr)
165 if (compress(dst, &zlen, src, n) != Z_OK) {
193 for (i = 0; i < w; i++){
204 int buf_size,
void *
data)
214 uint32_t *strip_sizes =
NULL;
215 uint32_t *strip_offsets =
NULL;
217 uint32_t res[2] = { 72, 1 };
218 static const uint16_t bpp_tab[] = { 8, 8, 8, 8 };
221 uint8_t *yuv_line =
NULL;
222 int shift_h, shift_v;
227 s->buf_size = buf_size;
232 avctx->coded_frame= &s->picture;
234 #if FF_API_TIFFENC_COMPLEVEL
237 "algorithm is deprecated. Please use the compression_algo private "
238 "option instead.\n");
239 if (avctx->compression_level == 0) {
241 }
else if(avctx->compression_level == 2) {
244 }
else if ((avctx->compression_level >= 3)) {
250 s->width = avctx->width;
251 s->height = avctx->height;
252 s->subsampling[0] = 1;
253 s->subsampling[1] = 1;
255 switch (avctx->pix_fmt) {
258 s->photometric_interpretation = 2;
262 s->photometric_interpretation = 1;
266 s->photometric_interpretation = 3;
270 s->photometric_interpretation = 1;
274 s->photometric_interpretation = 0;
281 s->photometric_interpretation = 6;
284 s->bpp = 8 + (16 >> (shift_h + shift_v));
285 s->subsampling[0] = 1 << shift_h;
286 s->subsampling[1] = 1 << shift_v;
292 "This colors format is not supported\n");
296 s->bpp_tab_size = (s->bpp >> 3);
302 s->rps =
FFMAX(8192 / (((s->width * s->bpp) >> 3) + 1), 1);
303 s->rps = ((s->rps - 1) / s->subsampling[1] + 1) * s->subsampling[1];
305 strips = (s->height - 1) / s->rps + 1;
311 bytestream_put_le16(&ptr, 0x4949);
312 bytestream_put_le16(&ptr, 42);
315 bytestream_put_le32(&ptr, 0);
317 strip_sizes =
av_mallocz(
sizeof(*strip_sizes) * strips);
318 strip_offsets =
av_mallocz(
sizeof(*strip_offsets) * strips);
319 if (!strip_sizes || !strip_offsets) {
324 bytes_per_row = (((s->width - 1)/s->subsampling[0] + 1) * s->bpp
325 * s->subsampling[0] * s->subsampling[1] + 7) >> 3;
328 if (yuv_line ==
NULL){
341 zlen = bytes_per_row * s->rps;
347 strip_offsets[0] = ptr - buf;
349 for (j = 0; j < s->rps; j++) {
352 memcpy(zbuf + zn, yuv_line, bytes_per_row);
353 j += s->subsampling[1] - 1;
356 memcpy(zbuf + j * bytes_per_row,
357 p->data[0] + j * p->linesize[0], bytes_per_row);
367 strip_sizes[0] = ptr - buf - strip_offsets[0];
378 for (i = 0; i < s->height; i++) {
379 if (strip_sizes[i / s->rps] == 0) {
384 strip_offsets[i / s->rps] = ptr - buf;
388 n =
encode_strip(s, yuv_line, ptr, bytes_per_row, s->compr);
389 i += s->subsampling[1] - 1;
393 ptr, bytes_per_row, s->compr);
398 strip_sizes[i / s->rps] += n;
400 if(s->compr ==
TIFF_LZW && (i==s->height-1 || i%s->rps == s->rps-1)){
403 strip_sizes[(i / s->rps )] += ret ;
438 uint16_t pal[256 * 3];
439 for (i = 0; i < 256; i++) {
440 uint32_t rgb = *(uint32_t *) (p->data[1] + i * 4);
441 pal[i] = ((rgb >> 16) & 0xff) * 257;
442 pal[i + 256] = ((rgb >> 8 ) & 0xff) * 257;
443 pal[i + 512] = ( rgb & 0xff) * 257;
449 uint32_t refbw[12] = {15, 1, 235, 1, 128, 1, 240, 1, 128, 1, 240, 1};
453 bytestream_put_le32(&offset, ptr - buf);
457 bytestream_put_le16(&ptr, s->num_entries);
459 bytestream_put_le32(&ptr, 0);
470 #define OFFSET(x) offsetof(TiffEncoderContext, x)
471 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM