Lines Matching refs:dec
71 static void ReconstructRow(const VP8Decoder* const dec, in ReconstructRow() argument
77 uint8_t* const y_dst = dec->yuv_b_ + Y_OFF; in ReconstructRow()
78 uint8_t* const u_dst = dec->yuv_b_ + U_OFF; in ReconstructRow()
79 uint8_t* const v_dst = dec->yuv_b_ + V_OFF; in ReconstructRow()
102 for (mb_x = 0; mb_x < dec->mb_w_; ++mb_x) { in ReconstructRow()
118 VP8TopSamples* const top_yuv = dec->yuv_t_ + mb_x; in ReconstructRow()
134 if (mb_x >= dec->mb_w_ - 1) { // on rightmost border in ReconstructRow()
169 if (mb_y < dec->mb_h_ - 1) { in ReconstructRow()
177 const int y_offset = cache_id * 16 * dec->cache_y_stride_; in ReconstructRow()
178 const int uv_offset = cache_id * 8 * dec->cache_uv_stride_; in ReconstructRow()
179 uint8_t* const y_out = dec->cache_y_ + mb_x * 16 + y_offset; in ReconstructRow()
180 uint8_t* const u_out = dec->cache_u_ + mb_x * 8 + uv_offset; in ReconstructRow()
181 uint8_t* const v_out = dec->cache_v_ + mb_x * 8 + uv_offset; in ReconstructRow()
183 memcpy(y_out + j * dec->cache_y_stride_, y_dst + j * BPS, 16); in ReconstructRow()
186 memcpy(u_out + j * dec->cache_uv_stride_, u_dst + j * BPS, 8); in ReconstructRow()
187 memcpy(v_out + j * dec->cache_uv_stride_, v_dst + j * BPS, 8); in ReconstructRow()
203 static void DoFilter(const VP8Decoder* const dec, int mb_x, int mb_y) { in DoFilter() argument
204 const VP8ThreadContext* const ctx = &dec->thread_ctx_; in DoFilter()
206 const int y_bps = dec->cache_y_stride_; in DoFilter()
208 uint8_t* const y_dst = dec->cache_y_ + cache_id * 16 * y_bps + mb_x * 16; in DoFilter()
215 if (dec->filter_type_ == 1) { // simple in DoFilter()
229 const int uv_bps = dec->cache_uv_stride_; in DoFilter()
230 uint8_t* const u_dst = dec->cache_u_ + cache_id * 8 * uv_bps + mb_x * 8; in DoFilter()
231 uint8_t* const v_dst = dec->cache_v_ + cache_id * 8 * uv_bps + mb_x * 8; in DoFilter()
253 static void FilterRow(const VP8Decoder* const dec) { in FilterRow() argument
255 const int mb_y = dec->thread_ctx_.mb_y_; in FilterRow()
256 assert(dec->thread_ctx_.filter_row_); in FilterRow()
257 for (mb_x = dec->tl_mb_x_; mb_x < dec->br_mb_x_; ++mb_x) { in FilterRow()
258 DoFilter(dec, mb_x, mb_y); in FilterRow()
265 static void PrecomputeFilterStrengths(VP8Decoder* const dec) { in PrecomputeFilterStrengths() argument
266 if (dec->filter_type_ > 0) { in PrecomputeFilterStrengths()
268 const VP8FilterHeader* const hdr = &dec->filter_hdr_; in PrecomputeFilterStrengths()
273 if (dec->segment_hdr_.use_segment_) { in PrecomputeFilterStrengths()
274 base_level = dec->segment_hdr_.filter_strength_[s]; in PrecomputeFilterStrengths()
275 if (!dec->segment_hdr_.absolute_delta_) { in PrecomputeFilterStrengths()
282 VP8FInfo* const info = &dec->fstrengths_[s][i4x4]; in PrecomputeFilterStrengths()
329 VP8Decoder* const dec) { in VP8InitDithering() argument
330 assert(dec != NULL); in VP8InitDithering()
339 VP8QuantMatrix* const dqm = &dec->dqm_[s]; in VP8InitDithering()
347 VP8InitRandom(&dec->dithering_rg_, 1.0f); in VP8InitDithering()
348 dec->dither_ = 1; in VP8InitDithering()
352 dec->alpha_dithering_ = options->alpha_dithering_strength; in VP8InitDithering()
353 if (dec->alpha_dithering_ > 100) { in VP8InitDithering()
354 dec->alpha_dithering_ = 100; in VP8InitDithering()
355 } else if (dec->alpha_dithering_ < 0) { in VP8InitDithering()
356 dec->alpha_dithering_ = 0; in VP8InitDithering()
371 static void DitherRow(VP8Decoder* const dec) { in DitherRow() argument
373 assert(dec->dither_); in DitherRow()
374 for (mb_x = dec->tl_mb_x_; mb_x < dec->br_mb_x_; ++mb_x) { in DitherRow()
375 const VP8ThreadContext* const ctx = &dec->thread_ctx_; in DitherRow()
378 const int uv_bps = dec->cache_uv_stride_; in DitherRow()
380 uint8_t* const u_dst = dec->cache_u_ + cache_id * 8 * uv_bps + mb_x * 8; in DitherRow()
381 uint8_t* const v_dst = dec->cache_v_ + cache_id * 8 * uv_bps + mb_x * 8; in DitherRow()
382 Dither8x8(&dec->dithering_rg_, u_dst, uv_bps, data->dither_); in DitherRow()
383 Dither8x8(&dec->dithering_rg_, v_dst, uv_bps, data->dither_); in DitherRow()
403 VP8Decoder* const dec = (VP8Decoder*)arg1; in FinishRow() local
406 const VP8ThreadContext* const ctx = &dec->thread_ctx_; in FinishRow()
408 const int extra_y_rows = kFilterExtraRows[dec->filter_type_]; in FinishRow()
409 const int ysize = extra_y_rows * dec->cache_y_stride_; in FinishRow()
410 const int uvsize = (extra_y_rows / 2) * dec->cache_uv_stride_; in FinishRow()
411 const int y_offset = cache_id * 16 * dec->cache_y_stride_; in FinishRow()
412 const int uv_offset = cache_id * 8 * dec->cache_uv_stride_; in FinishRow()
413 uint8_t* const ydst = dec->cache_y_ - ysize + y_offset; in FinishRow()
414 uint8_t* const udst = dec->cache_u_ - uvsize + uv_offset; in FinishRow()
415 uint8_t* const vdst = dec->cache_v_ - uvsize + uv_offset; in FinishRow()
418 const int is_last_row = (mb_y >= dec->br_mb_y_ - 1); in FinishRow()
420 if (dec->mt_method_ == 2) { in FinishRow()
421 ReconstructRow(dec, ctx); in FinishRow()
425 FilterRow(dec); in FinishRow()
428 if (dec->dither_) { in FinishRow()
429 DitherRow(dec); in FinishRow()
441 io->y = dec->cache_y_ + y_offset; in FinishRow()
442 io->u = dec->cache_u_ + uv_offset; in FinishRow()
443 io->v = dec->cache_v_ + uv_offset; in FinishRow()
454 if (dec->alpha_data_ != NULL && y_start < y_end) { in FinishRow()
455 io->a = VP8DecompressAlphaRows(dec, io, y_start, y_end - y_start); in FinishRow()
457 return VP8SetError(dec, VP8_STATUS_BITSTREAM_ERROR, in FinishRow()
465 io->y += dec->cache_y_stride_ * delta_y; in FinishRow()
466 io->u += dec->cache_uv_stride_ * (delta_y >> 1); in FinishRow()
467 io->v += dec->cache_uv_stride_ * (delta_y >> 1); in FinishRow()
486 if (cache_id + 1 == dec->num_caches_) { in FinishRow()
488 memcpy(dec->cache_y_ - ysize, ydst + 16 * dec->cache_y_stride_, ysize); in FinishRow()
489 memcpy(dec->cache_u_ - uvsize, udst + 8 * dec->cache_uv_stride_, uvsize); in FinishRow()
490 memcpy(dec->cache_v_ - uvsize, vdst + 8 * dec->cache_uv_stride_, uvsize); in FinishRow()
501 int VP8ProcessRow(VP8Decoder* const dec, VP8Io* const io) { in VP8ProcessRow() argument
503 VP8ThreadContext* const ctx = &dec->thread_ctx_; in VP8ProcessRow()
505 (dec->filter_type_ > 0) && in VP8ProcessRow()
506 (dec->mb_y_ >= dec->tl_mb_y_) && (dec->mb_y_ <= dec->br_mb_y_); in VP8ProcessRow()
507 if (dec->mt_method_ == 0) { in VP8ProcessRow()
509 ctx->mb_y_ = dec->mb_y_; in VP8ProcessRow()
511 ReconstructRow(dec, ctx); in VP8ProcessRow()
512 ok = FinishRow(dec, io); in VP8ProcessRow()
514 WebPWorker* const worker = &dec->worker_; in VP8ProcessRow()
520 ctx->id_ = dec->cache_id_; in VP8ProcessRow()
521 ctx->mb_y_ = dec->mb_y_; in VP8ProcessRow()
523 if (dec->mt_method_ == 2) { // swap macroblock data in VP8ProcessRow()
525 ctx->mb_data_ = dec->mb_data_; in VP8ProcessRow()
526 dec->mb_data_ = tmp; in VP8ProcessRow()
529 ReconstructRow(dec, ctx); in VP8ProcessRow()
533 ctx->f_info_ = dec->f_info_; in VP8ProcessRow()
534 dec->f_info_ = tmp; in VP8ProcessRow()
538 if (++dec->cache_id_ == dec->num_caches_) { in VP8ProcessRow()
539 dec->cache_id_ = 0; in VP8ProcessRow()
549 VP8StatusCode VP8EnterCritical(VP8Decoder* const dec, VP8Io* const io) { in VP8EnterCritical() argument
553 VP8SetError(dec, VP8_STATUS_USER_ABORT, "Frame setup failed"); in VP8EnterCritical()
554 return dec->status_; in VP8EnterCritical()
559 dec->filter_type_ = 0; in VP8EnterCritical()
572 const int extra_pixels = kFilterExtraRows[dec->filter_type_]; in VP8EnterCritical()
573 if (dec->filter_type_ == 2) { in VP8EnterCritical()
575 dec->tl_mb_x_ = 0; in VP8EnterCritical()
576 dec->tl_mb_y_ = 0; in VP8EnterCritical()
582 dec->tl_mb_x_ = (io->crop_left - extra_pixels) >> 4; in VP8EnterCritical()
583 dec->tl_mb_y_ = (io->crop_top - extra_pixels) >> 4; in VP8EnterCritical()
584 if (dec->tl_mb_x_ < 0) dec->tl_mb_x_ = 0; in VP8EnterCritical()
585 if (dec->tl_mb_y_ < 0) dec->tl_mb_y_ = 0; in VP8EnterCritical()
588 dec->br_mb_y_ = (io->crop_bottom + 15 + extra_pixels) >> 4; in VP8EnterCritical()
589 dec->br_mb_x_ = (io->crop_right + 15 + extra_pixels) >> 4; in VP8EnterCritical()
590 if (dec->br_mb_x_ > dec->mb_w_) { in VP8EnterCritical()
591 dec->br_mb_x_ = dec->mb_w_; in VP8EnterCritical()
593 if (dec->br_mb_y_ > dec->mb_h_) { in VP8EnterCritical()
594 dec->br_mb_y_ = dec->mb_h_; in VP8EnterCritical()
597 PrecomputeFilterStrengths(dec); in VP8EnterCritical()
601 int VP8ExitCritical(VP8Decoder* const dec, VP8Io* const io) { in VP8ExitCritical() argument
603 if (dec->mt_method_ > 0) { in VP8ExitCritical()
604 ok = WebPGetWorkerInterface()->Sync(&dec->worker_); in VP8ExitCritical()
641 static int InitThreadContext(VP8Decoder* const dec) { in InitThreadContext() argument
642 dec->cache_id_ = 0; in InitThreadContext()
643 if (dec->mt_method_ > 0) { in InitThreadContext()
644 WebPWorker* const worker = &dec->worker_; in InitThreadContext()
646 return VP8SetError(dec, VP8_STATUS_OUT_OF_MEMORY, in InitThreadContext()
649 worker->data1 = dec; in InitThreadContext()
650 worker->data2 = (void*)&dec->thread_ctx_.io_; in InitThreadContext()
652 dec->num_caches_ = in InitThreadContext()
653 (dec->filter_type_ > 0) ? MT_CACHE_LINES : MT_CACHE_LINES - 1; in InitThreadContext()
655 dec->num_caches_ = ST_CACHE_LINES; in InitThreadContext()
682 static int AllocateMemory(VP8Decoder* const dec) { in AllocateMemory() argument
683 const int num_caches = dec->num_caches_; in AllocateMemory()
684 const int mb_w = dec->mb_w_; in AllocateMemory()
690 (dec->filter_type_ > 0) ? in AllocateMemory()
691 mb_w * (dec->mt_method_ > 0 ? 2 : 1) * sizeof(VP8FInfo) in AllocateMemory()
693 const size_t yuv_size = YUV_SIZE * sizeof(*dec->yuv_b_); in AllocateMemory()
695 (dec->mt_method_ == 2 ? 2 : 1) * mb_w * sizeof(*dec->mb_data_); in AllocateMemory()
697 + kFilterExtraRows[dec->filter_type_]) * 3 / 2; in AllocateMemory()
700 const uint64_t alpha_size = (dec->alpha_data_ != NULL) ? in AllocateMemory()
701 (uint64_t)dec->pic_hdr_.width_ * dec->pic_hdr_.height_ : 0ULL; in AllocateMemory()
709 if (needed > dec->mem_size_) { in AllocateMemory()
710 WebPSafeFree(dec->mem_); in AllocateMemory()
711 dec->mem_size_ = 0; in AllocateMemory()
712 dec->mem_ = WebPSafeMalloc(needed, sizeof(uint8_t)); in AllocateMemory()
713 if (dec->mem_ == NULL) { in AllocateMemory()
714 return VP8SetError(dec, VP8_STATUS_OUT_OF_MEMORY, in AllocateMemory()
718 dec->mem_size_ = (size_t)needed; in AllocateMemory()
721 mem = (uint8_t*)dec->mem_; in AllocateMemory()
722 dec->intra_t_ = mem; in AllocateMemory()
725 dec->yuv_t_ = (VP8TopSamples*)mem; in AllocateMemory()
728 dec->mb_info_ = ((VP8MB*)mem) + 1; in AllocateMemory()
731 dec->f_info_ = f_info_size ? (VP8FInfo*)mem : NULL; in AllocateMemory()
733 dec->thread_ctx_.id_ = 0; in AllocateMemory()
734 dec->thread_ctx_.f_info_ = dec->f_info_; in AllocateMemory()
735 if (dec->mt_method_ > 0) { in AllocateMemory()
739 dec->thread_ctx_.f_info_ += mb_w; in AllocateMemory()
744 dec->yuv_b_ = mem; in AllocateMemory()
747 dec->mb_data_ = (VP8MBData*)mem; in AllocateMemory()
748 dec->thread_ctx_.mb_data_ = (VP8MBData*)mem; in AllocateMemory()
749 if (dec->mt_method_ == 2) { in AllocateMemory()
750 dec->thread_ctx_.mb_data_ += mb_w; in AllocateMemory()
754 dec->cache_y_stride_ = 16 * mb_w; in AllocateMemory()
755 dec->cache_uv_stride_ = 8 * mb_w; in AllocateMemory()
757 const int extra_rows = kFilterExtraRows[dec->filter_type_]; in AllocateMemory()
758 const int extra_y = extra_rows * dec->cache_y_stride_; in AllocateMemory()
759 const int extra_uv = (extra_rows / 2) * dec->cache_uv_stride_; in AllocateMemory()
760 dec->cache_y_ = mem + extra_y; in AllocateMemory()
761 dec->cache_u_ = dec->cache_y_ in AllocateMemory()
762 + 16 * num_caches * dec->cache_y_stride_ + extra_uv; in AllocateMemory()
763 dec->cache_v_ = dec->cache_u_ in AllocateMemory()
764 + 8 * num_caches * dec->cache_uv_stride_ + extra_uv; in AllocateMemory()
765 dec->cache_id_ = 0; in AllocateMemory()
770 dec->alpha_plane_ = alpha_size ? mem : NULL; in AllocateMemory()
772 assert(mem <= (uint8_t*)dec->mem_ + dec->mem_size_); in AllocateMemory()
775 memset(dec->mb_info_ - 1, 0, mb_info_size); in AllocateMemory()
776 VP8InitScanline(dec); // initialize left too. in AllocateMemory()
779 memset(dec->intra_t_, B_DC_PRED, intra_pred_mode_size); in AllocateMemory()
784 static void InitIo(VP8Decoder* const dec, VP8Io* io) { in InitIo() argument
787 io->y = dec->cache_y_; in InitIo()
788 io->u = dec->cache_u_; in InitIo()
789 io->v = dec->cache_v_; in InitIo()
790 io->y_stride = dec->cache_y_stride_; in InitIo()
791 io->uv_stride = dec->cache_uv_stride_; in InitIo()
795 int VP8InitFrame(VP8Decoder* const dec, VP8Io* const io) { in VP8InitFrame() argument
796 if (!InitThreadContext(dec)) return 0; // call first. Sets dec->num_caches_. in VP8InitFrame()
797 if (!AllocateMemory(dec)) return 0; in VP8InitFrame()
798 InitIo(dec, io); in VP8InitFrame()