Lines Matching refs:dec

79                              VP8LDecoder* const dec,
171 VP8LDecoder* const dec, const int* const code_length_code_lengths,
174 VP8LBitReader* const br = &dec->br_;
182 dec->status_ = VP8_STATUS_BITSTREAM_ERROR;
190 dec->status_ = VP8_STATUS_BITSTREAM_ERROR;
213 dec->status_ = VP8_STATUS_BITSTREAM_ERROR;
228 static int ReadHuffmanCode(int alphabet_size, VP8LDecoder* const dec,
231 VP8LBitReader* const br = &dec->br_;
258 dec->status_ = VP8_STATUS_BITSTREAM_ERROR;
265 dec->status_ = VP8_STATUS_OUT_OF_MEMORY;
272 ok = ReadHuffmanCodeLengths(dec, code_length_code_lengths, alphabet_size,
281 dec->status_ = VP8_STATUS_BITSTREAM_ERROR;
300 static int ReadHuffmanCodes(VP8LDecoder* const dec, int xsize, int ysize,
303 VP8LBitReader* const br = &dec->br_;
304 VP8LMetadata* const hdr = &dec->hdr_;
315 if (!DecodeImageStream(huffman_xsize, huffman_ysize, 0, dec,
317 dec->status_ = VP8_STATUS_BITSTREAM_ERROR;
338 dec->status_ = VP8_STATUS_OUT_OF_MEMORY;
349 if (!ReadHuffmanCode(alphabet_size, dec, htrees + j)) goto Error;
368 static int AllocateAndInitRescaler(VP8LDecoder* const dec, VP8Io* const io) {
378 const uint64_t memory_size = sizeof(*dec->rescaler) +
383 dec->status_ = VP8_STATUS_OUT_OF_MEMORY;
386 assert(dec->rescaler_memory == NULL);
387 dec->rescaler_memory = memory;
389 dec->rescaler = (WebPRescaler*)memory;
390 memory += sizeof(*dec->rescaler);
395 WebPRescalerInit(dec->rescaler, in_width, in_height, (uint8_t*)scaled_data,
420 static int EmitRescaledRows(const VP8LDecoder* const dec,
423 const WEBP_CSP_MODE colorspace = dec->output_->colorspace;
430 num_lines_in += WebPRescalerImport(dec->rescaler, mb_h - num_lines_in,
432 num_lines_out += Export(dec->rescaler, colorspace, out_stride, row_out);
518 static int ExportYUVA(const VP8LDecoder* const dec, int y_pos) {
519 WebPRescaler* const rescaler = dec->rescaler;
525 ConvertToYUVA(src, dst_width, y_pos, dec->output_);
532 static int EmitRescaledRowsYUVA(const VP8LDecoder* const dec,
537 int y_pos = dec->last_out_row_;
540 num_lines_in += WebPRescalerImport(dec->rescaler, mb_h - num_lines_in,
542 y_pos += ExportYUVA(dec, y_pos);
547 static int EmitRowsYUVA(const VP8LDecoder* const dec,
550 int y_pos = dec->last_out_row_;
553 ConvertToYUVA((const uint32_t*)row_in, mb_w, y_pos, dec->output_);
609 typedef void (*ProcessRowsFunc)(VP8LDecoder* const dec, int row);
611 static void ApplyInverseTransforms(VP8LDecoder* const dec, int num_rows,
613 int n = dec->next_transform_;
614 const int cache_pixs = dec->width_ * num_rows;
615 const int start_row = dec->last_row_;
618 uint32_t* const rows_out = dec->argb_cache_;
624 VP8LTransform* const transform = &dec->transforms_[n];
631 static void ApplyInverseTransformsAlpha(VP8LDecoder* const dec, int num_rows,
633 const int start_row = dec->last_row_;
636 uint8_t* rows_out = (uint8_t*)dec->io_->opaque + dec->io_->width * start_row;
637 VP8LTransform* const transform = &dec->transforms_[0];
638 assert(dec->next_transform_ == 1);
646 static void ProcessRows(VP8LDecoder* const dec, int row) {
647 const uint32_t* const rows = dec->pixels_ + dec->width_ * dec->last_row_;
648 const int num_rows = row - dec->last_row_;
651 ApplyInverseTransforms(dec, num_rows, rows);
655 VP8Io* const io = dec->io_;
656 const uint32_t* rows_data = dec->argb_cache_;
657 if (!SetCropWindow(io, dec->last_row_, row, &rows_data, io->width)) {
660 const WebPDecBuffer* const output = dec->output_;
664 uint8_t* const rgba = buf->rgba + dec->last_out_row_ * buf->stride;
666 EmitRescaledRows(dec, rows_data, in_stride, io->mb_h,
671 dec->last_out_row_ += num_rows_out;
673 dec->last_out_row_ = io->use_scaling ?
674 EmitRescaledRowsYUVA(dec, rows_data, in_stride, io->mb_h) :
675 EmitRowsYUVA(dec, rows_data, in_stride, io->mb_w, io->mb_h);
677 assert(dec->last_out_row_ <= output->height);
682 dec->last_row_ = row;
683 assert(dec->last_row_ <= dec->height_);
687 static int FUNC_NAME(VP8LDecoder* const dec, TYPE* const data, int width, \
691 VP8LBitReader* const br = &dec->br_; \
692 VP8LMetadata* const hdr = &dec->hdr_; \
728 process_func(dec, row); \
758 process_func(dec, row); \
785 if (process_func != NULL) process_func(dec, row); \
789 dec->status_ = \
792 dec->state_ = READ_DATA; \
850 VP8LDecoder* const dec) {
852 VP8LBitReader* const br = &dec->br_;
853 VP8LTransform* transform = &dec->transforms_[dec->next_transform_];
858 if (dec->transforms_seen_ & (1U << type)) {
861 dec->transforms_seen_ |= (1U << type);
867 ++dec->next_transform_;
868 assert(dec->next_transform_ <= NUM_TRANSFORMS);
878 0, dec, &transform->data_);
888 ok = DecodeImageStream(num_colors, 1, 0, dec, &transform->data_);
923 VP8LDecoder* const dec = (VP8LDecoder*)calloc(1, sizeof(*dec));
924 if (dec == NULL) return NULL;
925 dec->status_ = VP8_STATUS_OK;
926 dec->action_ = READ_DIM;
927 dec->state_ = READ_DIM;
928 return dec;
931 void VP8LClear(VP8LDecoder* const dec) {
933 if (dec == NULL) return;
934 ClearMetadata(&dec->hdr_);
936 free(dec->pixels_);
937 dec->pixels_ = NULL;
938 for (i = 0; i < dec->next_transform_; ++i) {
939 ClearTransform(&dec->transforms_[i]);
941 dec->next_transform_ = 0;
942 dec->transforms_seen_ = 0;
944 free(dec->rescaler_memory);
945 dec->rescaler_memory = NULL;
947 dec->output_ = NULL; // leave no trace behind
950 void VP8LDelete(VP8LDecoder* const dec) {
951 if (dec != NULL) {
952 VP8LClear(dec);
953 free(dec);
957 static void UpdateDecoder(VP8LDecoder* const dec, int width, int height) {
958 VP8LMetadata* const hdr = &dec->hdr_;
960 dec->width_ = width;
961 dec->height_ = height;
969 VP8LDecoder* const dec,
974 VP8LBitReader* const br = &dec->br_;
975 VP8LMetadata* const hdr = &dec->hdr_;
982 ok = ReadTransform(&transform_xsize, &transform_ysize, dec);
991 dec->status_ = VP8_STATUS_BITSTREAM_ERROR;
997 ok = ok && ReadHuffmanCodes(dec, transform_xsize, transform_ysize,
1000 dec->status_ = VP8_STATUS_BITSTREAM_ERROR;
1008 dec->status_ = VP8_STATUS_OUT_OF_MEMORY;
1015 UpdateDecoder(dec, transform_xsize, transform_ysize);
1018 dec->state_ = READ_HDR;
1026 dec->status_ = VP8_STATUS_OUT_OF_MEMORY;
1033 ok = DecodeImageData(dec, data, transform_xsize, transform_ysize, NULL);
1043 if (dec->status_ == VP8_STATUS_BITSTREAM_ERROR && dec->br_.eos_) {
1044 dec->status_ = VP8_STATUS_SUSPENDED;
1061 // Allocate internal buffers dec->pixels_ and dec->argb_cache_.
1062 static int AllocateInternalBuffers(VP8LDecoder* const dec, int final_width,
1065 const uint64_t num_pixels = (uint64_t)dec->width_ * dec->height_;
1076 assert(dec->width_ <= final_width);
1077 dec->pixels_ = (uint32_t*)WebPSafeMalloc(total_num_pixels, bytes_per_pixel);
1078 if (dec->pixels_ == NULL) {
1079 dec->argb_cache_ = NULL; // for sanity check
1080 dec->status_ = VP8_STATUS_OUT_OF_MEMORY;
1083 dec->argb_cache_ =
1084 argb_cache_needed ? dec->pixels_ + num_pixels + cache_top_pixels : NULL;
1091 static void ExtractAlphaRows(VP8LDecoder* const dec, int row) {
1092 const int num_rows = row - dec->last_row_;
1093 const uint32_t* const in = dec->pixels_ + dec->width_ * dec->last_row_;
1096 ApplyInverseTransforms(dec, num_rows, in);
1100 const int width = dec->io_->width; // the final width (!= dec->width_)
1102 uint8_t* const dst = (uint8_t*)dec->io_->opaque + width * dec->last_row_;
1103 const uint32_t* const src = dec->argb_cache_;
1107 dec->last_row_ = dec->last_out_row_ = row;
1112 static void ExtractPalettedAlphaRows(VP8LDecoder* const dec, int row) {
1113 const int num_rows = row - dec->last_row_;
1115 (uint8_t*)dec->pixels_ + dec->width_ * dec->last_row_;
1117 ApplyInverseTransformsAlpha(dec, num_rows, in);
1118 dec->last_row_ = dec->last_out_row_ = row;
1125 VP8LDecoder* const dec = VP8LNew();
1127 if (dec == NULL) return 0;
1129 dec->width_ = width;
1130 dec->height_ = height;
1131 dec->io_ = &io;
1139 dec->status_ = VP8_STATUS_OK;
1140 VP8LInitBitReader(&dec->br_, data, data_size);
1142 dec->action_ = READ_HDR;
1143 if (!DecodeImageStream(width, height, 1, dec, NULL)) goto Err;
1148 if (dec->next_transform_ == 1 &&
1149 dec->transforms_[0].type_ == COLOR_INDEXING_TRANSFORM &&
1150 dec->hdr_.color_cache_size_ == 0) {
1154 // Allocate internal buffers (note that dec->width_ may have changed here).
1155 if (!AllocateInternalBuffers(dec, width, bytes_per_pixel)) goto Err;
1158 dec->action_ = READ_DATA;
1160 DecodeAlphaData(dec, (uint8_t*)dec->pixels_, dec->width_, dec->height_,
1162 DecodeImageData(dec, dec->pixels_, dec->width_, dec->height_,
1166 VP8LDelete(dec);
1172 int VP8LDecodeHeader(VP8LDecoder* const dec, VP8Io* const io) {
1175 if (dec == NULL) return 0;
1177 dec->status_ = VP8_STATUS_INVALID_PARAM;
1181 dec->io_ = io;
1182 dec->status_ = VP8_STATUS_OK;
1183 VP8LInitBitReader(&dec->br_, io->data, io->data_size);
1184 if (!ReadImageInfo(&dec->br_, &width, &height, &has_alpha)) {
1185 dec->status_ = VP8_STATUS_BITSTREAM_ERROR;
1188 dec->state_ = READ_DIM;
1192 dec->action_ = READ_HDR;
1193 if (!DecodeImageStream(width, height, 1, dec, NULL)) goto Error;
1197 VP8LClear(dec);
1198 assert(dec->status_ != VP8_STATUS_OK);
1202 int VP8LDecodeImage(VP8LDecoder* const dec) {
1208 if (dec == NULL) return 0;
1210 io = dec->io_;
1214 dec->output_ = params->output;
1215 assert(dec->output_ != NULL);
1219 dec->status_ = VP8_STATUS_INVALID_PARAM;
1223 if (!AllocateInternalBuffers(dec, io->width, bytes_per_pixel)) goto Err;
1225 if (io->use_scaling && !AllocateAndInitRescaler(dec, io)) goto Err;
1228 dec->action_ = READ_DATA;
1229 if (!DecodeImageData(dec, dec->pixels_, dec->width_, dec->height_,
1235 params->last_y = dec->last_out_row_;
1236 VP8LClear(dec);
1240 VP8LClear(dec);
1241 assert(dec->status_ != VP8_STATUS_OK);