protected static void ProgressiveDeQuantization_Component(short[] data, RFX_COMPONMENT_CODEC_QUANT quant, bool useReduceExtrapolate) { int bitPos = 0; for (int i = 0; i < RdpegfxTileUtils.ComponentElementCount; i++) { BandType_Values band = RdpegfxTileUtils.GetBandByIndex(i, useReduceExtrapolate); bitPos = RdpegfxTileUtils.GetBitPosFromQuant(quant, band); data[i] = FunProgDeQ(data[i], bitPos, band); } }
//SRLEncode public static EncodedTile SRLEncode(RfxProgressiveCodecContext encodingContext, Rdpegfx.RFX_PROGRESSIVE_CODEC_QUANT progQuant) { SRLEncoder encoder = new SRLEncoder(); List <short> yDataToSrl = new List <short>(); List <short> cbDataToSrl = new List <short>(); List <short> crDataToSrl = new List <short>(); List <int> yDataToSrlBitLen = new List <int>(); List <int> cbDataToSrlBitLen = new List <int>(); List <int> crDataToSrlBitLen = new List <int>(); BitStream yRawBitStream = new BitStream(); BitStream cbRawBitStream = new BitStream(); BitStream crRawBitStream = new BitStream(); int nonLL3Len = RdpegfxTileUtils.ComponentElementCount - RdpegfxTileUtils.GetBandSize(BandType_Values.LL3, encodingContext.UseReduceExtrapolate); Rdpegfx.RFX_PROGRESSIVE_CODEC_QUANT prevProgQuant = encodingContext.prevProgQuant; Rdpegfx.RFX_PROGRESSIVE_CODEC_QUANT curProgQuant = progQuant; for (int i = 0; i < RdpegfxTileUtils.ComponentElementCount; i++) { BandType_Values band = RdpegfxTileUtils.GetBandByIndex(i, encodingContext.UseReduceExtrapolate); int targetBitPos = RdpegfxTileUtils.GetBitPosFromQuant(curProgQuant.yQuantValues, band); int prevBitPos = RdpegfxTileUtils.GetBitPosFromQuant(prevProgQuant.yQuantValues, band); int bitCount = prevBitPos - targetBitPos; if (bitCount > 0) { if (encodingContext.DAS.Y_DwtQ[i] == 0 && i < nonLL3Len) { yDataToSrl.Add(encodingContext.ProgQ.Y_DwtQ[i]); yDataToSrlBitLen.Add(bitCount); } else { //Add raw data yRawBitStream.WriteBits(bitCount, Math.Abs(encodingContext.ProgQ.Y_DwtQ[i])); } } targetBitPos = RdpegfxTileUtils.GetBitPosFromQuant(curProgQuant.cbQuantValues, band); prevBitPos = RdpegfxTileUtils.GetBitPosFromQuant(prevProgQuant.cbQuantValues, band); bitCount = prevBitPos - targetBitPos; if (bitCount > 0) { if (encodingContext.DAS.Cb_DwtQ[i] == 0 && i < nonLL3Len) { cbDataToSrl.Add(encodingContext.ProgQ.Cb_DwtQ[i]); cbDataToSrlBitLen.Add(bitCount); } else { //Add raw data cbRawBitStream.WriteBits(bitCount, Math.Abs(encodingContext.ProgQ.Cb_DwtQ[i])); } } targetBitPos = RdpegfxTileUtils.GetBitPosFromQuant(curProgQuant.crQuantValues, band); prevBitPos = RdpegfxTileUtils.GetBitPosFromQuant(curProgQuant.crQuantValues, band); bitCount = prevBitPos - targetBitPos; if (bitCount > 0) { if (encodingContext.DAS.Cr_DwtQ[i] == 0 && i < nonLL3Len) { crDataToSrl.Add(encodingContext.ProgQ.Cr_DwtQ[i]); crDataToSrlBitLen.Add(bitCount); } else { //Add raw data crRawBitStream.WriteBits(bitCount, Math.Abs(encodingContext.ProgQ.Cr_DwtQ[i])); } } } encodingContext.YData = encoder.Encode(yDataToSrl.ToArray(), yDataToSrlBitLen.ToArray()); encodingContext.CbData = encoder.Encode(cbDataToSrl.ToArray(), cbDataToSrlBitLen.ToArray()); encodingContext.CrData = encoder.Encode(crDataToSrl.ToArray(), crDataToSrlBitLen.ToArray()); EncodedTile ugTile = new EncodedTile(); ugTile.YEncodedData = (byte[])encodingContext.YData.Clone(); ugTile.CbEncodedData = (byte[])encodingContext.CbData.Clone(); ugTile.CrEncodedData = (byte[])encodingContext.CrData.Clone(); ugTile.YRawData = yRawBitStream.ToBytes(); ugTile.CbRawData = cbRawBitStream.ToBytes(); ugTile.CrRawData = crRawBitStream.ToBytes(); ugTile.DataType = EncodedTileType.UpgradePass; ugTile.IsDifferenceTile = encodingContext.UseDifferenceTile; ugTile.UseReduceExtrapolate = encodingContext.UseReduceExtrapolate; ugTile.CodecQuantVals = encodingContext.CodecQuantVals; ugTile.QuantIdxY = encodingContext.QuantIdxY; ugTile.QuantIdxCb = encodingContext.QuantIdxCb; ugTile.QuantIdxCr = encodingContext.QuantIdxCr; ugTile.ProgCodecQuant = curProgQuant; return(ugTile); }
public static void SRLDecode(RfxProgressiveCodecContext codecContext, EncodedTile enTile, TileState tState) { SRLDecoder yDecoder = null; SRLDecoder cbDecoder = null; SRLDecoder crDecoder = null; List <short> yData = new List <short>(); List <short> cbData = new List <short>(); List <short> crData = new List <short>(); DwtTile triState = tState.GetTriState(); RFX_PROGRESSIVE_CODEC_QUANT prvProgQuant = tState.GetDwt().ProgCodecQuant; int nonLL3Len = RdpegfxTileUtils.ComponentElementCount - RdpegfxTileUtils.GetBandSize(BandType_Values.LL3, enTile.UseReduceExtrapolate); if (enTile.YEncodedData != null) { yDecoder = new SRLDecoder(enTile.YEncodedData); } if (enTile.CbEncodedData != null) { cbDecoder = new SRLDecoder(enTile.CbEncodedData); } if (enTile.CrEncodedData != null) { crDecoder = new SRLDecoder(enTile.CrEncodedData); } BitStream yRaw = BitStream.GetFromBytes(enTile.YRawData); BitStream cbRaw = BitStream.GetFromBytes(enTile.CbRawData); BitStream crRaw = BitStream.GetFromBytes(enTile.CrRawData); for (int i = 0; i < RdpegfxTileUtils.ComponentElementCount; i++) { BandType_Values band = RdpegfxTileUtils.GetBandByIndex(i, enTile.UseReduceExtrapolate); //Y int curBitPos = RdpegfxTileUtils.GetBitPosFromQuant(enTile.ProgCodecQuant.yQuantValues, band); int prvBitPos = RdpegfxTileUtils.GetBitPosFromQuant(prvProgQuant.yQuantValues, band); int bitCount = prvBitPos - curBitPos; int sign = triState.Y_DwtQ[i]; if (bitCount > 0) { if (sign == 0 && i < nonLL3Len) { if (yDecoder != null) { short?decodedValue = yDecoder.DecodeOne(bitCount); if (decodedValue.HasValue) { yData.Add(decodedValue.Value); } else { yData.Add(0); } } else { yData.Add(0); } } else { int output; if (yRaw.ReadInt32(bitCount, out output)) { if (sign < 0 && i < nonLL3Len) { output = -output; } yData.Add((short)output); } else { yData.Add(0); } } } else { yData.Add(0); } //Cb curBitPos = RdpegfxTileUtils.GetBitPosFromQuant(enTile.ProgCodecQuant.cbQuantValues, band); prvBitPos = RdpegfxTileUtils.GetBitPosFromQuant(prvProgQuant.cbQuantValues, band); bitCount = prvBitPos - curBitPos; sign = triState.Cb_DwtQ[i]; if (bitCount > 0) { if (sign == 0 && i < nonLL3Len) { if (cbDecoder != null) { short?decodedValue = cbDecoder.DecodeOne(bitCount); if (decodedValue.HasValue) { cbData.Add(decodedValue.Value); } else { cbData.Add(0); } } else { cbData.Add(0); } } else { int output; if (cbRaw.ReadInt32(bitCount, out output)) { if (sign < 0 && i < nonLL3Len) { output = -output; } cbData.Add((short)output); } else { cbData.Add(0); } } } else { cbData.Add(0); } //cr curBitPos = RdpegfxTileUtils.GetBitPosFromQuant(enTile.ProgCodecQuant.crQuantValues, band); prvBitPos = RdpegfxTileUtils.GetBitPosFromQuant(prvProgQuant.crQuantValues, band); bitCount = prvBitPos - curBitPos; sign = triState.Cr_DwtQ[i]; if (bitCount > 0) { if (sign == 0 && i < nonLL3Len) { if (crDecoder != null) { short?decodedValue = crDecoder.DecodeOne(bitCount); if (decodedValue.HasValue) { crData.Add(decodedValue.Value); } else { crData.Add(0); } } else { crData.Add(0); } } else { int output; if (crRaw.ReadInt32(bitCount, out output)) { if (sign < 0 && i < nonLL3Len) { output = -output; } crData.Add((short)output); } else { crData.Add(0); } } } else { crData.Add(0); } } codecContext.YComponent = yData.ToArray(); codecContext.CbComponent = cbData.ToArray(); codecContext.CrComponent = crData.ToArray(); }