public List <byte> Compress() { List <Block <short> > yccChannels = ColourConverter.BitmapRGBToYCC(this.bitmap, 8); Block <short> cbCulled = yccChannels[1].CullBlockToBlockFactor(2, 8); Block <short> crCulled = yccChannels[2].CullBlockToBlockFactor(2, 8); List <Block <short> > yBlocks = DCT.DCTChannel(yccChannels[0], 8); List <Block <short> > cbBlocks = DCT.DCTChannel(cbCulled, 8); List <Block <short> > crBlocks = DCT.DCTChannel(crCulled, 8); Quantizer quantizer = new Quantizer(); List <byte> yStream = RunLength.RLE(yBlocks, quantizer.GetLumiQT()); List <byte> cbStream = RunLength.RLE(cbBlocks, quantizer.GetChromaQT()); List <byte> crStream = RunLength.RLE(crBlocks, quantizer.GetChromaQT()); yStream.AddRange(cbStream); yStream.AddRange(crStream); return(yStream); }
public Bitmap Decompress() { // Load blocks Quantizer quantizer = new Quantizer(); List <List <Block <short> > > channelBlocks = RunLength.RLD(compressedData, 8, width, height, quantizer.GetLumiQT(), quantizer.GetChromaQT()); Block <byte> yChannel = DCT.IDCTChannel(channelBlocks[0], width, height); Block <byte> cbChannel = DCT.IDCTChannel(channelBlocks[1], width / 2, height / 2); Block <byte> crChannel = DCT.IDCTChannel(channelBlocks[2], width / 2, height / 2); Block <byte> cbPadded = cbChannel.PadBlock(2); Block <byte> crPadded = crChannel.PadBlock(2); List <byte> uncompressed = LoadImageData(yChannel, cbPadded, crPadded); return(CreateBitmapFromBytes(width, height, uncompressed)); }