Lines Matching refs:idec
104 static int NeedCompressedAlpha(const WebPIDecoder* const idec) { in NeedCompressedAlpha() argument
105 if (idec->state_ == STATE_PRE_VP8) { in NeedCompressedAlpha()
110 if (idec->is_lossless_) { in NeedCompressedAlpha()
113 const VP8Decoder* const dec = (VP8Decoder*)idec->dec_; in NeedCompressedAlpha()
119 static void DoRemap(WebPIDecoder* const idec, ptrdiff_t offset) { in DoRemap() argument
120 MemBuffer* const mem = &idec->mem_; in DoRemap()
124 idec->io_.data = new_base; in DoRemap()
125 idec->io_.data_size = MemDataSize(mem); in DoRemap()
127 if (idec->dec_ != NULL) { in DoRemap()
128 if (!idec->is_lossless_) { in DoRemap()
129 VP8Decoder* const dec = (VP8Decoder*)idec->dec_; in DoRemap()
144 if (NeedCompressedAlpha(idec)) dec->alpha_data_ += offset; in DoRemap()
146 VP8LDecoder* const dec = (VP8LDecoder*)idec->dec_; in DoRemap()
154 static int AppendToMemBuffer(WebPIDecoder* const idec, in AppendToMemBuffer() argument
156 VP8Decoder* const dec = (VP8Decoder*)idec->dec_; in AppendToMemBuffer()
157 MemBuffer* const mem = &idec->mem_; in AppendToMemBuffer()
158 const int need_compressed_alpha = NeedCompressedAlpha(idec); in AppendToMemBuffer()
189 DoRemap(idec, mem->buf_ + mem->start_ - old_start); in AppendToMemBuffer()
193 static int RemapMemBuffer(WebPIDecoder* const idec, in RemapMemBuffer() argument
195 MemBuffer* const mem = &idec->mem_; in RemapMemBuffer()
205 DoRemap(idec, mem->buf_ + mem->start_ - old_start); in RemapMemBuffer()
268 static VP8StatusCode IDecError(WebPIDecoder* const idec, VP8StatusCode error) { in IDecError() argument
269 if (idec->state_ == STATE_VP8_DATA) { in IDecError()
270 VP8Io* const io = &idec->io_; in IDecError()
275 idec->state_ = STATE_ERROR; in IDecError()
279 static void ChangeState(WebPIDecoder* const idec, DecState new_state, in ChangeState() argument
281 MemBuffer* const mem = &idec->mem_; in ChangeState()
282 idec->state_ = new_state; in ChangeState()
285 idec->io_.data = mem->buf_ + mem->start_; in ChangeState()
286 idec->io_.data_size = MemDataSize(mem); in ChangeState()
290 static VP8StatusCode DecodeWebPHeaders(WebPIDecoder* const idec) { in DecodeWebPHeaders() argument
291 MemBuffer* const mem = &idec->mem_; in DecodeWebPHeaders()
303 return IDecError(idec, status); in DecodeWebPHeaders()
306 idec->chunk_size_ = headers.compressed_size; in DecodeWebPHeaders()
307 idec->is_lossless_ = headers.is_lossless; in DecodeWebPHeaders()
308 if (!idec->is_lossless_) { in DecodeWebPHeaders()
313 idec->dec_ = dec; in DecodeWebPHeaders()
315 dec->use_threads_ = (idec->params_.options != NULL) && in DecodeWebPHeaders()
316 (idec->params_.options->use_threads > 0); in DecodeWebPHeaders()
322 ChangeState(idec, STATE_VP8_FRAME_HEADER, headers.offset); in DecodeWebPHeaders()
328 idec->dec_ = dec; in DecodeWebPHeaders()
329 ChangeState(idec, STATE_VP8L_HEADER, headers.offset); in DecodeWebPHeaders()
334 static VP8StatusCode DecodeVP8FrameHeader(WebPIDecoder* const idec) { in DecodeVP8FrameHeader() argument
335 const uint8_t* data = idec->mem_.buf_ + idec->mem_.start_; in DecodeVP8FrameHeader()
336 const size_t curr_size = MemDataSize(&idec->mem_); in DecodeVP8FrameHeader()
343 if (!VP8GetInfo(data, curr_size, idec->chunk_size_, NULL, NULL)) { in DecodeVP8FrameHeader()
344 return IDecError(idec, VP8_STATUS_BITSTREAM_ERROR); in DecodeVP8FrameHeader()
348 idec->mem_.part0_size_ = (bits >> 5) + VP8_FRAME_HEADER_SIZE; in DecodeVP8FrameHeader()
350 idec->io_.data = data; in DecodeVP8FrameHeader()
351 idec->io_.data_size = curr_size; in DecodeVP8FrameHeader()
352 idec->state_ = STATE_VP8_PARTS0; in DecodeVP8FrameHeader()
357 static int CopyParts0Data(WebPIDecoder* const idec) { in CopyParts0Data() argument
358 VP8Decoder* const dec = (VP8Decoder*)idec->dec_; in CopyParts0Data()
361 MemBuffer* const mem = &idec->mem_; in CopyParts0Data()
362 assert(!idec->is_lossless_); in CopyParts0Data()
383 static VP8StatusCode DecodePartition0(WebPIDecoder* const idec) { in DecodePartition0() argument
384 VP8Decoder* const dec = (VP8Decoder*)idec->dec_; in DecodePartition0()
385 VP8Io* const io = &idec->io_; in DecodePartition0()
386 const WebPDecParams* const params = &idec->params_; in DecodePartition0()
390 if (MemDataSize(&idec->mem_) < idec->mem_.part0_size_) { in DecodePartition0()
401 return IDecError(idec, status); in DecodePartition0()
408 return IDecError(idec, dec->status_); in DecodePartition0()
411 if (!CopyParts0Data(idec)) { in DecodePartition0()
412 return IDecError(idec, VP8_STATUS_OUT_OF_MEMORY); in DecodePartition0()
417 return IDecError(idec, dec->status_); in DecodePartition0()
422 idec->state_ = STATE_VP8_DATA; in DecodePartition0()
425 return IDecError(idec, dec->status_); in DecodePartition0()
431 static VP8StatusCode DecodeRemaining(WebPIDecoder* const idec) { in DecodeRemaining() argument
432 VP8Decoder* const dec = (VP8Decoder*)idec->dec_; in DecodeRemaining()
433 VP8Io* const io = &idec->io_; in DecodeRemaining()
449 if (dec->num_parts_ == 1 && MemDataSize(&idec->mem_) > MAX_MB_SIZE) { in DecodeRemaining()
450 return IDecError(idec, VP8_STATUS_BITSTREAM_ERROR); in DecodeRemaining()
459 idec->mem_.start_ = token_br->buf_ - idec->mem_.buf_; in DecodeRemaining()
460 assert(idec->mem_.start_ <= idec->mem_.end_); in DecodeRemaining()
464 return IDecError(idec, VP8_STATUS_USER_ABORT); in DecodeRemaining()
470 return IDecError(idec, VP8_STATUS_USER_ABORT); in DecodeRemaining()
473 idec->state_ = STATE_DONE; in DecodeRemaining()
478 static int ErrorStatusLossless(WebPIDecoder* const idec, VP8StatusCode status) { in ErrorStatusLossless() argument
482 return IDecError(idec, status); in ErrorStatusLossless()
485 static VP8StatusCode DecodeVP8LHeader(WebPIDecoder* const idec) { in DecodeVP8LHeader() argument
486 VP8Io* const io = &idec->io_; in DecodeVP8LHeader()
487 VP8LDecoder* const dec = (VP8LDecoder*)idec->dec_; in DecodeVP8LHeader()
488 const WebPDecParams* const params = &idec->params_; in DecodeVP8LHeader()
490 size_t curr_size = MemDataSize(&idec->mem_); in DecodeVP8LHeader()
491 assert(idec->is_lossless_); in DecodeVP8LHeader()
494 if (curr_size < (idec->chunk_size_ >> 3)) { in DecodeVP8LHeader()
498 return ErrorStatusLossless(idec, dec->status_); in DecodeVP8LHeader()
504 return IDecError(idec, dec->status_); in DecodeVP8LHeader()
507 idec->state_ = STATE_VP8L_DATA; in DecodeVP8LHeader()
511 static VP8StatusCode DecodeVP8LData(WebPIDecoder* const idec) { in DecodeVP8LData() argument
512 VP8LDecoder* const dec = (VP8LDecoder*)idec->dec_; in DecodeVP8LData()
513 const size_t curr_size = MemDataSize(&idec->mem_); in DecodeVP8LData()
514 assert(idec->is_lossless_); in DecodeVP8LData()
518 if (curr_size < idec->chunk_size_) { in DecodeVP8LData()
523 return ErrorStatusLossless(idec, dec->status_); in DecodeVP8LData()
526 idec->state_ = STATE_DONE; in DecodeVP8LData()
532 static VP8StatusCode IDecode(WebPIDecoder* idec) { in IDecode() argument
535 if (idec->state_ == STATE_PRE_VP8) { in IDecode()
536 status = DecodeWebPHeaders(idec); in IDecode()
538 if (idec->dec_ == NULL) { in IDecode()
542 if (idec->state_ == STATE_VP8_FRAME_HEADER) { in IDecode()
543 status = DecodeVP8FrameHeader(idec); in IDecode()
545 if (idec->state_ == STATE_VP8_PARTS0) { in IDecode()
546 status = DecodePartition0(idec); in IDecode()
548 if (idec->state_ == STATE_VP8_DATA) { in IDecode()
549 status = DecodeRemaining(idec); in IDecode()
551 if (idec->state_ == STATE_VP8L_HEADER) { in IDecode()
552 status = DecodeVP8LHeader(idec); in IDecode()
554 if (idec->state_ == STATE_VP8L_DATA) { in IDecode()
555 status = DecodeVP8LData(idec); in IDecode()
564 WebPIDecoder* idec = (WebPIDecoder*)calloc(1, sizeof(*idec)); in WebPINewDecoder() local
565 if (idec == NULL) { in WebPINewDecoder()
569 idec->state_ = STATE_PRE_VP8; in WebPINewDecoder()
570 idec->chunk_size_ = 0; in WebPINewDecoder()
572 InitMemBuffer(&idec->mem_); in WebPINewDecoder()
573 WebPInitDecBuffer(&idec->output_); in WebPINewDecoder()
574 VP8InitIo(&idec->io_); in WebPINewDecoder()
576 WebPResetDecParams(&idec->params_); in WebPINewDecoder()
577 idec->params_.output = output_buffer ? output_buffer : &idec->output_; in WebPINewDecoder()
578 WebPInitCustomIo(&idec->params_, &idec->io_); // Plug the I/O functions. in WebPINewDecoder()
580 return idec; in WebPINewDecoder()
585 WebPIDecoder* idec; in WebPIDecode() local
594 idec = WebPINewDecoder(config ? &config->output : NULL); in WebPIDecode()
595 if (idec == NULL) { in WebPIDecode()
600 idec->params_.options = &config->options; in WebPIDecode()
602 return idec; in WebPIDecode()
605 void WebPIDelete(WebPIDecoder* idec) { in WebPIDelete() argument
606 if (idec == NULL) return; in WebPIDelete()
607 if (idec->dec_ != NULL) { in WebPIDelete()
608 if (!idec->is_lossless_) { in WebPIDelete()
609 VP8Delete(idec->dec_); in WebPIDelete()
611 VP8LDelete(idec->dec_); in WebPIDelete()
614 ClearMemBuffer(&idec->mem_); in WebPIDelete()
615 WebPFreeDecBuffer(&idec->output_); in WebPIDelete()
616 free(idec); in WebPIDelete()
625 WebPIDecoder* idec; in WebPINewRGB() local
636 idec = WebPINewDecoder(NULL); in WebPINewRGB()
637 if (idec == NULL) return NULL; in WebPINewRGB()
638 idec->output_.colorspace = mode; in WebPINewRGB()
639 idec->output_.is_external_memory = is_external_memory; in WebPINewRGB()
640 idec->output_.u.RGBA.rgba = output_buffer; in WebPINewRGB()
641 idec->output_.u.RGBA.stride = output_stride; in WebPINewRGB()
642 idec->output_.u.RGBA.size = output_buffer_size; in WebPINewRGB()
643 return idec; in WebPINewRGB()
651 WebPIDecoder* idec; in WebPINewYUVA() local
669 idec = WebPINewDecoder(NULL); in WebPINewYUVA()
670 if (idec == NULL) return NULL; in WebPINewYUVA()
672 idec->output_.colorspace = colorspace; in WebPINewYUVA()
673 idec->output_.is_external_memory = is_external_memory; in WebPINewYUVA()
674 idec->output_.u.YUVA.y = luma; in WebPINewYUVA()
675 idec->output_.u.YUVA.y_stride = luma_stride; in WebPINewYUVA()
676 idec->output_.u.YUVA.y_size = luma_size; in WebPINewYUVA()
677 idec->output_.u.YUVA.u = u; in WebPINewYUVA()
678 idec->output_.u.YUVA.u_stride = u_stride; in WebPINewYUVA()
679 idec->output_.u.YUVA.u_size = u_size; in WebPINewYUVA()
680 idec->output_.u.YUVA.v = v; in WebPINewYUVA()
681 idec->output_.u.YUVA.v_stride = v_stride; in WebPINewYUVA()
682 idec->output_.u.YUVA.v_size = v_size; in WebPINewYUVA()
683 idec->output_.u.YUVA.a = a; in WebPINewYUVA()
684 idec->output_.u.YUVA.a_stride = a_stride; in WebPINewYUVA()
685 idec->output_.u.YUVA.a_size = a_size; in WebPINewYUVA()
686 return idec; in WebPINewYUVA()
700 static VP8StatusCode IDecCheckStatus(const WebPIDecoder* const idec) { in IDecCheckStatus() argument
701 assert(idec); in IDecCheckStatus()
702 if (idec->state_ == STATE_ERROR) { in IDecCheckStatus()
705 if (idec->state_ == STATE_DONE) { in IDecCheckStatus()
711 VP8StatusCode WebPIAppend(WebPIDecoder* idec, in WebPIAppend() argument
714 if (idec == NULL || data == NULL) { in WebPIAppend()
717 status = IDecCheckStatus(idec); in WebPIAppend()
722 if (!CheckMemBufferMode(&idec->mem_, MEM_MODE_APPEND)) { in WebPIAppend()
726 if (!AppendToMemBuffer(idec, data, data_size)) { in WebPIAppend()
729 return IDecode(idec); in WebPIAppend()
732 VP8StatusCode WebPIUpdate(WebPIDecoder* idec, in WebPIUpdate() argument
735 if (idec == NULL || data == NULL) { in WebPIUpdate()
738 status = IDecCheckStatus(idec); in WebPIUpdate()
743 if (!CheckMemBufferMode(&idec->mem_, MEM_MODE_MAP)) { in WebPIUpdate()
747 if (!RemapMemBuffer(idec, data, data_size)) { in WebPIUpdate()
750 return IDecode(idec); in WebPIUpdate()
755 static const WebPDecBuffer* GetOutputBuffer(const WebPIDecoder* const idec) { in GetOutputBuffer() argument
756 if (idec == NULL || idec->dec_ == NULL) { in GetOutputBuffer()
759 if (idec->state_ <= STATE_VP8_PARTS0) { in GetOutputBuffer()
762 return idec->params_.output; in GetOutputBuffer()
765 const WebPDecBuffer* WebPIDecodedArea(const WebPIDecoder* idec, in WebPIDecodedArea() argument
768 const WebPDecBuffer* const src = GetOutputBuffer(idec); in WebPIDecodedArea()
774 if (height != NULL) *height = idec->params_.last_y; in WebPIDecodedArea()
782 uint8_t* WebPIDecGetRGB(const WebPIDecoder* idec, int* last_y, in WebPIDecGetRGB() argument
784 const WebPDecBuffer* const src = GetOutputBuffer(idec); in WebPIDecGetRGB()
790 if (last_y != NULL) *last_y = idec->params_.last_y; in WebPIDecGetRGB()
798 uint8_t* WebPIDecGetYUVA(const WebPIDecoder* idec, int* last_y, in WebPIDecGetYUVA() argument
802 const WebPDecBuffer* const src = GetOutputBuffer(idec); in WebPIDecGetYUVA()
808 if (last_y != NULL) *last_y = idec->params_.last_y; in WebPIDecGetYUVA()
821 int WebPISetIOHooks(WebPIDecoder* const idec, in WebPISetIOHooks() argument
826 if (idec == NULL || idec->state_ > STATE_PRE_VP8) { in WebPISetIOHooks()
830 idec->io_.put = put; in WebPISetIOHooks()
831 idec->io_.setup = setup; in WebPISetIOHooks()
832 idec->io_.teardown = teardown; in WebPISetIOHooks()
833 idec->io_.opaque = user_data; in WebPISetIOHooks()