static int TWebPVSetField(TIFF* tif, uint32 tag, va_list ap) { static const char module[] = "WebPVSetField"; WebPState* sp = LState(tif); switch (tag) { case TIFFTAG_WEBP_LEVEL: sp->quality_level = (int) va_arg(ap, int); if( sp->quality_level <= 0 || sp->quality_level > 100.0f ) { TIFFWarningExt(tif->tif_clientdata, module, "WEBP_LEVEL should be between 1 and 100"); } return 1; case TIFFTAG_WEBP_LOSSLESS: #if WEBP_ENCODER_ABI_VERSION >= 0x0100 sp->lossless = va_arg(ap, int); if (sp->lossless){ sp->quality_level = 100.0f; } return 1; #else TIFFErrorExt(tif->tif_clientdata, module, "Need to upgrade WEBP driver, this version doesn't support " "lossless compression."); return 0; #endif default: return (*sp->vsetparent)(tif, tag, ap); } /*NOTREACHED*/ }
static int LZMAVSetField(TIFF* tif, uint32 tag, va_list ap) { static const char module[] = "LZMAVSetField"; LZMAState* sp = LState(tif); switch (tag) { case TIFFTAG_LZMAPRESET: sp->preset = (int) va_arg(ap, int); lzma_lzma_preset(&sp->opt_lzma, sp->preset); if (sp->state & LSTATE_INIT_ENCODE) { lzma_ret ret = lzma_stream_encoder(&sp->stream, sp->filters, sp->check); if (ret != LZMA_OK) { TIFFErrorExt(tif->tif_clientdata, module, "Liblzma error: %s", LZMAStrerror(ret)); } } return 1; default: return (*sp->vsetparent)(tif, tag, ap); } /*NOTREACHED*/ }
static int LERCVGetField(TIFF* tif, uint32 tag, va_list ap) { LERCState* sp = LState(tif); switch (tag) { case TIFFTAG_LERC_MAXZERROR: *va_arg(ap, double*) = sp->maxzerror; break; case TIFFTAG_LERC_VERSION: *va_arg(ap, int*) = sp->lerc_version; break; case TIFFTAG_LERC_ADD_COMPRESSION: *va_arg(ap, int*) = sp->additional_compression; break; case TIFFTAG_ZSTD_LEVEL: *va_arg(ap, int*) = sp->zstd_compress_level; break; case TIFFTAG_ZIPQUALITY: *va_arg(ap, int*) = sp->zipquality; break; default: return (*sp->vgetparent)(tif, tag, ap); } return 1; }
static void TWebPCleanup(TIFF* tif) { WebPState* sp = LState(tif); assert(sp != 0); tif->tif_tagmethods.vgetfield = sp->vgetparent; tif->tif_tagmethods.vsetfield = sp->vsetparent; if (sp->state & LSTATE_INIT_ENCODE) { WebPPictureFree(&sp->sPicture); } if (sp->psDecoder != NULL) { WebPIDelete(sp->psDecoder); WebPFreeDecBuffer(&sp->sDecBuffer); sp->psDecoder = NULL; sp->last_y = 0; } if (sp->pBuffer != NULL) { _TIFFfree(sp->pBuffer); sp->pBuffer = NULL; } _TIFFfree(tif->tif_data); tif->tif_data = NULL; _TIFFSetDefaultCompressionState(tif); }
static int LERCVSetFieldBase(TIFF* tif, uint32 tag, ...) { LERCState* sp = LState(tif); int ret; va_list ap; va_start(ap, tag); ret = (*sp->vsetparent)(tif, tag, ap); va_end(ap); return ret; }
static int LZMAVGetField(TIFF* tif, uint32 tag, va_list ap) { LZMAState* sp = LState(tif); switch (tag) { case TIFFTAG_LZMAPRESET: *va_arg(ap, int*) = sp->preset; break; default: return (*sp->vgetparent)(tif, tag, ap); } return 1; }
static int TWebPVGetField(TIFF* tif, uint32 tag, va_list ap) { WebPState* sp = LState(tif); switch (tag) { case TIFFTAG_WEBP_LEVEL: *va_arg(ap, int*) = sp->quality_level; break; case TIFFTAG_WEBP_LOSSLESS: *va_arg(ap, int*) = sp->lossless; default: return (*sp->vgetparent)(tif, tag, ap); } return 1; }
static void LERCCleanup(TIFF* tif) { LERCState* sp = LState(tif); assert(sp != 0); tif->tif_tagmethods.vgetfield = sp->vgetparent; tif->tif_tagmethods.vsetfield = sp->vsetparent; _TIFFfree(sp->uncompressed_buffer); _TIFFfree(sp->compressed_buffer); _TIFFfree(sp->mask_buffer); _TIFFfree(sp); tif->tif_data = NULL; _TIFFSetDefaultCompressionState(tif); }
static void LZMACleanup(TIFF* tif) { LZMAState* sp = LState(tif); assert(sp != 0); (void)TIFFPredictorCleanup(tif); tif->tif_tagmethods.vgetfield = sp->vgetparent; tif->tif_tagmethods.vsetfield = sp->vsetparent; if (sp->state) { lzma_end(&sp->stream); sp->state = 0; } _TIFFfree(sp); tif->tif_data = NULL; _TIFFSetDefaultCompressionState(tif); }
int TIFFInitLZMA(TIFF* tif, int scheme) { static const char module[] = "TIFFInitLZMA"; LZMAState* sp; lzma_stream tmp_stream = LZMA_STREAM_INIT; assert( scheme == COMPRESSION_LZMA ); /* * Merge codec-specific tag information. */ if (!_TIFFMergeFields(tif, lzmaFields, TIFFArrayCount(lzmaFields))) { TIFFErrorExt(tif->tif_clientdata, module, "Merging LZMA2 codec-specific tags failed"); return 0; } /* * Allocate state block so tag methods have storage to record values. */ tif->tif_data = (uint8*) _TIFFmalloc(sizeof(LZMAState)); if (tif->tif_data == NULL) goto bad; sp = LState(tif); memcpy(&sp->stream, &tmp_stream, sizeof(lzma_stream)); /* * Override parent get/set field methods. */ sp->vgetparent = tif->tif_tagmethods.vgetfield; tif->tif_tagmethods.vgetfield = LZMAVGetField; /* hook for codec tags */ sp->vsetparent = tif->tif_tagmethods.vsetfield; tif->tif_tagmethods.vsetfield = LZMAVSetField; /* hook for codec tags */ /* Default values for codec-specific fields */ sp->preset = LZMA_PRESET_DEFAULT; /* default comp. level */ sp->check = LZMA_CHECK_NONE; sp->state = 0; /* Data filters. So far we are using delta and LZMA2 filters only. */ sp->opt_delta.type = LZMA_DELTA_TYPE_BYTE; /* * The sample size in bytes seems to be reasonable distance for delta * filter. */ sp->opt_delta.dist = (tif->tif_dir.td_bitspersample % 8) ? 1 : tif->tif_dir.td_bitspersample / 8; sp->filters[0].id = LZMA_FILTER_DELTA; sp->filters[0].options = &sp->opt_delta; lzma_lzma_preset(&sp->opt_lzma, sp->preset); sp->filters[1].id = LZMA_FILTER_LZMA2; sp->filters[1].options = &sp->opt_lzma; sp->filters[2].id = LZMA_VLI_UNKNOWN; sp->filters[2].options = NULL; /* * Install codec methods. */ tif->tif_fixuptags = LZMAFixupTags; tif->tif_setupdecode = LZMASetupDecode; tif->tif_predecode = LZMAPreDecode; tif->tif_decoderow = LZMADecode; tif->tif_decodestrip = LZMADecode; tif->tif_decodetile = LZMADecode; tif->tif_setupencode = LZMASetupEncode; tif->tif_preencode = LZMAPreEncode; tif->tif_postencode = LZMAPostEncode; tif->tif_encoderow = LZMAEncode; tif->tif_encodestrip = LZMAEncode; tif->tif_encodetile = LZMAEncode; tif->tif_cleanup = LZMACleanup; /* * Setup predictor setup. */ (void) TIFFPredictorInit(tif); return 1; bad: TIFFErrorExt(tif->tif_clientdata, module, "No space for LZMA2 state block"); return 0; }
int TIFFInitWebP(TIFF* tif, int scheme) { static const char module[] = "TIFFInitWebP"; WebPState* sp; assert( scheme == COMPRESSION_WEBP ); /* * Merge codec-specific tag information. */ if ( !_TIFFMergeFields(tif, TWebPFields, TIFFArrayCount(TWebPFields)) ) { TIFFErrorExt(tif->tif_clientdata, module, "Merging WebP codec-specific tags failed"); return 0; } /* * Allocate state block so tag methods have storage to record values. */ tif->tif_data = (uint8*) _TIFFmalloc(sizeof(WebPState)); if (tif->tif_data == NULL) goto bad; sp = LState(tif); /* * Override parent get/set field methods. */ sp->vgetparent = tif->tif_tagmethods.vgetfield; tif->tif_tagmethods.vgetfield = TWebPVGetField; /* hook for codec tags */ sp->vsetparent = tif->tif_tagmethods.vsetfield; tif->tif_tagmethods.vsetfield = TWebPVSetField; /* hook for codec tags */ /* Default values for codec-specific fields */ sp->quality_level = 75.0f; /* default comp. level */ sp->lossless = 0; /* default to false */ sp->state = 0; sp->nSamples = 0; sp->psDecoder = NULL; sp->last_y = 0; sp->buffer_offset = 0; sp->pBuffer = NULL; /* * Install codec methods. * Notes: * encoderow is not supported */ tif->tif_fixuptags = TWebPFixupTags; tif->tif_setupdecode = TWebPSetupDecode; tif->tif_predecode = TWebPPreDecode; tif->tif_decoderow = TWebPDecode; tif->tif_decodestrip = TWebPDecode; tif->tif_decodetile = TWebPDecode; tif->tif_setupencode = TWebPSetupEncode; tif->tif_preencode = TWebPPreEncode; tif->tif_postencode = TWebPPostEncode; tif->tif_encoderow = TWebPEncode; tif->tif_encodestrip = TWebPEncode; tif->tif_encodetile = TWebPEncode; tif->tif_cleanup = TWebPCleanup; return 1; bad: TIFFErrorExt(tif->tif_clientdata, module, "No space for WebP state block"); return 0; }
int TIFFInitLERC(TIFF* tif, int scheme) { static const char module[] = "TIFFInitLERC"; LERCState* sp; assert( scheme == COMPRESSION_LERC ); /* * Merge codec-specific tag information. */ if (!_TIFFMergeFields(tif, LERCFields, TIFFArrayCount(LERCFields))) { TIFFErrorExt(tif->tif_clientdata, module, "Merging LERC codec-specific tags failed"); return 0; } /* * Allocate state block so tag methods have storage to record values. */ tif->tif_data = (uint8*) _TIFFcalloc(1, sizeof(LERCState)); if (tif->tif_data == NULL) goto bad; sp = LState(tif); /* * Override parent get/set field methods. */ sp->vgetparent = tif->tif_tagmethods.vgetfield; tif->tif_tagmethods.vgetfield = LERCVGetField; /* hook for codec tags */ sp->vsetparent = tif->tif_tagmethods.vsetfield; tif->tif_tagmethods.vsetfield = LERCVSetField; /* hook for codec tags */ /* * Install codec methods. */ tif->tif_fixuptags = LERCFixupTags; tif->tif_setupdecode = LERCSetupDecode; tif->tif_predecode = LERCPreDecode; tif->tif_decoderow = LERCDecode; tif->tif_decodestrip = LERCDecode; tif->tif_decodetile = LERCDecode; tif->tif_setupencode = LERCSetupEncode; tif->tif_preencode = LERCPreEncode; tif->tif_postencode = LERCPostEncode; tif->tif_encoderow = LERCEncode; tif->tif_encodestrip = LERCEncode; tif->tif_encodetile = LERCEncode; tif->tif_cleanup = LERCCleanup; /* Default values for codec-specific fields */ TIFFSetField(tif, TIFFTAG_LERC_VERSION, LERC_VERSION_2_4); TIFFSetField(tif, TIFFTAG_LERC_ADD_COMPRESSION, LERC_ADD_COMPRESSION_NONE); sp->maxzerror = 0.0; sp->zstd_compress_level = 9; /* default comp. level */ sp->zipquality = Z_DEFAULT_COMPRESSION; /* default comp. level */ sp->state = 0; return 1; bad: TIFFErrorExt(tif->tif_clientdata, module, "No space for LERC state block"); return 0; }
static int LERCVSetField(TIFF* tif, uint32 tag, va_list ap) { static const char module[] = "LERCVSetField"; LERCState* sp = LState(tif); switch (tag) { case TIFFTAG_LERC_PARAMETERS: { uint32 count = va_arg(ap, int); int* params = va_arg(ap, int*); if( count < 2 ) { TIFFErrorExt(tif->tif_clientdata, module, "Invalid count for LercParameters: %u", count); return 0; } sp->lerc_version = params[0]; sp->additional_compression = params[1]; return LERCVSetFieldBase(tif, TIFFTAG_LERC_PARAMETERS, count, params); } case TIFFTAG_LERC_MAXZERROR: sp->maxzerror = va_arg(ap, double); return 1; case TIFFTAG_LERC_VERSION: { int params[2] = {0, 0}; int version = va_arg(ap, int); if( version != LERC_VERSION_2_4 ) { TIFFErrorExt(tif->tif_clientdata, module, "Invalid value for LercVersion: %d", version); return 0; } sp->lerc_version = version; params[0] = sp->lerc_version; params[1] = sp->additional_compression; return LERCVSetFieldBase(tif, TIFFTAG_LERC_PARAMETERS, 2, params); } case TIFFTAG_LERC_ADD_COMPRESSION: { int params[2] = {0, 0}; int additional_compression = va_arg(ap, int); #ifndef ZSTD_SUPPORT if( additional_compression == LERC_ADD_COMPRESSION_ZSTD ) { TIFFErrorExt(tif->tif_clientdata, module, "LERC_ZSTD requested, but ZSTD not available"); return 0; } #endif if( additional_compression != LERC_ADD_COMPRESSION_NONE && additional_compression != LERC_ADD_COMPRESSION_DEFLATE && additional_compression != LERC_ADD_COMPRESSION_ZSTD ) { TIFFErrorExt(tif->tif_clientdata, module, "Invalid value for LercAdditionalCompression: %d", additional_compression); return 0; } sp->additional_compression = additional_compression; params[0] = sp->lerc_version; params[1] = sp->additional_compression; return LERCVSetFieldBase(tif, TIFFTAG_LERC_PARAMETERS, 2, params); } #ifdef ZSTD_SUPPORT case TIFFTAG_ZSTD_LEVEL: { sp->zstd_compress_level = (int) va_arg(ap, int); if( sp->zstd_compress_level <= 0 || sp->zstd_compress_level > ZSTD_maxCLevel() ) { TIFFWarningExt(tif->tif_clientdata, module, "ZSTD_LEVEL should be between 1 and %d", ZSTD_maxCLevel()); } return 1; } #endif case TIFFTAG_ZIPQUALITY: { sp->zipquality = (int) va_arg(ap, int); return (1); } default: return (*sp->vsetparent)(tif, tag, ap); } /*NOTREACHED*/ }