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()
308 WebPDemuxer* const dmux, uint32_t frame_chunk_size) { in ParseAnimationFrame() argument
309 const int is_animation = !!(dmux->feature_flags_ & ANIMATION_FLAG); in ParseAnimationFrame()
313 MemBuffer* const mem = &dmux->mem_; in ParseAnimationFrame()
335 status = StoreFrame(dmux->num_frames_ + 1, anmf_payload_size, mem, frame); in ParseAnimationFrame()
337 added_frame = AddFrame(dmux, frame); in ParseAnimationFrame()
339 ++dmux->num_frames_; in ParseAnimationFrame()
353 static int StoreChunk(WebPDemuxer* const dmux, in StoreChunk() argument
360 AddChunk(dmux, chunk); in StoreChunk()
392 static ParseStatus ParseSingleImage(WebPDemuxer* const dmux) { in ParseSingleImage() argument
394 MemBuffer* const mem = &dmux->mem_; in ParseSingleImage()
399 if (dmux->frames_ != NULL) return PARSE_ERROR; in ParseSingleImage()
408 status = StoreFrame(1, 0, &dmux->mem_, frame); in ParseSingleImage()
410 const int has_alpha = !!(dmux->feature_flags_ & ALPHA_FLAG); in ParseSingleImage()
420 if (!dmux->is_ext_format_ && frame->width_ > 0 && frame->height_ > 0) { in ParseSingleImage()
421 dmux->state_ = WEBP_DEMUX_PARSED_HEADER; in ParseSingleImage()
422 dmux->canvas_width_ = frame->width_; in ParseSingleImage()
423 dmux->canvas_height_ = frame->height_; in ParseSingleImage()
424 dmux->feature_flags_ |= frame->has_alpha_ ? ALPHA_FLAG : 0; in ParseSingleImage()
426 if (!AddFrame(dmux, frame)) { in ParseSingleImage()
430 dmux->num_frames_ = 1; in ParseSingleImage()
438 static ParseStatus ParseVP8XChunks(WebPDemuxer* const dmux) { in ParseVP8XChunks() argument
439 const int is_animation = !!(dmux->feature_flags_ & ANIMATION_FLAG); in ParseVP8XChunks()
440 MemBuffer* const mem = &dmux->mem_; in ParseVP8XChunks()
465 status = ParseSingleImage(dmux); in ParseVP8XChunks()
475 dmux->bgcolor_ = ReadLE32(mem); in ParseVP8XChunks()
476 dmux->loop_count_ = ReadLE16s(mem); in ParseVP8XChunks()
486 status = ParseAnimationFrame(dmux, chunk_size_padded); in ParseVP8XChunks()
490 store_chunk = !!(dmux->feature_flags_ & ICCP_FLAG); in ParseVP8XChunks()
494 store_chunk = !!(dmux->feature_flags_ & EXIF_FLAG); in ParseVP8XChunks()
498 store_chunk = !!(dmux->feature_flags_ & XMP_FLAG); in ParseVP8XChunks()
507 if (!StoreChunk(dmux, chunk_start_offset, in ParseVP8XChunks()
529 static ParseStatus ParseVP8X(WebPDemuxer* const dmux) { in ParseVP8X() argument
530 MemBuffer* const mem = &dmux->mem_; in ParseVP8X()
535 dmux->is_ext_format_ = 1; in ParseVP8X()
544 dmux->feature_flags_ = ReadByte(mem); in ParseVP8X()
546 dmux->canvas_width_ = 1 + ReadLE24s(mem); in ParseVP8X()
547 dmux->canvas_height_ = 1 + ReadLE24s(mem); in ParseVP8X()
548 if (dmux->canvas_width_ * (uint64_t)dmux->canvas_height_ >= MAX_IMAGE_AREA) { in ParseVP8X()
552 dmux->state_ = WEBP_DEMUX_PARSED_HEADER; in ParseVP8X()
557 return ParseVP8XChunks(dmux); in ParseVP8X()
563 static int IsValidSimpleFormat(const WebPDemuxer* const dmux) { in IsValidSimpleFormat() argument
564 const Frame* const frame = dmux->frames_; in IsValidSimpleFormat()
565 if (dmux->state_ == WEBP_DEMUX_PARSING_HEADER) return 1; in IsValidSimpleFormat()
567 if (dmux->canvas_width_ <= 0 || dmux->canvas_height_ <= 0) return 0; in IsValidSimpleFormat()
568 if (dmux->state_ == WEBP_DEMUX_DONE && frame == NULL) return 0; in IsValidSimpleFormat()
593 static int IsValidExtendedFormat(const WebPDemuxer* const dmux) { in IsValidExtendedFormat() argument
594 const int is_animation = !!(dmux->feature_flags_ & ANIMATION_FLAG); in IsValidExtendedFormat()
595 const Frame* f = dmux->frames_; in IsValidExtendedFormat()
597 if (dmux->state_ == WEBP_DEMUX_PARSING_HEADER) return 1; in IsValidExtendedFormat()
599 if (dmux->canvas_width_ <= 0 || dmux->canvas_height_ <= 0) return 0; in IsValidExtendedFormat()
600 if (dmux->loop_count_ < 0) return 0; in IsValidExtendedFormat()
601 if (dmux->state_ == WEBP_DEMUX_DONE && dmux->frames_ == NULL) return 0; in IsValidExtendedFormat()
602 if (dmux->feature_flags_ & ~ALL_VALID_FLAGS) return 0; // invalid bitstream in IsValidExtendedFormat()
625 if (dmux->state_ == WEBP_DEMUX_DONE) return 0; in IsValidExtendedFormat()
638 dmux->canvas_width_, dmux->canvas_height_)) { in IsValidExtendedFormat()
651 static void InitDemux(WebPDemuxer* const dmux, const MemBuffer* const mem) { in InitDemux() argument
652 dmux->state_ = WEBP_DEMUX_PARSING_HEADER; in InitDemux()
653 dmux->loop_count_ = 1; in InitDemux()
654 dmux->bgcolor_ = 0xFFFFFFFF; // White background by default. in InitDemux()
655 dmux->canvas_width_ = -1; in InitDemux()
656 dmux->canvas_height_ = -1; in InitDemux()
657 dmux->frames_tail_ = &dmux->frames_; in InitDemux()
658 dmux->chunks_tail_ = &dmux->chunks_; in InitDemux()
659 dmux->mem_ = *mem; in InitDemux()
674 WebPDemuxer* const dmux = (WebPDemuxer*)WebPSafeCalloc(1ULL, sizeof(*dmux)); in CreateRawImageDemuxer() local
676 if (dmux == NULL || frame == NULL) goto Error; in CreateRawImageDemuxer()
677 InitDemux(dmux, mem); in CreateRawImageDemuxer()
680 if (!AddFrame(dmux, frame)) goto Error; in CreateRawImageDemuxer()
681 dmux->state_ = WEBP_DEMUX_DONE; in CreateRawImageDemuxer()
682 dmux->canvas_width_ = frame->width_; in CreateRawImageDemuxer()
683 dmux->canvas_height_ = frame->height_; in CreateRawImageDemuxer()
684 dmux->feature_flags_ |= frame->has_alpha_ ? ALPHA_FLAG : 0; in CreateRawImageDemuxer()
685 dmux->num_frames_ = 1; in CreateRawImageDemuxer()
686 assert(IsValidSimpleFormat(dmux)); in CreateRawImageDemuxer()
687 *demuxer = dmux; in CreateRawImageDemuxer()
691 WebPSafeFree(dmux); in CreateRawImageDemuxer()
703 WebPDemuxer* dmux; in WebPDemuxInternal() local
716 status = CreateRawImageDemuxer(&mem, &dmux); in WebPDemuxInternal()
719 return dmux; in WebPDemuxInternal()
732 dmux = (WebPDemuxer*)WebPSafeCalloc(1ULL, sizeof(*dmux)); in WebPDemuxInternal()
733 if (dmux == NULL) return NULL; in WebPDemuxInternal()
734 InitDemux(dmux, &mem); in WebPDemuxInternal()
738 if (!memcmp(parser->id, GetBuffer(&dmux->mem_), TAG_SIZE)) { in WebPDemuxInternal()
739 status = parser->parse(dmux); in WebPDemuxInternal()
740 if (status == PARSE_OK) dmux->state_ = WEBP_DEMUX_DONE; in WebPDemuxInternal()
742 if (status != PARSE_ERROR && !parser->valid(dmux)) status = PARSE_ERROR; in WebPDemuxInternal()
743 if (status == PARSE_ERROR) dmux->state_ = WEBP_DEMUX_PARSE_ERROR; in WebPDemuxInternal()
747 if (state != NULL) *state = dmux->state_; in WebPDemuxInternal()
750 WebPDemuxDelete(dmux); in WebPDemuxInternal()
753 return dmux; in WebPDemuxInternal()
756 void WebPDemuxDelete(WebPDemuxer* dmux) { in WebPDemuxDelete() argument
759 if (dmux == NULL) return; in WebPDemuxDelete()
761 for (f = dmux->frames_; f != NULL;) { in WebPDemuxDelete()
766 for (c = dmux->chunks_; c != NULL;) { in WebPDemuxDelete()
771 WebPSafeFree(dmux); in WebPDemuxDelete()
776 uint32_t WebPDemuxGetI(const WebPDemuxer* dmux, WebPFormatFeature feature) { in WebPDemuxGetI() argument
777 if (dmux == NULL) return 0; in WebPDemuxGetI()
780 case WEBP_FF_FORMAT_FLAGS: return dmux->feature_flags_; in WebPDemuxGetI()
781 case WEBP_FF_CANVAS_WIDTH: return (uint32_t)dmux->canvas_width_; in WebPDemuxGetI()
782 case WEBP_FF_CANVAS_HEIGHT: return (uint32_t)dmux->canvas_height_; in WebPDemuxGetI()
783 case WEBP_FF_LOOP_COUNT: return (uint32_t)dmux->loop_count_; in WebPDemuxGetI()
784 case WEBP_FF_BACKGROUND_COLOR: return dmux->bgcolor_; in WebPDemuxGetI()
785 case WEBP_FF_FRAME_COUNT: return (uint32_t)dmux->num_frames_; in WebPDemuxGetI()
793 static const Frame* GetFrame(const WebPDemuxer* const dmux, int frame_num) { in GetFrame() argument
795 for (f = dmux->frames_; f != NULL; f = f->next_) { in GetFrame()
826 static int SynthesizeFrame(const WebPDemuxer* const dmux, in SynthesizeFrame() argument
829 const uint8_t* const mem_buf = dmux->mem_.buf_; in SynthesizeFrame()
836 iter->num_frames = dmux->num_frames_; in SynthesizeFrame()
853 const WebPDemuxer* const dmux = (WebPDemuxer*)iter->private_; in SetFrame() local
854 if (dmux == NULL || frame_num < 0) return 0; in SetFrame()
855 if (frame_num > dmux->num_frames_) return 0; in SetFrame()
856 if (frame_num == 0) frame_num = dmux->num_frames_; in SetFrame()
858 frame = GetFrame(dmux, frame_num); in SetFrame()
861 return SynthesizeFrame(dmux, frame, iter); in SetFrame()
864 int WebPDemuxGetFrame(const WebPDemuxer* dmux, int frame, WebPIterator* iter) { in WebPDemuxGetFrame() argument
868 iter->private_ = (void*)dmux; in WebPDemuxGetFrame()
890 static int ChunkCount(const WebPDemuxer* const dmux, const char fourcc[4]) { in ChunkCount() argument
891 const uint8_t* const mem_buf = dmux->mem_.buf_; in ChunkCount()
894 for (c = dmux->chunks_; c != NULL; c = c->next_) { in ChunkCount()
901 static const Chunk* GetChunk(const WebPDemuxer* const dmux, in GetChunk() argument
903 const uint8_t* const mem_buf = dmux->mem_.buf_; in GetChunk()
906 for (c = dmux->chunks_; c != NULL; c = c->next_) { in GetChunk()
916 const WebPDemuxer* const dmux = (WebPDemuxer*)iter->private_; in SetChunk() local
919 if (dmux == NULL || fourcc == NULL || chunk_num < 0) return 0; in SetChunk()
920 count = ChunkCount(dmux, fourcc); in SetChunk()
925 const uint8_t* const mem_buf = dmux->mem_.buf_; in SetChunk()
926 const Chunk* const chunk = GetChunk(dmux, fourcc, chunk_num); in SetChunk()
936 int WebPDemuxGetChunk(const WebPDemuxer* dmux, in WebPDemuxGetChunk() argument
942 iter->private_ = (void*)dmux; in WebPDemuxGetChunk()