Lines Matching refs:enc
59 static void ResetStats(VP8Encoder* const enc) {
60 VP8Proba* const proba = &enc->proba_;
75 static int FinalizeSkipProba(VP8Encoder* const enc) {
76 VP8Proba* const proba = &enc->proba_;
77 const int nb_mbs = enc->mb_w_ * enc->mb_h_;
94 static void ResetTokenStats(VP8Encoder* const enc) {
95 VP8Proba* const proba = &enc->proba_;
225 static void SetSegmentProbas(VP8Encoder* const enc) {
229 for (n = 0; n < enc->mb_w_ * enc->mb_h_; ++n) {
230 const VP8MBInfo* const mb = &enc->mb_info_[n];
233 if (enc->pic_->stats != NULL) {
235 enc->pic_->stats->segment_size[n] = p[n];
238 if (enc->segment_hdr_.num_segments_ > 1) {
239 uint8_t* const probas = enc->proba_.segments_;
244 enc->segment_hdr_.update_map_ =
246 enc->segment_hdr_.size_ =
252 enc->segment_hdr_.update_map_ = 0;
253 enc->segment_hdr_.size_ = 0;
261 VP8Encoder* const enc, VP8Residual* const res) {
263 res->prob = enc->proba_.coeffs_[coeff_type];
264 res->stats = enc->proba_.stats_[coeff_type];
265 res->cost = enc->proba_.level_cost_[coeff_type];
334 VP8Encoder* const enc = it->enc_;
338 InitResidual(0, 3, enc, &res);
347 VP8Encoder* const enc = it->enc_;
354 InitResidual(0, 1, enc, &res);
359 InitResidual(1, 0, enc, &res);
373 VP8Encoder* const enc = it->enc_;
379 InitResidual(0, 2, enc, &res);
475 VP8Encoder* const enc = it->enc_;
481 InitResidual(0, 1, enc, &res);
485 InitResidual(1, 0, enc, &res);
487 InitResidual(0, 3, enc, &res);
501 InitResidual(0, 2, enc, &res);
526 VP8Encoder* const enc = it->enc_;
531 InitResidual(0, 1, enc, &res);
535 InitResidual(1, 0, enc, &res);
537 InitResidual(0, 3, enc, &res);
550 InitResidual(0, 2, enc, &res);
574 VP8Encoder* const enc = it->enc_;
579 InitResidual(0, 1, enc, &res);
585 InitResidual(1, 0, enc, &res);
587 InitResidual(0, 3, enc, &res);
603 InitResidual(0, 2, enc, &res);
634 static void ResetSSE(VP8Encoder* const enc) {
635 enc->sse_[0] = 0;
636 enc->sse_[1] = 0;
637 enc->sse_[2] = 0;
638 // Note: enc->sse_[3] is managed by alpha.c
639 enc->sse_count_ = 0;
643 VP8Encoder* const enc = it->enc_;
647 enc->sse_[0] += VP8SSE16x16(in + Y_OFF, out + Y_OFF);
648 enc->sse_[1] += VP8SSE8x8(in + U_OFF, out + U_OFF);
649 enc->sse_[2] += VP8SSE8x8(in + V_OFF, out + V_OFF);
650 enc->sse_count_ += 16 * 16;
654 VP8Encoder* const enc = it->enc_;
656 WebPPicture* const pic = enc->pic_;
660 enc->block_count_[0] += (mb->type_ == 0);
661 enc->block_count_[1] += (mb->type_ == 1);
662 enc->block_count_[2] += (mb->skip_ != 0);
666 uint8_t* const info = &pic->extra_info[it->x_ + it->y_ * enc->mb_w_];
670 case 3: *info = enc->dqm_[mb->segment_].quant_; break;
695 static void SetLoopParams(VP8Encoder* const enc, float q) {
703 VP8SetSegmentParams(enc, q); // setup segment quantizations and filters
704 SetSegmentProbas(enc); // compute segment probabilities
706 ResetStats(enc);
707 ResetTokenStats(enc);
709 ResetSSE(enc);
712 static int OneStatPass(VP8Encoder* const enc, float q, VP8RDLevel rd_opt,
719 SetLoopParams(enc, q);
721 VP8IteratorInit(enc, &it);
727 enc->proba_.nb_skip_++;
735 size += FinalizeSkipProba(enc);
736 size += FinalizeTokenProbas(&enc->proba_);
737 size += enc->segment_hdr_.size_;
749 static int StatLoop(VP8Encoder* const enc) {
750 const int method = enc->method_;
751 const int do_search = enc->do_search_;
753 float q = enc->config_->quality;
754 const int max_passes = enc->config_->pass;
757 const int final_percent = enc->percent_ + task_percent;
762 nb_mbs = enc->mb_w_ * enc->mb_h_;
775 if (!OneStatPass(enc, q, rd_opt, nb_mbs, NULL, percent_per_pass)) {
784 const int size = OneStatPass(enc, q, RD_OPT_BASIC, nb_mbs, &PSNR,
790 if (enc->config_->target_PSNR > 0) {
791 criterion = (PSNR < enc->config_->target_PSNR);
793 criterion = (size < enc->config_->target_size);
803 VP8CalculateLevelCosts(&enc->proba_); // finalize costs
804 return WebPReportProgress(enc->pic_, final_percent, &enc->percent_);
813 static int PreLoopInitialize(VP8Encoder* const enc) {
816 const int average_bytes_per_MB = kAverageBytesPerMB[enc->base_quant_ >> 4];
818 enc->mb_w_ * enc->mb_h_ * average_bytes_per_MB / enc->num_parts_;
820 for (p = 0; ok && p < enc->num_parts_; ++p) {
821 ok = VP8BitWriterInit(enc->parts_ + p, bytes_per_parts);
823 if (!ok) VP8EncFreeBitWriters(enc); // malloc error occurred
828 VP8Encoder* const enc = it->enc_;
831 for (p = 0; p < enc->num_parts_; ++p) {
832 VP8BitWriterFinish(enc->parts_ + p);
833 ok &= !enc->parts_[p].error_;
838 if (enc->pic_->stats) { // finalize byte counters...
842 enc->residual_bytes_[i][s] = (int)((it->bit_count_[s][i] + 7) >> 3);
849 VP8EncFreeBitWriters(enc);
866 int VP8EncLoop(VP8Encoder* const enc) {
868 int ok = PreLoopInitialize(enc);
871 StatLoop(enc); // stats-collection loop
873 VP8IteratorInit(enc, &it);
877 const int dont_use_skip = !enc->proba_.use_skip_proba_;
878 const VP8RDLevel rd_opt = enc->rd_opt_level_;
889 if (enc->use_layer_) {
909 int VP8EncTokenLoop(VP8Encoder* const enc) {
912 int max_count = (enc->mb_w_ * enc->mb_h_) >> 3;
915 VP8Proba* const proba = &enc->proba_;
916 const VP8RDLevel rd_opt = enc->rd_opt_level_;
921 assert(enc->num_parts_ == 1);
922 assert(enc->use_tokens_);
925 assert(!enc->do_search_); // TODO(skal): handle pass and dichotomy
927 SetLoopParams(enc, enc->config_->quality);
929 ok = PreLoopInitialize(enc);
932 VP8IteratorInit(enc, &it);
943 RecordTokens(&it, &info, &enc->tokens_);
945 if (enc->use_layer_) {
955 ok = ok && WebPReportProgress(enc->pic_, enc->percent_ + 20, &enc->percent_);
959 ok = VP8EmitTokens(&enc->tokens_, enc->parts_ + 0,
968 int VP8EncTokenLoop(VP8Encoder* const enc) {
969 (void)enc;