//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; }
//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); }