Home | History | Annotate | Download | only in dec

Lines Matching refs:idec

95 static int NeedCompressedAlpha(const WebPIDecoder* const idec) {
96 if (idec->state_ == STATE_WEBP_HEADER) {
101 if (idec->is_lossless_) {
104 const VP8Decoder* const dec = (VP8Decoder*)idec->dec_;
105 assert(dec != NULL); // Must be true as idec->state_ != STATE_WEBP_HEADER.
110 static void DoRemap(WebPIDecoder* const idec, ptrdiff_t offset) {
111 MemBuffer* const mem = &idec->mem_;
113 // note: for VP8, setting up idec->io_ is only really needed at the beginning
115 idec->io_.data = new_base;
116 idec->io_.data_size = MemDataSize(mem);
118 if (idec->dec_ != NULL) {
119 if (!idec->is_lossless_) {
120 VP8Decoder* const dec = (VP8Decoder*)idec->dec_;
135 if (NeedCompressedAlpha(idec)) {
152 VP8LDecoder* const dec = (VP8LDecoder*)idec->dec_;
160 static int AppendToMemBuffer(WebPIDecoder* const idec,
162 VP8Decoder* const dec = (VP8Decoder*)idec->dec_;
163 MemBuffer* const mem = &idec->mem_;
164 const int need_compressed_alpha = NeedCompressedAlpha(idec);
195 DoRemap(idec, mem->buf_ + mem->start_ - old_start);
199 static int RemapMemBuffer(WebPIDecoder* const idec,
201 MemBuffer* const mem = &idec->mem_;
211 DoRemap(idec, mem->buf_ + mem->start_ - old_start);
242 static VP8StatusCode FinishDecoding(WebPIDecoder* const idec) {
244 const WebPDecoderOptions* const options = idec->params_.options;
245 WebPDecBuffer* const output = idec->params_.output;
247 idec->state_ = STATE_DONE;
252 idec->state_ = STATE_DONE;
275 static VP8StatusCode IDecError(WebPIDecoder* const idec, VP8StatusCode error) {
276 if (idec->state_ == STATE_VP8_DATA) {
277 VP8Io* const io = &idec->io_;
282 idec->state_ = STATE_ERROR;
286 static void ChangeState(WebPIDecoder* const idec, DecState new_state,
288 MemBuffer* const mem = &idec->mem_;
289 idec->state_ = new_state;
292 idec->io_.data = mem->buf_ + mem->start_;
293 idec->io_.data_size = MemDataSize(mem);
297 static VP8StatusCode DecodeWebPHeaders(WebPIDecoder* const idec) {
298 MemBuffer* const mem = &idec->mem_;
311 return IDecError(idec, status);
314 idec->chunk_size_ = headers.compressed_size;
315 idec->is_lossless_ = headers.is_lossless;
316 if (!idec->is_lossless_) {
321 idec->dec_ = dec;
324 ChangeState(idec, STATE_VP8_HEADER, headers.offset);
330 idec->dec_ = dec;
331 ChangeState(idec, STATE_VP8L_HEADER, headers.offset);
336 static VP8StatusCode DecodeVP8FrameHeader(WebPIDecoder* const idec) {
337 const uint8_t* data = idec->mem_.buf_ + idec->mem_.start_;
338 const size_t curr_size = MemDataSize(&idec->mem_);
346 if (!VP8GetInfo(data, curr_size, idec->chunk_size_, &width, &height)) {
347 return IDecError(idec, VP8_STATUS_BITSTREAM_ERROR);
351 idec->mem_.part0_size_ = (bits >> 5) + VP8_FRAME_HEADER_SIZE;
353 idec->io_.data = data;
354 idec->io_.data_size = curr_size;
355 idec->state_ = STATE_VP8_PARTS0;
360 static int CopyParts0Data(WebPIDecoder* const idec) {
361 VP8Decoder* const dec = (VP8Decoder*)idec->dec_;
364 MemBuffer* const mem = &idec->mem_;
365 assert(!idec->is_lossless_);
386 static VP8StatusCode DecodePartition0(WebPIDecoder* const idec) {
387 VP8Decoder* const dec = (VP8Decoder*)idec->dec_;
388 VP8Io* const io = &idec->io_;
389 const WebPDecParams* const params = &idec->params_;
393 if (MemDataSize(&idec->mem_) < idec->mem_.part0_size_) {
404 return IDecError(idec, status);
411 return IDecError(idec, dec->status_);
417 if (!CopyParts0Data(idec)) {
418 return IDecError(idec, VP8_STATUS_OUT_OF_MEMORY);
423 return IDecError(idec, dec->status_);
428 idec->state_ = STATE_VP8_DATA;
431 return IDecError(idec, dec->status_);
437 static VP8StatusCode DecodeRemaining(WebPIDecoder* const idec) {
438 VP8Decoder* const dec = (VP8Decoder*)idec->dec_;
439 VP8Io* const io = &idec->io_;
443 if (idec->last_mb_y_ != dec->mb_y_) {
448 return IDecError(idec, VP8_STATUS_BITSTREAM_ERROR);
450 idec->last_mb_y_ = dec->mb_y_;
459 if (dec->num_parts_ == 1 && MemDataSize(&idec->mem_) > MAX_MB_SIZE) {
460 return IDecError(idec, VP8_STATUS_BITSTREAM_ERROR);
467 idec->mem_.start_ = token_br->buf_ - idec->mem_.buf_;
468 assert(idec->mem_.start_ <= idec
475 return IDecError(idec, VP8_STATUS_USER_ABORT);
480 return IDecError(idec, VP8_STATUS_USER_ABORT);
483 return FinishDecoding(idec);
486 static VP8StatusCode ErrorStatusLossless(WebPIDecoder* const idec,
491 return IDecError(idec, status);
494 static VP8StatusCode DecodeVP8LHeader(WebPIDecoder* const idec) {
495 VP8Io* const io = &idec->io_;
496 VP8LDecoder* const dec = (VP8LDecoder*)idec->dec_;
497 const WebPDecParams* const params = &idec->params_;
499 size_t curr_size = MemDataSize(&idec->mem_);
500 assert(idec->is_lossless_);
503 if (curr_size < (idec->chunk_size_ >> 3)) {
507 return ErrorStatusLossless(idec, dec->status_);
513 return IDecError(idec, dec->status_);
516 idec->state_ = STATE_VP8L_DATA;
520 static VP8StatusCode DecodeVP8LData(WebPIDecoder* const idec) {
521 VP8LDecoder* const dec = (VP8LDecoder*)idec->dec_;
522 const size_t curr_size = MemDataSize(&idec->mem_);
523 assert(idec->is_lossless_);
527 if (curr_size < idec->chunk_size_) {
532 return ErrorStatusLossless(idec, dec->status_);
535 return FinishDecoding(idec);
539 static VP8StatusCode IDecode(WebPIDecoder* idec) {
542 if (idec->state_ == STATE_WEBP_HEADER) {
543 status = DecodeWebPHeaders(idec);
545 if (idec->dec_ == NULL) {
549 if (idec->state_ == STATE_VP8_HEADER) {
550 status = DecodeVP8FrameHeader(idec);
552 if (idec->state_ == STATE_VP8_PARTS0) {
553 status = DecodePartition0(idec);
555 if (idec->state_ == STATE_VP8_DATA) {
556 status = DecodeRemaining(idec);
558 if (idec->state_ == STATE_VP8L_HEADER) {
559 status = DecodeVP8LHeader(idec);
561 if (idec->state_ == STATE_VP8L_DATA) {
562 status = DecodeVP8LData(idec);
571 WebPIDecoder* idec = (WebPIDecoder*)WebPSafeCalloc(1ULL, sizeof(*idec));
572 if (idec == NULL) {
576 idec->state_ = STATE_WEBP_HEADER;
577 idec->chunk_size_ = 0;
579 idec->last_mb_y_ = -1;
581 InitMemBuffer(&idec->mem_);
582 WebPInitDecBuffer(&idec->output_);
583 VP8InitIo(&idec->io_);
585 WebPResetDecParams(&idec->params_);
586 idec->params_.output = (output_buffer != NULL) ? output_buffer
587 : &idec->output_;
588 WebPInitCustomIo(&idec->params_, &idec->io_); // Plug the I/O functions.
590 return idec;
595 WebPIDecoder* idec;
604 idec = WebPINewDecoder(config ? &config->output : NULL);
605 if (idec == NULL) {
610 idec->params_.options = &config->options;
612 return idec;
615 void WebPIDelete(WebPIDecoder* idec) {
616 if (idec == NULL) return;
617 if (idec->dec_ != NULL) {
618 if (!idec->is_lossless_) {
619 if (idec->state_ == STATE_VP8_DATA) {
621 VP8ExitCritical((VP8Decoder*)idec->dec_, &idec->io_);
623 VP8Delete((VP8Decoder*)idec->dec_);
625 VP8LDelete((VP8LDecoder*)idec->dec_);
628 ClearMemBuffer(&idec->mem_);
629 WebPFreeDecBuffer(&idec->output_);
630 WebPSafeFree(idec);
639 WebPIDecoder* idec;
650 idec = WebPINewDecoder(NULL);
651 if (idec == NULL) return NULL;
652 idec->output_.colorspace = mode;
653 idec->output_.is_external_memory = is_external_memory;
654 idec->output_.u.RGBA.rgba = output_buffer;
655 idec->output_.u.RGBA.stride = output_stride;
656 idec->output_.u.RGBA.size = output_buffer_size;
657 return idec;
665 WebPIDecoder* idec;
683 idec = WebPINewDecoder(NULL);
684 if (idec == NULL) return NULL;
686 idec->output_.colorspace = colorspace;
687 idec->output_.is_external_memory = is_external_memory;
688 idec->output_.u.YUVA.y = luma;
689 idec->output_.u.YUVA.y_stride = luma_stride;
690 idec->output_.u.YUVA.y_size = luma_size;
691 idec->output_.u.YUVA.u = u;
692 idec->output_.u.YUVA.u_stride = u_stride;
693 idec->output_.u.YUVA.u_size = u_size;
694 idec->output_.u.YUVA.v = v;
695 idec->output_.u.YUVA.v_stride = v_stride;
696 idec->output_.u.YUVA.v_size = v_size;
697 idec->output_.u.YUVA.a = a;
698 idec->output_.u.YUVA.a_stride = a_stride;
699 idec->output_.u.YUVA.a_size = a_size;
700 return idec;
714 static VP8StatusCode IDecCheckStatus(const WebPIDecoder* const idec) {
715 assert(idec);
716 if (idec->state_ == STATE_ERROR) {
719 if (idec->state_ == STATE_DONE) {
725 VP8StatusCode WebPIAppend(WebPIDecoder* idec,
728 if (idec == NULL || data == NULL) {
731 status = IDecCheckStatus(idec);
736 if (!CheckMemBufferMode(&idec->mem_, MEM_MODE_APPEND)) {
740 if (!AppendToMemBuffer(idec, data, data_size)) {
743 return IDecode(idec);
746 VP8StatusCode WebPIUpdate(WebPIDecoder* idec,
749 if (idec == NULL || data == NULL) {
752 status = IDecCheckStatus(idec);
757 if (!CheckMemBufferMode(&idec->mem_, MEM_MODE_MAP)) {
761 if (!RemapMemBuffer(idec, data, data_size)) {
764 return IDecode(idec);
769 static const WebPDecBuffer* GetOutputBuffer(const WebPIDecoder* const idec) {
770 if (idec == NULL || idec->dec_ == NULL) {
773 if (idec->state_ <= STATE_VP8_PARTS0) {
776 return idec->params_.output;
779 const WebPDecBuffer* WebPIDecodedArea(const WebPIDecoder* idec,
782 const WebPDecBuffer* const src = GetOutputBuffer(idec);
788 if (height != NULL) *height = idec->params_.last_y;
796 uint8_t* WebPIDecGetRGB(const WebPIDecoder* idec, int* last_y,
798 const WebPDecBuffer* const src = GetOutputBuffer(idec);
804 if (last_y != NULL) *last_y = idec->params_.last_y;
812 uint8_t* WebPIDecGetYUVA(const WebPIDecoder* idec, int* last_y,
816 const WebPDecBuffer* const src = GetOutputBuffer(idec);
822 if (last_y != NULL) *last_y = idec->params_.last_y;
835 int WebPISetIOHooks(WebPIDecoder* const idec,
840 if (idec == NULL || idec->state_ > STATE_WEBP_HEADER) {
844 idec->io_.put = put;
845 idec->io_.setup = setup;
846 idec->io_.teardown = teardown;
847 idec->io_.opaque = user_data;