Lines Matching refs:dmux
84 ParseStatus (*parse)(WebPDemuxer* const dmux);
85 int (*valid)(const WebPDemuxer* const dmux);
88 static ParseStatus ParseSingleImage(WebPDemuxer* const dmux);
89 static ParseStatus ParseVP8X(WebPDemuxer* const dmux);
90 static int IsValidSimpleFormat(const WebPDemuxer* const dmux);
91 static int IsValidExtendedFormat(const WebPDemuxer* const dmux);
177 static void AddChunk(WebPDemuxer* const dmux, Chunk* const chunk) { in AddChunk() argument
178 *dmux->chunks_tail_ = chunk; in AddChunk()
180 dmux->chunks_tail_ = &chunk->next_; in AddChunk()
185 static int AddFrame(WebPDemuxer* const dmux, Frame* const frame) { in AddFrame() argument
186 const Frame* const last_frame = *dmux->frames_tail_; in AddFrame()
189 *dmux->frames_tail_ = frame; in AddFrame()
191 dmux->frames_tail_ = &frame->next_; in AddFrame()
306 WebPDemuxer* const dmux, uint32_t frame_chunk_size) { in ParseAnimationFrame() argument
307 const int is_animation = !!(dmux->feature_flags_ & ANIMATION_FLAG); in ParseAnimationFrame()
311 MemBuffer* const mem = &dmux->mem_; in ParseAnimationFrame()
333 status = StoreFrame(dmux->num_frames_ + 1, anmf_payload_size, mem, frame); in ParseAnimationFrame()
335 added_frame = AddFrame(dmux, frame); in ParseAnimationFrame()
337 ++dmux->num_frames_; in ParseAnimationFrame()
351 static int StoreChunk(WebPDemuxer* const dmux, in StoreChunk() argument
358 AddChunk(dmux, chunk); in StoreChunk()
390 static ParseStatus ParseSingleImage(WebPDemuxer* const dmux) { in ParseSingleImage() argument
392 MemBuffer* const mem = &dmux->mem_; in ParseSingleImage()
397 if (dmux->frames_ != NULL) return PARSE_ERROR; in ParseSingleImage()
406 status = StoreFrame(1, CHUNK_HEADER_SIZE, &dmux->mem_, frame); in ParseSingleImage()
408 const int has_alpha = !!(dmux->feature_flags_ & ALPHA_FLAG); in ParseSingleImage()
418 if (!dmux->is_ext_format_ && frame->width_ > 0 && frame->height_ > 0) { in ParseSingleImage()
419 dmux->state_ = WEBP_DEMUX_PARSED_HEADER; in ParseSingleImage()
420 dmux->canvas_width_ = frame->width_; in ParseSingleImage()
421 dmux->canvas_height_ = frame->height_; in ParseSingleImage()
422 dmux->feature_flags_ |= frame->has_alpha_ ? ALPHA_FLAG : 0; in ParseSingleImage()
424 if (!AddFrame(dmux, frame)) { in ParseSingleImage()
428 dmux->num_frames_ = 1; in ParseSingleImage()
436 static ParseStatus ParseVP8XChunks(WebPDemuxer* const dmux) { in ParseVP8XChunks() argument
437 const int is_animation = !!(dmux->feature_flags_ & ANIMATION_FLAG); in ParseVP8XChunks()
438 MemBuffer* const mem = &dmux->mem_; in ParseVP8XChunks()
463 status = ParseSingleImage(dmux); in ParseVP8XChunks()
473 dmux->bgcolor_ = ReadLE32(mem); in ParseVP8XChunks()
474 dmux->loop_count_ = ReadLE16s(mem); in ParseVP8XChunks()
484 status = ParseAnimationFrame(dmux, chunk_size_padded); in ParseVP8XChunks()
488 store_chunk = !!(dmux->feature_flags_ & ICCP_FLAG); in ParseVP8XChunks()
492 store_chunk = !!(dmux->feature_flags_ & EXIF_FLAG); in ParseVP8XChunks()
496 store_chunk = !!(dmux->feature_flags_ & XMP_FLAG); in ParseVP8XChunks()
505 if (!StoreChunk(dmux, chunk_start_offset, in ParseVP8XChunks()
527 static ParseStatus ParseVP8X(WebPDemuxer* const dmux) { in ParseVP8X() argument
528 MemBuffer* const mem = &dmux->mem_; in ParseVP8X()
533 dmux->is_ext_format_ = 1; in ParseVP8X()
542 dmux->feature_flags_ = ReadByte(mem); in ParseVP8X()
544 dmux->canvas_width_ = 1 + ReadLE24s(mem); in ParseVP8X()
545 dmux->canvas_height_ = 1 + ReadLE24s(mem); in ParseVP8X()
546 if (dmux->canvas_width_ * (uint64_t)dmux->canvas_height_ >= MAX_IMAGE_AREA) { in ParseVP8X()
550 dmux->state_ = WEBP_DEMUX_PARSED_HEADER; in ParseVP8X()
555 return ParseVP8XChunks(dmux); in ParseVP8X()
561 static int IsValidSimpleFormat(const WebPDemuxer* const dmux) { in IsValidSimpleFormat() argument
562 const Frame* const frame = dmux->frames_; in IsValidSimpleFormat()
563 if (dmux->state_ == WEBP_DEMUX_PARSING_HEADER) return 1; in IsValidSimpleFormat()
565 if (dmux->canvas_width_ <= 0 || dmux->canvas_height_ <= 0) return 0; in IsValidSimpleFormat()
566 if (dmux->state_ == WEBP_DEMUX_DONE && frame == NULL) return 0; in IsValidSimpleFormat()
591 static int IsValidExtendedFormat(const WebPDemuxer* const dmux) { in IsValidExtendedFormat() argument
592 const int is_animation = !!(dmux->feature_flags_ & ANIMATION_FLAG); in IsValidExtendedFormat()
593 const int is_fragmented = !!(dmux->feature_flags_ & FRAGMENTS_FLAG); in IsValidExtendedFormat()
594 const Frame* f = dmux->frames_; in IsValidExtendedFormat()
596 if (dmux->state_ == WEBP_DEMUX_PARSING_HEADER) return 1; in IsValidExtendedFormat()
598 if (dmux->canvas_width_ <= 0 || dmux->canvas_height_ <= 0) return 0; in IsValidExtendedFormat()
599 if (dmux->loop_count_ < 0) return 0; in IsValidExtendedFormat()
600 if (dmux->state_ == WEBP_DEMUX_DONE && dmux->frames_ == NULL) return 0; in IsValidExtendedFormat()
624 if (dmux->state_ == WEBP_DEMUX_DONE) return 0; in IsValidExtendedFormat()
637 dmux->canvas_width_, dmux->canvas_height_)) { in IsValidExtendedFormat()
650 static void InitDemux(WebPDemuxer* const dmux, const MemBuffer* const mem) { in InitDemux() argument
651 dmux->state_ = WEBP_DEMUX_PARSING_HEADER; in InitDemux()
652 dmux->loop_count_ = 1; in InitDemux()
653 dmux->bgcolor_ = 0xFFFFFFFF; // White background by default. in InitDemux()
654 dmux->canvas_width_ = -1; in InitDemux()
655 dmux->canvas_height_ = -1; in InitDemux()
656 dmux->frames_tail_ = &dmux->frames_; in InitDemux()
657 dmux->chunks_tail_ = &dmux->chunks_; in InitDemux()
658 dmux->mem_ = *mem; in InitDemux()
673 WebPDemuxer* const dmux = (WebPDemuxer*)WebPSafeCalloc(1ULL, sizeof(*dmux)); in CreateRawImageDemuxer() local
675 if (dmux == NULL || frame == NULL) goto Error; in CreateRawImageDemuxer()
676 InitDemux(dmux, mem); in CreateRawImageDemuxer()
679 if (!AddFrame(dmux, frame)) goto Error; in CreateRawImageDemuxer()
680 dmux->state_ = WEBP_DEMUX_DONE; in CreateRawImageDemuxer()
681 dmux->canvas_width_ = frame->width_; in CreateRawImageDemuxer()
682 dmux->canvas_height_ = frame->height_; in CreateRawImageDemuxer()
683 dmux->feature_flags_ |= frame->has_alpha_ ? ALPHA_FLAG : 0; in CreateRawImageDemuxer()
684 dmux->num_frames_ = 1; in CreateRawImageDemuxer()
685 assert(IsValidSimpleFormat(dmux)); in CreateRawImageDemuxer()
686 *demuxer = dmux; in CreateRawImageDemuxer()
690 WebPSafeFree(dmux); in CreateRawImageDemuxer()
702 WebPDemuxer* dmux; in WebPDemuxInternal() local
715 status = CreateRawImageDemuxer(&mem, &dmux); in WebPDemuxInternal()
718 return dmux; in WebPDemuxInternal()
731 dmux = (WebPDemuxer*)WebPSafeCalloc(1ULL, sizeof(*dmux)); in WebPDemuxInternal()
732 if (dmux == NULL) return NULL; in WebPDemuxInternal()
733 InitDemux(dmux, &mem); in WebPDemuxInternal()
737 if (!memcmp(parser->id, GetBuffer(&dmux->mem_), TAG_SIZE)) { in WebPDemuxInternal()
738 status = parser->parse(dmux); in WebPDemuxInternal()
739 if (status == PARSE_OK) dmux->state_ = WEBP_DEMUX_DONE; in WebPDemuxInternal()
741 if (status != PARSE_ERROR && !parser->valid(dmux)) status = PARSE_ERROR; in WebPDemuxInternal()
742 if (status == PARSE_ERROR) dmux->state_ = WEBP_DEMUX_PARSE_ERROR; in WebPDemuxInternal()
746 if (state != NULL) *state = dmux->state_; in WebPDemuxInternal()
749 WebPDemuxDelete(dmux); in WebPDemuxInternal()
752 return dmux; in WebPDemuxInternal()
755 void WebPDemuxDelete(WebPDemuxer* dmux) { in WebPDemuxDelete() argument
758 if (dmux == NULL) return; in WebPDemuxDelete()
760 for (f = dmux->frames_; f != NULL;) { in WebPDemuxDelete()
765 for (c = dmux->chunks_; c != NULL;) { in WebPDemuxDelete()
770 WebPSafeFree(dmux); in WebPDemuxDelete()
775 uint32_t WebPDemuxGetI(const WebPDemuxer* dmux, WebPFormatFeature feature) { in WebPDemuxGetI() argument
776 if (dmux == NULL) return 0; in WebPDemuxGetI()
779 case WEBP_FF_FORMAT_FLAGS: return dmux->feature_flags_; in WebPDemuxGetI()
780 case WEBP_FF_CANVAS_WIDTH: return (uint32_t)dmux->canvas_width_; in WebPDemuxGetI()
781 case WEBP_FF_CANVAS_HEIGHT: return (uint32_t)dmux->canvas_height_; in WebPDemuxGetI()
782 case WEBP_FF_LOOP_COUNT: return (uint32_t)dmux->loop_count_; in WebPDemuxGetI()
783 case WEBP_FF_BACKGROUND_COLOR: return dmux->bgcolor_; in WebPDemuxGetI()
784 case WEBP_FF_FRAME_COUNT: return (uint32_t)dmux->num_frames_; in WebPDemuxGetI()
792 static const Frame* GetFrame(const WebPDemuxer* const dmux, int frame_num) { in GetFrame() argument
794 for (f = dmux->frames_; f != NULL; f = f->next_) { in GetFrame()
825 static int SynthesizeFrame(const WebPDemuxer* const dmux, in SynthesizeFrame() argument
828 const uint8_t* const mem_buf = dmux->mem_.buf_; in SynthesizeFrame()
835 iter->num_frames = dmux->num_frames_; in SynthesizeFrame()
852 const WebPDemuxer* const dmux = (WebPDemuxer*)iter->private_; in SetFrame() local
853 if (dmux == NULL || frame_num < 0) return 0; in SetFrame()
854 if (frame_num > dmux->num_frames_) return 0; in SetFrame()
855 if (frame_num == 0) frame_num = dmux->num_frames_; in SetFrame()
857 frame = GetFrame(dmux, frame_num); in SetFrame()
860 return SynthesizeFrame(dmux, frame, iter); in SetFrame()
863 int WebPDemuxGetFrame(const WebPDemuxer* dmux, int frame, WebPIterator* iter) { in WebPDemuxGetFrame() argument
867 iter->private_ = (void*)dmux; in WebPDemuxGetFrame()
889 static int ChunkCount(const WebPDemuxer* const dmux, const char fourcc[4]) { in ChunkCount() argument
890 const uint8_t* const mem_buf = dmux->mem_.buf_; in ChunkCount()
893 for (c = dmux->chunks_; c != NULL; c = c->next_) { in ChunkCount()
900 static const Chunk* GetChunk(const WebPDemuxer* const dmux, in GetChunk() argument
902 const uint8_t* const mem_buf = dmux->mem_.buf_; in GetChunk()
905 for (c = dmux->chunks_; c != NULL; c = c->next_) { in GetChunk()
915 const WebPDemuxer* const dmux = (WebPDemuxer*)iter->private_; in SetChunk() local
918 if (dmux == NULL || fourcc == NULL || chunk_num < 0) return 0; in SetChunk()
919 count = ChunkCount(dmux, fourcc); in SetChunk()
924 const uint8_t* const mem_buf = dmux->mem_.buf_; in SetChunk()
925 const Chunk* const chunk = GetChunk(dmux, fourcc, chunk_num); in SetChunk()
935 int WebPDemuxGetChunk(const WebPDemuxer* dmux, in WebPDemuxGetChunk() argument
941 iter->private_ = (void*)dmux; in WebPDemuxGetChunk()