static void LZWCleanup(TIFF* tif) { if (tif->tif_data) { if (LZWState(tif)->rw_mode == O_RDONLY) { if (DecoderState(tif)->dec_codetab) _TIFFfree(DecoderState(tif)->dec_codetab); } else { if (EncoderState(tif)->enc_hashtab) _TIFFfree(EncoderState(tif)->enc_hashtab); } _TIFFfree(tif->tif_data); tif->tif_data = NULL; } }
int TIFFInitLZW(TIFF* tif, int scheme) { assert(scheme == COMPRESSION_LZW); /* * Allocate state block so tag methods have storage to record values. */ if (tif->tif_mode == O_RDONLY) { tif->tif_data = (tidata_t) _TIFFmalloc(sizeof (LZWDecodeState)); if (tif->tif_data == NULL) goto bad; DecoderState(tif)->dec_codetab = NULL; DecoderState(tif)->dec_decode = NULL; } else { tif->tif_data = (tidata_t) _TIFFmalloc(sizeof (LZWEncodeState)); if (tif->tif_data == NULL) goto bad; EncoderState(tif)->enc_hashtab = NULL; } LZWState(tif)->rw_mode = tif->tif_mode; /* * Install codec methods. */ tif->tif_setupdecode = LZWSetupDecode; tif->tif_predecode = LZWPreDecode; tif->tif_decoderow = LZWDecode; tif->tif_decodestrip = LZWDecode; tif->tif_decodetile = LZWDecode; tif->tif_setupencode = LZWSetupEncode; tif->tif_preencode = LZWPreEncode; tif->tif_postencode = LZWPostEncode; tif->tif_encoderow = LZWEncode; tif->tif_encodestrip = LZWEncode; tif->tif_encodetile = LZWEncode; tif->tif_cleanup = LZWCleanup; /* * Setup predictor setup. */ (void) TIFFPredictorInit(tif); return (1); bad: TIFFError("TIFFInitLZW", "No space for LZW state block"); return (0); }
int TIFFInitLZW(TIFF* tif, int scheme) { static const char module[] = "TIFFInitLZW"; assert(scheme == COMPRESSION_LZW); /* * Allocate state block so tag methods have storage to record values. */ tif->tif_data = (uint8*) _TIFFmalloc(sizeof (LZWCodecState)); if (tif->tif_data == NULL) goto bad; DecoderState(tif)->dec_codetab = NULL; DecoderState(tif)->dec_decode = NULL; EncoderState(tif)->enc_hashtab = NULL; LZWState(tif)->rw_mode = tif->tif_mode; /* * Install codec methods. */ tif->tif_fixuptags = LZWFixupTags; tif->tif_setupdecode = LZWSetupDecode; tif->tif_predecode = LZWPreDecode; tif->tif_decoderow = LZWDecode; tif->tif_decodestrip = LZWDecode; tif->tif_decodetile = LZWDecode; tif->tif_setupencode = LZWSetupEncode; tif->tif_preencode = LZWPreEncode; tif->tif_postencode = LZWPostEncode; tif->tif_encoderow = LZWEncode; tif->tif_encodestrip = LZWEncode; tif->tif_encodetile = LZWEncode; tif->tif_cleanup = LZWCleanup; /* * Setup predictor setup. */ (void) TIFFPredictorInit(tif); return (1); bad: TIFFErrorExt(tif->tif_clientdata, module, "No space for LZW state block"); return (0); }