Lines Matching refs:idec
100 static void DoRemap(WebPIDecoder* const idec, ptrdiff_t offset) { in DoRemap() argument
101 MemBuffer* const mem = &idec->mem_; in DoRemap()
105 idec->io_.data = new_base; in DoRemap()
106 idec->io_.data_size = MemDataSize(mem); in DoRemap()
108 if (idec->dec_ != NULL) { in DoRemap()
109 if (!idec->is_lossless_) { in DoRemap()
110 VP8Decoder* const dec = (VP8Decoder*)idec->dec_; in DoRemap()
126 VP8LDecoder* const dec = (VP8LDecoder*)idec->dec_; in DoRemap()
134 static int AppendToMemBuffer(WebPIDecoder* const idec, in AppendToMemBuffer() argument
136 MemBuffer* const mem = &idec->mem_; in AppendToMemBuffer()
164 DoRemap(idec, mem->buf_ + mem->start_ - old_base); in AppendToMemBuffer()
168 static int RemapMemBuffer(WebPIDecoder* const idec, in RemapMemBuffer() argument
170 MemBuffer* const mem = &idec->mem_; in RemapMemBuffer()
179 DoRemap(idec, mem->buf_ + mem->start_ - old_base); in RemapMemBuffer()
242 static VP8StatusCode IDecError(WebPIDecoder* const idec, VP8StatusCode error) { in IDecError() argument
243 if (idec->state_ == STATE_VP8_DATA) { in IDecError()
244 VP8Io* const io = &idec->io_; in IDecError()
249 idec->state_ = STATE_ERROR; in IDecError()
253 static void ChangeState(WebPIDecoder* const idec, DecState new_state, in ChangeState() argument
255 MemBuffer* const mem = &idec->mem_; in ChangeState()
256 idec->state_ = new_state; in ChangeState()
259 idec->io_.data = mem->buf_ + mem->start_; in ChangeState()
260 idec->io_.data_size = MemDataSize(mem); in ChangeState()
264 static VP8StatusCode DecodeWebPHeaders(WebPIDecoder* const idec) { in DecodeWebPHeaders() argument
265 MemBuffer* const mem = &idec->mem_; in DecodeWebPHeaders()
277 return IDecError(idec, status); in DecodeWebPHeaders()
280 idec->chunk_size_ = headers.compressed_size; in DecodeWebPHeaders()
281 idec->is_lossless_ = headers.is_lossless; in DecodeWebPHeaders()
282 if (!idec->is_lossless_) { in DecodeWebPHeaders()
287 idec->dec_ = dec; in DecodeWebPHeaders()
289 dec->use_threads_ = (idec->params_.options != NULL) && in DecodeWebPHeaders()
290 (idec->params_.options->use_threads > 0); in DecodeWebPHeaders()
296 ChangeState(idec, STATE_VP8_FRAME_HEADER, headers.offset); in DecodeWebPHeaders()
302 idec->dec_ = dec; in DecodeWebPHeaders()
303 ChangeState(idec, STATE_VP8L_HEADER, headers.offset); in DecodeWebPHeaders()
308 static VP8StatusCode DecodeVP8FrameHeader(WebPIDecoder* const idec) { in DecodeVP8FrameHeader() argument
309 const uint8_t* data = idec->mem_.buf_ + idec->mem_.start_; in DecodeVP8FrameHeader()
310 const size_t curr_size = MemDataSize(&idec->mem_); in DecodeVP8FrameHeader()
317 if (!VP8GetInfo(data, curr_size, idec->chunk_size_, NULL, NULL)) { in DecodeVP8FrameHeader()
318 return IDecError(idec, VP8_STATUS_BITSTREAM_ERROR); in DecodeVP8FrameHeader()
322 idec->mem_.part0_size_ = (bits >> 5) + VP8_FRAME_HEADER_SIZE; in DecodeVP8FrameHeader()
324 idec->io_.data = data; in DecodeVP8FrameHeader()
325 idec->io_.data_size = curr_size; in DecodeVP8FrameHeader()
326 idec->state_ = STATE_VP8_PARTS0; in DecodeVP8FrameHeader()
331 static int CopyParts0Data(WebPIDecoder* const idec) { in CopyParts0Data() argument
332 VP8Decoder* const dec = (VP8Decoder*)idec->dec_; in CopyParts0Data()
335 MemBuffer* const mem = &idec->mem_; in CopyParts0Data()
336 assert(!idec->is_lossless_); in CopyParts0Data()
357 static VP8StatusCode DecodePartition0(WebPIDecoder* const idec) { in DecodePartition0() argument
358 VP8Decoder* const dec = (VP8Decoder*)idec->dec_; in DecodePartition0()
359 VP8Io* const io = &idec->io_; in DecodePartition0()
360 const WebPDecParams* const params = &idec->params_; in DecodePartition0()
364 if (MemDataSize(&idec->mem_) < idec->mem_.part0_size_) { in DecodePartition0()
375 return IDecError(idec, status); in DecodePartition0()
382 return IDecError(idec, dec->status_); in DecodePartition0()
385 if (!CopyParts0Data(idec)) { in DecodePartition0()
386 return IDecError(idec, VP8_STATUS_OUT_OF_MEMORY); in DecodePartition0()
391 return IDecError(idec, dec->status_); in DecodePartition0()
396 idec->state_ = STATE_VP8_DATA; in DecodePartition0()
399 return IDecError(idec, dec->status_); in DecodePartition0()
405 static VP8StatusCode DecodeRemaining(WebPIDecoder* const idec) { in DecodeRemaining() argument
406 VP8Decoder* const dec = (VP8Decoder*)idec->dec_; in DecodeRemaining()
407 VP8Io* const io = &idec->io_; in DecodeRemaining()
423 if (dec->num_parts_ == 1 && MemDataSize(&idec->mem_) > MAX_MB_SIZE) { in DecodeRemaining()
424 return IDecError(idec, VP8_STATUS_BITSTREAM_ERROR); in DecodeRemaining()
433 idec->mem_.start_ = token_br->buf_ - idec->mem_.buf_; in DecodeRemaining()
434 assert(idec->mem_.start_ <= idec->mem_.end_); in DecodeRemaining()
438 return IDecError(idec, VP8_STATUS_USER_ABORT); in DecodeRemaining()
444 return IDecError(idec, VP8_STATUS_USER_ABORT); in DecodeRemaining()
447 idec->state_ = STATE_DONE; in DecodeRemaining()
452 static int ErrorStatusLossless(WebPIDecoder* const idec, VP8StatusCode status) { in ErrorStatusLossless() argument
456 return IDecError(idec, status); in ErrorStatusLossless()
459 static VP8StatusCode DecodeVP8LHeader(WebPIDecoder* const idec) { in DecodeVP8LHeader() argument
460 VP8Io* const io = &idec->io_; in DecodeVP8LHeader()
461 VP8LDecoder* const dec = (VP8LDecoder*)idec->dec_; in DecodeVP8LHeader()
462 const WebPDecParams* const params = &idec->params_; in DecodeVP8LHeader()
464 size_t curr_size = MemDataSize(&idec->mem_); in DecodeVP8LHeader()
465 assert(idec->is_lossless_); in DecodeVP8LHeader()
468 if (curr_size < (idec->chunk_size_ >> 3)) { in DecodeVP8LHeader()
472 return ErrorStatusLossless(idec, dec->status_); in DecodeVP8LHeader()
478 return IDecError(idec, dec->status_); in DecodeVP8LHeader()
481 idec->state_ = STATE_VP8L_DATA; in DecodeVP8LHeader()
485 static VP8StatusCode DecodeVP8LData(WebPIDecoder* const idec) { in DecodeVP8LData() argument
486 VP8LDecoder* const dec = (VP8LDecoder*)idec->dec_; in DecodeVP8LData()
487 const size_t curr_size = MemDataSize(&idec->mem_); in DecodeVP8LData()
488 assert(idec->is_lossless_); in DecodeVP8LData()
492 if (curr_size < idec->chunk_size_) { in DecodeVP8LData()
497 return ErrorStatusLossless(idec, dec->status_); in DecodeVP8LData()
500 idec->state_ = STATE_DONE; in DecodeVP8LData()
506 static VP8StatusCode IDecode(WebPIDecoder* idec) { in IDecode() argument
509 if (idec->state_ == STATE_PRE_VP8) { in IDecode()
510 status = DecodeWebPHeaders(idec); in IDecode()
512 if (idec->dec_ == NULL) { in IDecode()
516 if (idec->state_ == STATE_VP8_FRAME_HEADER) { in IDecode()
517 status = DecodeVP8FrameHeader(idec); in IDecode()
519 if (idec->state_ == STATE_VP8_PARTS0) { in IDecode()
520 status = DecodePartition0(idec); in IDecode()
522 if (idec->state_ == STATE_VP8_DATA) { in IDecode()
523 status = DecodeRemaining(idec); in IDecode()
525 if (idec->state_ == STATE_VP8L_HEADER) { in IDecode()
526 status = DecodeVP8LHeader(idec); in IDecode()
528 if (idec->state_ == STATE_VP8L_DATA) { in IDecode()
529 status = DecodeVP8LData(idec); in IDecode()
538 WebPIDecoder* idec = (WebPIDecoder*)calloc(1, sizeof(*idec)); in WebPINewDecoder() local
539 if (idec == NULL) { in WebPINewDecoder()
543 idec->state_ = STATE_PRE_VP8; in WebPINewDecoder()
544 idec->chunk_size_ = 0; in WebPINewDecoder()
546 InitMemBuffer(&idec->mem_); in WebPINewDecoder()
547 WebPInitDecBuffer(&idec->output_); in WebPINewDecoder()
548 VP8InitIo(&idec->io_); in WebPINewDecoder()
550 WebPResetDecParams(&idec->params_); in WebPINewDecoder()
551 idec->params_.output = output_buffer ? output_buffer : &idec->output_; in WebPINewDecoder()
552 WebPInitCustomIo(&idec->params_, &idec->io_); // Plug the I/O functions. in WebPINewDecoder()
554 return idec; in WebPINewDecoder()
559 WebPIDecoder* idec; in WebPIDecode() local
568 idec = WebPINewDecoder(config ? &config->output : NULL); in WebPIDecode()
569 if (idec == NULL) { in WebPIDecode()
574 idec->params_.options = &config->options; in WebPIDecode()
576 return idec; in WebPIDecode()
579 void WebPIDelete(WebPIDecoder* idec) { in WebPIDelete() argument
580 if (idec == NULL) return; in WebPIDelete()
581 if (idec->dec_ != NULL) { in WebPIDelete()
582 if (!idec->is_lossless_) { in WebPIDelete()
583 VP8Delete(idec->dec_); in WebPIDelete()
585 VP8LDelete(idec->dec_); in WebPIDelete()
588 ClearMemBuffer(&idec->mem_); in WebPIDelete()
589 WebPFreeDecBuffer(&idec->output_); in WebPIDelete()
590 free(idec); in WebPIDelete()
599 WebPIDecoder* idec; in WebPINewRGB() local
610 idec = WebPINewDecoder(NULL); in WebPINewRGB()
611 if (idec == NULL) return NULL; in WebPINewRGB()
612 idec->output_.colorspace = mode; in WebPINewRGB()
613 idec->output_.is_external_memory = is_external_memory; in WebPINewRGB()
614 idec->output_.u.RGBA.rgba = output_buffer; in WebPINewRGB()
615 idec->output_.u.RGBA.stride = output_stride; in WebPINewRGB()
616 idec->output_.u.RGBA.size = output_buffer_size; in WebPINewRGB()
617 return idec; in WebPINewRGB()
625 WebPIDecoder* idec; in WebPINewYUVA() local
643 idec = WebPINewDecoder(NULL); in WebPINewYUVA()
644 if (idec == NULL) return NULL; in WebPINewYUVA()
646 idec->output_.colorspace = colorspace; in WebPINewYUVA()
647 idec->output_.is_external_memory = is_external_memory; in WebPINewYUVA()
648 idec->output_.u.YUVA.y = luma; in WebPINewYUVA()
649 idec->output_.u.YUVA.y_stride = luma_stride; in WebPINewYUVA()
650 idec->output_.u.YUVA.y_size = luma_size; in WebPINewYUVA()
651 idec->output_.u.YUVA.u = u; in WebPINewYUVA()
652 idec->output_.u.YUVA.u_stride = u_stride; in WebPINewYUVA()
653 idec->output_.u.YUVA.u_size = u_size; in WebPINewYUVA()
654 idec->output_.u.YUVA.v = v; in WebPINewYUVA()
655 idec->output_.u.YUVA.v_stride = v_stride; in WebPINewYUVA()
656 idec->output_.u.YUVA.v_size = v_size; in WebPINewYUVA()
657 idec->output_.u.YUVA.a = a; in WebPINewYUVA()
658 idec->output_.u.YUVA.a_stride = a_stride; in WebPINewYUVA()
659 idec->output_.u.YUVA.a_size = a_size; in WebPINewYUVA()
660 return idec; in WebPINewYUVA()
674 static VP8StatusCode IDecCheckStatus(const WebPIDecoder* const idec) { in IDecCheckStatus() argument
675 assert(idec); in IDecCheckStatus()
676 if (idec->state_ == STATE_ERROR) { in IDecCheckStatus()
679 if (idec->state_ == STATE_DONE) { in IDecCheckStatus()
685 VP8StatusCode WebPIAppend(WebPIDecoder* idec, in WebPIAppend() argument
688 if (idec == NULL || data == NULL) { in WebPIAppend()
691 status = IDecCheckStatus(idec); in WebPIAppend()
696 if (!CheckMemBufferMode(&idec->mem_, MEM_MODE_APPEND)) { in WebPIAppend()
700 if (!AppendToMemBuffer(idec, data, data_size)) { in WebPIAppend()
703 return IDecode(idec); in WebPIAppend()
706 VP8StatusCode WebPIUpdate(WebPIDecoder* idec, in WebPIUpdate() argument
709 if (idec == NULL || data == NULL) { in WebPIUpdate()
712 status = IDecCheckStatus(idec); in WebPIUpdate()
717 if (!CheckMemBufferMode(&idec->mem_, MEM_MODE_MAP)) { in WebPIUpdate()
721 if (!RemapMemBuffer(idec, data, data_size)) { in WebPIUpdate()
724 return IDecode(idec); in WebPIUpdate()
729 static const WebPDecBuffer* GetOutputBuffer(const WebPIDecoder* const idec) { in GetOutputBuffer() argument
730 if (idec == NULL || idec->dec_ == NULL) { in GetOutputBuffer()
733 if (idec->state_ <= STATE_VP8_PARTS0) { in GetOutputBuffer()
736 return idec->params_.output; in GetOutputBuffer()
739 const WebPDecBuffer* WebPIDecodedArea(const WebPIDecoder* idec, in WebPIDecodedArea() argument
742 const WebPDecBuffer* const src = GetOutputBuffer(idec); in WebPIDecodedArea()
748 if (height != NULL) *height = idec->params_.last_y; in WebPIDecodedArea()
756 uint8_t* WebPIDecGetRGB(const WebPIDecoder* idec, int* last_y, in WebPIDecGetRGB() argument
758 const WebPDecBuffer* const src = GetOutputBuffer(idec); in WebPIDecGetRGB()
764 if (last_y != NULL) *last_y = idec->params_.last_y; in WebPIDecGetRGB()
772 uint8_t* WebPIDecGetYUVA(const WebPIDecoder* idec, int* last_y, in WebPIDecGetYUVA() argument
776 const WebPDecBuffer* const src = GetOutputBuffer(idec); in WebPIDecGetYUVA()
782 if (last_y != NULL) *last_y = idec->params_.last_y; in WebPIDecGetYUVA()
795 int WebPISetIOHooks(WebPIDecoder* const idec, in WebPISetIOHooks() argument
800 if (idec == NULL || idec->state_ > STATE_PRE_VP8) { in WebPISetIOHooks()
804 idec->io_.put = put; in WebPISetIOHooks()
805 idec->io_.setup = setup; in WebPISetIOHooks()
806 idec->io_.teardown = teardown; in WebPISetIOHooks()
807 idec->io_.opaque = user_data; in WebPISetIOHooks()