Lines Matching refs:enc
138 static int AnalyzeAndInit(VP8LEncoder* const enc, WebPImageHint image_hint) {
139 const WebPPicture* const pic = enc->pic_;
148 enc->use_palette_ =
149 AnalyzeAndCreatePalette(pic, enc->palette_, &enc->palette_size_);
152 if (enc->use_palette_ && enc->palette_size_ < MAX_COLORS_FOR_GRAPH) {
153 enc->use_palette_ = 0;
157 if (!enc->use_palette_) {
159 enc->use_predict_ = 1;
160 enc->use_cross_color_ = 1;
168 enc->use_predict_ = 1;
169 enc->use_cross_color_ = 1;
173 if (!VP8LHashChainInit(&enc->hash_chain_, pix_cnt)) return 0;
177 if (enc->use_palette_) refs_block_size /= 2;
178 VP8LBackwardRefsInit(&enc->refs_[0], refs_block_size);
179 VP8LBackwardRefsInit(&enc->refs_[1], refs_block_size);
701 static WebPEncodingError EvalAndApplySubtractGreen(VP8LEncoder* const enc,
704 if (!enc->use_palette_) {
706 const uint32_t* const argb = enc->argb_;
729 enc->use_subtract_green_ = (bit_cost_after < bit_cost_before);
730 if (enc->use_subtract_green_) {
733 VP8LSubtractGreenFromBlueAndRed(enc->argb_, width * height);
739 static WebPEncodingError ApplyPredictFilter(const VP8LEncoder* const enc,
742 const int pred_bits = enc->transform_bits_;
746 VP8LResidualImage(width, height, pred_bits, enc->argb_, enc->argb_scratch_,
747 enc->transform_data_);
752 return EncodeImageNoHuffman(bw, enc->transform_data_,
753 (VP8LHashChain*)&enc->hash_chain_,
754 (VP8LBackwardRefs*)enc->refs_, // cast const away
759 static WebPEncodingError ApplyCrossColorFilter(const VP8LEncoder* const enc,
763 const int ccolor_transform_bits = enc->transform_bits_;
768 enc->argb_, enc->transform_data_);
773 return EncodeImageNoHuffman(bw, enc->transform_data_,
774 (VP8LHashChain*)&enc->hash_chain_,
775 (VP8LBackwardRefs*)enc->refs_, // cast const away
849 static WebPEncodingError AllocateTransformBuffer(VP8LEncoder* const enc,
852 const int tile_size = 1 << enc->transform_bits_;
856 VP8LSubSampleSize(width, enc->transform_bits_) *
857 VP8LSubSampleSize(height, enc->transform_bits_);
865 enc->argb_ = mem;
867 enc->argb_scratch_ = mem;
869 enc->transform_data_ = mem;
870 enc->current_width_ = width;
929 // Note: Expects "enc->palette_" to be set properly.
930 // Also, "enc->palette_" will be modified after this call and should not be used
933 VP8LEncoder* const enc, int quality) {
936 const WebPPicture* const pic = enc->pic_;
941 uint32_t* const palette = enc->palette_;
942 const int palette_size = enc->palette_size_;
954 err = AllocateTransformBuffer(enc, VP8LSubSampleSize(width, xbits), height);
956 dst = enc->argb_;
961 ApplyPalette(src, dst, pic->argb_stride, enc->current_width_,
972 err = EncodeImageNoHuffman(bw, palette, &enc->hash_chain_, enc->refs_,
1005 static void FinishEncParams(VP8LEncoder* const enc) {
1006 const WebPConfig* const config = enc->config_;
1007 const WebPPicture* const pic = enc->pic_;
1010 const int use_palette = enc->use_palette_;
1011 enc->histo_bits_ = GetHistoBits(method, use_palette, pic->width, pic->height);
1012 enc->transform_bits_ = GetTransformBits(method, enc->histo_bits_);
1013 enc->cache_bits_ = GetCacheBits(quality);
1021 VP8LEncoder* const enc = (VP8LEncoder*)WebPSafeCalloc(1ULL, sizeof(*enc));
1022 if (enc == NULL) {
1026 enc->config_ = config;
1027 enc->pic_ = picture;
1031 return enc;
1034 static void VP8LEncoderDelete(VP8LEncoder* enc) {
1035 if (enc != NULL) {
1036 VP8LHashChainClear(&enc->hash_chain_);
1037 VP8LBackwardRefsClear(&enc->refs_[0]);
1038 VP8LBackwardRefsClear(&enc->refs_[1]);
1039 WebPSafeFree(enc->argb_);
1040 WebPSafeFree(enc);
1054 VP8LEncoder* const enc = VP8LEncoderNew(config, picture);
1057 if (enc == NULL) {
1065 if (!AnalyzeAndInit(enc, config->image_hint)) {
1070 FinishEncParams(enc);
1072 if (enc->use_palette_) {
1073 err = EncodePalette(bw, enc, quality);
1076 enc->cache_bits_ = 0;
1080 if (enc->argb_ == NULL) {
1082 err = AllocateTransformBuffer(enc, width, height);
1085 memcpy(enc->argb_ + y * width,
1087 width * sizeof(*enc->argb_));
1089 enc->current_width_ = width;
1095 err = EvalAndApplySubtractGreen(enc, enc->current_width_, height, bw);
1098 if (enc->use_predict_) {
1099 err = ApplyPredictFilter(enc, enc->current_width_, height, quality, bw);
1103 if (enc->use_cross_color_) {
1104 err = ApplyCrossColorFilter(enc, enc->current_width_, height, quality, bw);
1113 if (enc->cache_bits_ > 0) {
1114 if (!VP8LCalculateEstimateForCacheSize(enc->argb_, enc->current_width_,
1115 height, quality, &enc->hash_chain_,
1116 &enc->refs_[0], &enc->cache_bits_)) {
1125 err = EncodeImageInternal(bw, enc->argb_, &enc->hash_chain_, enc->refs_,
1126 enc->current_width_, height, quality,
1127 enc->cache_bits_, enc->histo_bits_);
1133 if (enc->use_predict_) stats->lossless_features |= 1;
1134 if (enc->use_cross_color_) stats->lossless_features |= 2;
1135 if (enc->use_subtract_green_) stats->lossless_features |= 4;
1136 if (enc->use_palette_) stats->lossless_features |= 8;
1137 stats->histogram_bits = enc->histo_bits_;
1138 stats->transform_bits = enc->transform_bits_;
1139 stats->cache_bits = enc->cache_bits_;
1140 stats->palette_size = enc->palette_size_;
1145 VP8LEncoderDelete(enc);