//------------------------------------------------------------------------------ public bool DecodeImage() { // Initialization. if (state_ != VP8DecodeState.ReadData) { AllocateInternalBuffers32b (io_.width); if (incremental_) { if (hdr_.color_cache_size_ > 0 && hdr_.saved_color_cache_.colors_ == null) { hdr_.saved_color_cache_.Init (hdr_.color_cache_.hash_bits_); } } state_ = VP8DecodeState.ReadData; } // Decode. return DecodeImageData (pixels32_, width_, height_, height_, ProcessRows); }
public bool DecodeImageStream(int xsize, int ysize, bool is_level0, ref uint[] decoded_data, bool set_data) { bool ok = true; int transform_xsize = xsize; int transform_ysize = ysize; int color_cache_bits = 0; uint[] data = null; // Read the transforms (may recurse). if (is_level0) { while (ok && 0 != br_.ReadBits (1)) ok = ReadTransform (ref transform_xsize, ref transform_ysize); } // Color cache if (ok && 0 != br_.ReadBits (1)) { color_cache_bits = (int)br_.ReadBits (4); ok = (color_cache_bits >= 1 && color_cache_bits <= MaxCacheBits); if (!ok) { status_ = VP8StatusCode.BitstreamError; return false; } } // Read the Huffman codes (may recurse). ok = ok && ReadHuffmanCodes (transform_xsize, transform_ysize, color_cache_bits, is_level0); if (!ok) { status_ = VP8StatusCode.BitstreamError; return false; } // Finish setting up the color-cache if (color_cache_bits > 0) { hdr_.color_cache_size_ = 1 << color_cache_bits; hdr_.color_cache_.Init (color_cache_bits); } else { hdr_.color_cache_size_ = 0; } UpdateDecoder (transform_xsize, transform_ysize); if (is_level0) // level 0 complete { state_ = VP8DecodeState.ReadHdr; } else { var total_size = transform_xsize * transform_ysize; data = new uint[total_size]; // Use the Huffman trees to decode the LZ77 encoded data. ok = DecodeImageData (data, transform_xsize, transform_ysize, transform_ysize, null); ok = ok && !br_.EoS; } if (ok) { if (set_data) { decoded_data = data; } last_pixel_ = 0; // Reset for future DECODE_DATA_FUNC() calls. if (!is_level0) hdr_.ClearMetadata(); } return ok; }
public LosslessDecoder() { status_ = VP8StatusCode.Ok; state_ = VP8DecodeState.ReadDim; for (int i = 0; i < transforms_.Length; ++i) transforms_[i] = new VP8LTransform(); }