Lines Matching refs:dmux

86   ParseStatus (*parse)(WebPDemuxer* const dmux);
87 int (*valid)(const WebPDemuxer* const dmux);
90 static ParseStatus ParseSingleImage(WebPDemuxer* const dmux);
91 static ParseStatus ParseVP8X(WebPDemuxer* const dmux);
92 static int IsValidSimpleFormat(const WebPDemuxer* const dmux);
93 static int IsValidExtendedFormat(const WebPDemuxer* const dmux);
179 static void AddChunk(WebPDemuxer* const dmux, Chunk* const chunk) { in AddChunk() argument
180 Chunk** c = &dmux->chunks_; in AddChunk()
188 static int AddFrame(WebPDemuxer* const dmux, Frame* const frame) { in AddFrame() argument
189 const Frame* const last_frame = *dmux->frames_tail_; in AddFrame()
192 *dmux->frames_tail_ = frame; in AddFrame()
194 dmux->frames_tail_ = &frame->next_; in AddFrame()
305 WebPDemuxer* const dmux, uint32_t frame_chunk_size) { in ParseAnimationFrame() argument
306 const int has_frames = !!(dmux->feature_flags_ & ANIMATION_FLAG); in ParseAnimationFrame()
309 MemBuffer* const mem = &dmux->mem_; in ParseAnimationFrame()
328 status = StoreFrame(dmux->num_frames_ + 1, anmf_payload_size, mem, frame, in ParseAnimationFrame()
331 added_frame = AddFrame(dmux, frame); in ParseAnimationFrame()
333 ++dmux->num_frames_; in ParseAnimationFrame()
346 static ParseStatus ParseFragment(WebPDemuxer* const dmux, in ParseFragment() argument
349 const int has_fragments = !!(dmux->feature_flags_ & FRAGMENTS_FLAG); in ParseFragment()
352 MemBuffer* const mem = &dmux->mem_; in ParseFragment()
366 added_fragment = AddFrame(dmux, frame); in ParseFragment()
370 dmux->num_frames_ = 1; in ParseFragment()
383 static int StoreChunk(WebPDemuxer* const dmux, in StoreChunk() argument
390 AddChunk(dmux, chunk); in StoreChunk()
422 static ParseStatus ParseSingleImage(WebPDemuxer* const dmux) { in ParseSingleImage() argument
424 MemBuffer* const mem = &dmux->mem_; in ParseSingleImage()
429 if (dmux->frames_ != NULL) return PARSE_ERROR; in ParseSingleImage()
438 status = StoreFrame(1, CHUNK_HEADER_SIZE, &dmux->mem_, frame, in ParseSingleImage()
441 const int has_alpha = !!(dmux->feature_flags_ & ALPHA_FLAG); in ParseSingleImage()
450 if (!dmux->is_ext_format_ && frame->width_ > 0 && frame->height_ > 0) { in ParseSingleImage()
451 dmux->state_ = WEBP_DEMUX_PARSED_HEADER; in ParseSingleImage()
452 dmux->canvas_width_ = frame->width_; in ParseSingleImage()
453 dmux->canvas_height_ = frame->height_; in ParseSingleImage()
454 dmux->feature_flags_ |= has_vp8l_alpha ? ALPHA_FLAG : 0; in ParseSingleImage()
456 AddFrame(dmux, frame); in ParseSingleImage()
457 dmux->num_frames_ = 1; in ParseSingleImage()
465 static ParseStatus ParseVP8X(WebPDemuxer* const dmux) { in ParseVP8X() argument
466 MemBuffer* const mem = &dmux->mem_; in ParseVP8X()
473 dmux->is_ext_format_ = 1; in ParseVP8X()
482 dmux->feature_flags_ = ReadByte(mem); in ParseVP8X()
484 dmux->canvas_width_ = 1 + ReadLE24s(mem); in ParseVP8X()
485 dmux->canvas_height_ = 1 + ReadLE24s(mem); in ParseVP8X()
486 if (dmux->canvas_width_ * (uint64_t)dmux->canvas_height_ >= MAX_IMAGE_AREA) { in ParseVP8X()
490 dmux->state_ = WEBP_DEMUX_PARSED_HEADER; in ParseVP8X()
516 status = ParseSingleImage(dmux); in ParseVP8X()
526 dmux->bgcolor_ = ReadLE32(mem); in ParseVP8X()
527 dmux->loop_count_ = ReadLE16s(mem); in ParseVP8X()
537 status = ParseAnimationFrame(dmux, chunk_size_padded); in ParseVP8X()
542 status = ParseFragment(dmux, chunk_size_padded); in ParseVP8X()
547 store_chunk = !!(dmux->feature_flags_ & ICCP_FLAG); in ParseVP8X()
551 store_chunk = !!(dmux->feature_flags_ & XMP_FLAG); in ParseVP8X()
555 store_chunk = !!(dmux->feature_flags_ & EXIF_FLAG); in ParseVP8X()
564 if (!StoreChunk(dmux, chunk_start_offset, in ParseVP8X()
589 static int IsValidSimpleFormat(const WebPDemuxer* const dmux) { in IsValidSimpleFormat() argument
590 const Frame* const frame = dmux->frames_; in IsValidSimpleFormat()
591 if (dmux->state_ == WEBP_DEMUX_PARSING_HEADER) return 1; in IsValidSimpleFormat()
593 if (dmux->canvas_width_ <= 0 || dmux->canvas_height_ <= 0) return 0; in IsValidSimpleFormat()
594 if (dmux->state_ == WEBP_DEMUX_DONE && frame == NULL) return 0; in IsValidSimpleFormat()
600 static int IsValidExtendedFormat(const WebPDemuxer* const dmux) { in IsValidExtendedFormat() argument
601 const int has_fragments = !!(dmux->feature_flags_ & FRAGMENTS_FLAG); in IsValidExtendedFormat()
602 const int has_frames = !!(dmux->feature_flags_ & ANIMATION_FLAG); in IsValidExtendedFormat()
605 if (dmux->state_ == WEBP_DEMUX_PARSING_HEADER) return 1; in IsValidExtendedFormat()
607 if (dmux->canvas_width_ <= 0 || dmux->canvas_height_ <= 0) return 0; in IsValidExtendedFormat()
608 if (dmux->loop_count_ < 0) return 0; in IsValidExtendedFormat()
609 if (dmux->state_ == WEBP_DEMUX_DONE && dmux->frames_ == NULL) return 0; in IsValidExtendedFormat()
611 for (f = dmux->frames_; f != NULL; f = f->next_) { in IsValidExtendedFormat()
634 if (dmux->state_ == WEBP_DEMUX_DONE) return 0; in IsValidExtendedFormat()
658 static void InitDemux(WebPDemuxer* const dmux, const MemBuffer* const mem) { in InitDemux() argument
659 dmux->state_ = WEBP_DEMUX_PARSING_HEADER; in InitDemux()
660 dmux->loop_count_ = 1; in InitDemux()
661 dmux->bgcolor_ = 0xFFFFFFFF; // White background by default. in InitDemux()
662 dmux->canvas_width_ = -1; in InitDemux()
663 dmux->canvas_height_ = -1; in InitDemux()
664 dmux->frames_tail_ = &dmux->frames_; in InitDemux()
665 dmux->mem_ = *mem; in InitDemux()
674 WebPDemuxer* dmux; in WebPDemuxInternal() local
685 dmux = (WebPDemuxer*)calloc(1, sizeof(*dmux)); in WebPDemuxInternal()
686 if (dmux == NULL) return NULL; in WebPDemuxInternal()
687 InitDemux(dmux, &mem); in WebPDemuxInternal()
690 if (!memcmp(parser->id, GetBuffer(&dmux->mem_), TAG_SIZE)) { in WebPDemuxInternal()
691 status = parser->parse(dmux); in WebPDemuxInternal()
692 if (status == PARSE_OK) dmux->state_ = WEBP_DEMUX_DONE; in WebPDemuxInternal()
694 if (status != PARSE_ERROR && !parser->valid(dmux)) status = PARSE_ERROR; in WebPDemuxInternal()
698 if (state) *state = dmux->state_; in WebPDemuxInternal()
701 WebPDemuxDelete(dmux); in WebPDemuxInternal()
704 return dmux; in WebPDemuxInternal()
707 void WebPDemuxDelete(WebPDemuxer* dmux) { in WebPDemuxDelete() argument
710 if (dmux == NULL) return; in WebPDemuxDelete()
712 for (f = dmux->frames_; f != NULL;) { in WebPDemuxDelete()
717 for (c = dmux->chunks_; c != NULL;) { in WebPDemuxDelete()
722 free(dmux); in WebPDemuxDelete()
727 uint32_t WebPDemuxGetI(const WebPDemuxer* dmux, WebPFormatFeature feature) { in WebPDemuxGetI() argument
728 if (dmux == NULL) return 0; in WebPDemuxGetI()
731 case WEBP_FF_FORMAT_FLAGS: return dmux->feature_flags_; in WebPDemuxGetI()
732 case WEBP_FF_CANVAS_WIDTH: return (uint32_t)dmux->canvas_width_; in WebPDemuxGetI()
733 case WEBP_FF_CANVAS_HEIGHT: return (uint32_t)dmux->canvas_height_; in WebPDemuxGetI()
734 case WEBP_FF_LOOP_COUNT: return (uint32_t)dmux->loop_count_; in WebPDemuxGetI()
735 case WEBP_FF_BACKGROUND_COLOR: return dmux->bgcolor_; in WebPDemuxGetI()
736 case WEBP_FF_FRAME_COUNT: return (uint32_t)dmux->num_frames_; in WebPDemuxGetI()
746 static const Frame* GetFrame(const WebPDemuxer* const dmux, int frame_num) { in GetFrame() argument
748 for (f = dmux->frames_; f != NULL; f = f->next_) { in GetFrame()
794 static int SynthesizeFrame(const WebPDemuxer* const dmux, in SynthesizeFrame() argument
797 const uint8_t* const mem_buf = dmux->mem_.buf_; in SynthesizeFrame()
808 iter->num_frames = dmux->num_frames_; in SynthesizeFrame()
826 const WebPDemuxer* const dmux = (WebPDemuxer*)iter->private_; in SetFrame() local
827 if (dmux == NULL || frame_num < 0) return 0; in SetFrame()
828 if (frame_num > dmux->num_frames_) return 0; in SetFrame()
829 if (frame_num == 0) frame_num = dmux->num_frames_; in SetFrame()
831 frame = GetFrame(dmux, frame_num); in SetFrame()
834 return SynthesizeFrame(dmux, frame, 1, iter); in SetFrame()
837 int WebPDemuxGetFrame(const WebPDemuxer* dmux, int frame, WebPIterator* iter) { in WebPDemuxGetFrame() argument
841 iter->private_ = (void*)dmux; in WebPDemuxGetFrame()
858 const WebPDemuxer* const dmux = (WebPDemuxer*)iter->private_; in WebPDemuxSelectFragment() local
859 const Frame* const frame = GetFrame(dmux, iter->frame_num); in WebPDemuxSelectFragment()
862 return SynthesizeFrame(dmux, frame, fragment_num, iter); in WebPDemuxSelectFragment()
874 static int ChunkCount(const WebPDemuxer* const dmux, const char fourcc[4]) { in ChunkCount() argument
875 const uint8_t* const mem_buf = dmux->mem_.buf_; in ChunkCount()
878 for (c = dmux->chunks_; c != NULL; c = c->next_) { in ChunkCount()
885 static const Chunk* GetChunk(const WebPDemuxer* const dmux, in GetChunk() argument
887 const uint8_t* const mem_buf = dmux->mem_.buf_; in GetChunk()
890 for (c = dmux->chunks_; c != NULL; c = c->next_) { in GetChunk()
900 const WebPDemuxer* const dmux = (WebPDemuxer*)iter->private_; in SetChunk() local
903 if (dmux == NULL || fourcc == NULL || chunk_num < 0) return 0; in SetChunk()
904 count = ChunkCount(dmux, fourcc); in SetChunk()
909 const uint8_t* const mem_buf = dmux->mem_.buf_; in SetChunk()
910 const Chunk* const chunk = GetChunk(dmux, fourcc, chunk_num); in SetChunk()
920 int WebPDemuxGetChunk(const WebPDemuxer* dmux, in WebPDemuxGetChunk() argument
926 iter->private_ = (void*)dmux; in WebPDemuxGetChunk()