//Compute the difference tile dwt public static void SubBandDiffing_DT(RfxProgressiveCodecContext encodingContext, TileState enTileInfo) { if (encodingContext.UseDifferenceTile) { DwtTile oldDwt = enTileInfo.GetOldDwt(); if (oldDwt != null) { short[] yDiffDwt, cbDiffDwt, crDiffDwt; int lenOfNonLL3Band = (RdpegfxTileUtils.ComponentElementCount - RdpegfxTileUtils.GetBandSize(BandType_Values.LL3, encodingContext.UseReduceExtrapolate));// ? 81 : 64; int yNewZeroCount, cbNewZeroCount, crNewZeroCount; int yDiffZeroCount, cbDiffZeroCount, crDiffZeroCount; yDiffDwt = RdpegfxTileUtils.SubDiffingDwt(encodingContext.YComponent, oldDwt.Y_DwtQ, lenOfNonLL3Band, out yNewZeroCount, out yDiffZeroCount); cbDiffDwt = RdpegfxTileUtils.SubDiffingDwt(encodingContext.CbComponent, oldDwt.Cb_DwtQ, lenOfNonLL3Band, out cbNewZeroCount, out cbDiffZeroCount); crDiffDwt = RdpegfxTileUtils.SubDiffingDwt(encodingContext.CrComponent, oldDwt.Cr_DwtQ, lenOfNonLL3Band, out crNewZeroCount, out crDiffZeroCount); if ((yDiffDwt != null && cbDiffDwt != null && crDiffDwt != null) && (yNewZeroCount + cbNewZeroCount + crNewZeroCount < yDiffZeroCount + cbDiffZeroCount + crDiffZeroCount)) {//use difference tile encodingContext.YComponent = yDiffDwt; encodingContext.CbComponent = cbDiffDwt; encodingContext.CrComponent = crDiffDwt; return; } } } encodingContext.UseDifferenceTile = false;//use orginal tile }
/// <summary> /// Encode the surface with Progressive Codec /// </summary> /// <param name="quality">The target encoded quality.</param> /// <param name="bProg">Indicates if encode progressively</param> /// <param name="bSubDiff">Indicates if sub-diffing with last frame of this surface</param> /// <param name="bReduceExtrapolate">Indicates if use Reduce Extrapolate method in DWT step.</param> /// <returns>The dictionary of tile index and encoded tile datas.</returns> public Dictionary <TileIndex, EncodedTile[]> ProgressiveEncode(ImageQuality_Values quality, bool bProg, bool bSubDiff, bool bReduceExtrapolate, bool ignoreUnchangedTile = true) { Dictionary <TileIndex, EncodedTile[]> encodedTileDic = new Dictionary <TileIndex, EncodedTile[]>(); TS_RFX_CODEC_QUANT quant = RdpegfxTileUtils.GetCodecQuant(quality); TileIndex[] tileIndexArr; if (!ignoreUnchangedTile) { tileIndexArr = GetAllIndexes(); } else { tileIndexArr = GetDiffIndexes(true); } foreach (TileIndex index in tileIndexArr) { RfxProgressiveCodecContext codecContext = new RfxProgressiveCodecContext( new TS_RFX_CODEC_QUANT[] { quant }, 0, // quantization index of Y, set this paramter to 0 since only one quantization value in the array 0, // quantization index of Cb 0, // quantization index of Cr bProg, //progressive bSubDiff, //sub-diffing bReduceExtrapolate); //reduce extrapolate TileState tState = new TileState(this, index); encodedTileDic.Add(index, RfxProgressiveEncoder.EncodeTile(codecContext, tState)); } return(encodedTileDic); }
public static void ComputeOriginalLL3FromDeltas(RfxProgressiveCodecContext codecContext) { int ll3Len = RdpegfxTileUtils.GetBandSize(BandType_Values.LL3, codecContext.UseReduceExtrapolate); int ll3Idx = RdpegfxTileUtils.ComponentElementCount - ll3Len; for (int i = ll3Idx + 1; i < RdpegfxTileUtils.ComponentElementCount; i++) { codecContext.YComponent[i] = (short)(codecContext.YComponent[i] + codecContext.YComponent[i - 1]); codecContext.CbComponent[i] = (short)(codecContext.CbComponent[i] + codecContext.CbComponent[i - 1]); codecContext.CrComponent[i] = (short)(codecContext.CrComponent[i] + codecContext.CrComponent[i - 1]); } }
public static void ComputeOriginalLL3FromDeltas(RfxProgressiveCodecContext codecContext) { int ll3Len = RdpegfxTileUtils.GetBandSize(BandType_Values.LL3, codecContext.UseReduceExtrapolate); int ll3Idx = RdpegfxTileUtils.ComponentElementCount - ll3Len; for (int i = ll3Idx + 1; i < RdpegfxTileUtils.ComponentElementCount; i++) { codecContext.YComponent[i] = (short)(codecContext.YComponent[i] + codecContext.YComponent[i - 1]); codecContext.CbComponent[i] = (short)(codecContext.CbComponent[i] + codecContext.CbComponent[i - 1]); codecContext.CrComponent[i] = (short)(codecContext.CrComponent[i] + codecContext.CrComponent[i - 1]); } }
public static void ComputeLL3Deltas(RfxProgressiveCodecContext encodingContext) { int ll3Len = RdpegfxTileUtils.GetBandSize(BandType_Values.LL3, encodingContext.UseReduceExtrapolate); int ll3Idx = RdpegfxTileUtils.ComponentElementCount - ll3Len; //for (int i = ll3Idx + 1; i < TileUtils.ComponentElementCount; i++) for (int i = RdpegfxTileUtils.ComponentElementCount - 1; i >= ll3Idx + 1; i--) { encodingContext.YComponent[i] = (short)(encodingContext.YComponent[i] - encodingContext.YComponent[i - 1]); encodingContext.CbComponent[i] = (short)(encodingContext.CbComponent[i] - encodingContext.CbComponent[i - 1]); encodingContext.CrComponent[i] = (short)(encodingContext.CrComponent[i] - encodingContext.CrComponent[i - 1]); } }
public static void ComputeLL3Deltas(RfxProgressiveCodecContext encodingContext) { int ll3Len = RdpegfxTileUtils.GetBandSize(BandType_Values.LL3, encodingContext.UseReduceExtrapolate); int ll3Idx = RdpegfxTileUtils.ComponentElementCount - ll3Len; //for (int i = ll3Idx + 1; i < TileUtils.ComponentElementCount; i++) for (int i = RdpegfxTileUtils.ComponentElementCount - 1; i >= ll3Idx + 1; i--) { encodingContext.YComponent[i] = (short)(encodingContext.YComponent[i] - encodingContext.YComponent[i - 1]); encodingContext.CbComponent[i] = (short)(encodingContext.CbComponent[i] - encodingContext.CbComponent[i - 1]); encodingContext.CrComponent[i] = (short)(encodingContext.CrComponent[i] - encodingContext.CrComponent[i - 1]); } }
static DwtTile GetDTS(RfxProgressiveCodecContext encodingContext, ProgressiveChunk_Values chunk) { DwtBands yBD = DwtBands.GetFromLinearizationResult(encodingContext.DRS.Y_DwtQ, encodingContext.UseReduceExtrapolate); DwtBands cbBD = DwtBands.GetFromLinearizationResult(encodingContext.DRS.Cb_DwtQ, encodingContext.UseReduceExtrapolate); DwtBands crBD = DwtBands.GetFromLinearizationResult(encodingContext.DRS.Cr_DwtQ, encodingContext.UseReduceExtrapolate); DTS_Component(yBD, TileComponents.Y, chunk); DTS_Component(cbBD, TileComponents.Cb, chunk); DTS_Component(crBD, TileComponents.Cr, chunk); DwtTile dwtDts = new DwtTile(yBD.GetLinearizationData(), cbBD.GetLinearizationData(), crBD.GetLinearizationData()); return(dwtDts); }
public static void ProgressiveQuantization(RfxProgressiveCodecContext encodingContext, ProgressiveChunk_Values chunk) { DwtBands yBD = DwtBands.GetFromLinearizationResult(encodingContext.DRS.Y_DwtQ, encodingContext.UseReduceExtrapolate); DwtBands cbBD = DwtBands.GetFromLinearizationResult(encodingContext.DRS.Cb_DwtQ, encodingContext.UseReduceExtrapolate); DwtBands crBD = DwtBands.GetFromLinearizationResult(encodingContext.DRS.Cr_DwtQ, encodingContext.UseReduceExtrapolate); ProgressiveQuantization_Component(yBD, TileComponents.Y, chunk); ProgressiveQuantization_Component(cbBD, TileComponents.Cb, chunk); ProgressiveQuantization_Component(crBD, TileComponents.Cr, chunk); DwtTile dwtDts = new DwtTile(yBD.GetLinearizationData(), cbBD.GetLinearizationData(), crBD.GetLinearizationData()); encodingContext.ProgQ = dwtDts; //Compute DTS encodingContext.DTS = GetDTS(encodingContext, chunk); }
/// <summary> /// Decode a tile from DWT /// </summary> /// <param name="codecContext">The codec context which contains the DWT data of a tile.</param> public static void DecodeTileFromDwtQ(RfxProgressiveCodecContext codecContext) { //Sub Band Reconstruction SubBandReconstruction(codecContext); //De-quantization Dequantization(codecContext); //Inverse DWT if (codecContext.UseReduceExtrapolate) { InverseDWT(codecContext); } else { RemoteFXDecoder.InverseDWT(codecContext); } //(Y, U, V) to (R, G, B) RemoteFXDecoder.YCbCrToRGB(codecContext); }
/// <summary> /// Decode and Render the tile to an image /// </summary> /// <returns>The image rendered from tile</returns> public Bitmap ToImage() { Bitmap tileImg = new Bitmap(RdpegfxTileUtils.TileSize, RdpegfxTileUtils.TileSize); RfxProgressiveCodecContext codecContext = new RfxProgressiveCodecContext(this.CodecQuantVals, this.QuantIdxY, this.QuantIdxCb, this.QuantIdxCr, UseReduceExtrapolate); codecContext.YComponent = new short[Y_DwtQ.Length]; codecContext.CbComponent = new short[Cb_DwtQ.Length]; codecContext.CrComponent = new short[Cr_DwtQ.Length]; Y_DwtQ.CopyTo(codecContext.YComponent, 0); Cb_DwtQ.CopyTo(codecContext.CbComponent, 0); Cr_DwtQ.CopyTo(codecContext.CrComponent, 0); RfxProgressiveDecoder.DecodeTileFromDwtQ(codecContext); BitmapData bmpData = tileImg.LockBits(new Rectangle(0, 0, tileImg.Width, tileImg.Height), ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb); unsafe { byte *cusor = (byte *)bmpData.Scan0.ToPointer(); for (int y = 0; y < bmpData.Height; y++) { for (int x = 0; x < bmpData.Width; x++) { cusor[0] = codecContext.BSet[x, y]; cusor[1] = codecContext.GSet[x, y]; cusor[2] = codecContext.RSet[x, y]; cusor += 3; } cusor += (bmpData.Stride - 3 * (bmpData.Width)); } } tileImg.UnlockBits(bmpData); return(tileImg); }
public static void Linearization_NoLL3Delta(RfxProgressiveCodecContext encodingContext) { linearization_Compontent(encodingContext.YSet, encodingContext.UseReduceExtrapolate, out encodingContext.YComponent); linearization_Compontent(encodingContext.CbSet, encodingContext.UseReduceExtrapolate, out encodingContext.CbComponent); linearization_Compontent(encodingContext.CrSet, encodingContext.UseReduceExtrapolate, out encodingContext.CrComponent); }
public static void Quantization(RfxProgressiveCodecContext encodingContext) { doQuantization_Component(encodingContext.YSet, encodingContext.CodecQuantVals[encodingContext.QuantIdxY], encodingContext.UseReduceExtrapolate); doQuantization_Component(encodingContext.CbSet, encodingContext.CodecQuantVals[encodingContext.QuantIdxCb], encodingContext.UseReduceExtrapolate); doQuantization_Component(encodingContext.CrSet, encodingContext.CodecQuantVals[encodingContext.QuantIdxCr], encodingContext.UseReduceExtrapolate); }
/// <summary> /// Encode a Tile /// </summary> /// <param name="encodingContext">The tile encoding context</param> /// <param name="enTileInfo">The tile to be encoded</param> /// <returns>A array of CompressedTile which contains the encoded tiles</returns> public static EncodedTile[] EncodeTile(RfxProgressiveCodecContext encodingContext, TileState enTileInfo) { EncodedTileType targetType = encodingContext.UseProgressive ? EncodedTileType.FirstPass : EncodedTileType.Simple; //File RGB FillRgbData(encodingContext, enTileInfo.GetRgb()); //Do color conversion RemoteFXEncoder.RGBToYCbCr(encodingContext); //Do DWT if (encodingContext.UseReduceExtrapolate) { //Do DWT using UseReduce Extrapolate method DWT(encodingContext); } else { RemoteFXEncoder.DWT(encodingContext); } //Do quantiztion Quantization(encodingContext); //Do linearization (LL3 delta not computed) Linearization_NoLL3Delta(encodingContext); //Update new DWT to tile DwtTile dwt = new DwtTile( (short[])encodingContext.YComponent.Clone(), (short[])encodingContext.CbComponent.Clone(), (short[])encodingContext.CrComponent.Clone(), encodingContext.CodecQuantVals, encodingContext.QuantIdxY, encodingContext.QuantIdxCb, encodingContext.QuantIdxCr, encodingContext.UseReduceExtrapolate ); enTileInfo.UpdateDwt(dwt); //Sub-Band Diffing if (encodingContext.UseDifferenceTile) { SubBandDiffing_DT(encodingContext, enTileInfo); } if (targetType == EncodedTileType.Simple) { ComputeLL3Deltas(encodingContext); RemoteFXEncoder.RLGREncode(encodingContext); EncodedTile cpTile = new EncodedTile(); cpTile.YEncodedData = (byte[])encodingContext.YData.Clone(); cpTile.CbEncodedData = (byte[])encodingContext.CbData.Clone(); cpTile.CrEncodedData = (byte[])encodingContext.CrData.Clone(); cpTile.DataType = EncodedTileType.Simple; cpTile.IsDifferenceTile = encodingContext.UseDifferenceTile; cpTile.UseReduceExtrapolate = encodingContext.UseReduceExtrapolate; cpTile.CodecQuantVals = encodingContext.CodecQuantVals; cpTile.QuantIdxY = encodingContext.QuantIdxY; cpTile.QuantIdxCb = encodingContext.QuantIdxCb; cpTile.QuantIdxCr = encodingContext.QuantIdxCr; cpTile.ProgCodecQuant = null; return(new EncodedTile[] { cpTile }); } else { List <EncodedTile> progCTileList = new List <EncodedTile>(); //Init DRS, DAS encodingContext.DRS = new DwtTile(encodingContext.YComponent, encodingContext.CbComponent, encodingContext.CrComponent); encodingContext.DAS = new DwtTile(new short[RdpegfxTileUtils.ComponentElementCount], new short[RdpegfxTileUtils.ComponentElementCount], new short[RdpegfxTileUtils.ComponentElementCount]); #region Chunk 25, first pass ProgressiveQuantization(encodingContext, ProgressiveChunk_Values.kChunk_25); //Compute ProgQ LL3 deltas encodingContext.YComponent = encodingContext.ProgQ.Y_DwtQ; encodingContext.CbComponent = encodingContext.ProgQ.Cb_DwtQ; encodingContext.CrComponent = encodingContext.ProgQ.Cr_DwtQ; ComputeLL3Deltas(encodingContext); RemoteFXEncoder.RLGREncode(encodingContext); EncodedTile firstPassTile = new EncodedTile(); firstPassTile.YEncodedData = (byte[])encodingContext.YData.Clone(); firstPassTile.CbEncodedData = (byte[])encodingContext.CbData.Clone(); firstPassTile.CrEncodedData = (byte[])encodingContext.CrData.Clone(); firstPassTile.DataType = EncodedTileType.FirstPass; firstPassTile.IsDifferenceTile = encodingContext.UseDifferenceTile; firstPassTile.UseReduceExtrapolate = encodingContext.UseReduceExtrapolate; firstPassTile.CodecQuantVals = encodingContext.CodecQuantVals; firstPassTile.QuantIdxY = encodingContext.QuantIdxY; firstPassTile.QuantIdxCb = encodingContext.QuantIdxCb; firstPassTile.QuantIdxCr = encodingContext.QuantIdxCr; firstPassTile.ProgCodecQuant = RdpegfxTileUtils.GetProgCodecQuant(ProgressiveChunk_Values.kChunk_25); progCTileList.Add(firstPassTile); encodingContext.prevProgQuant = RdpegfxTileUtils.GetProgCodecQuant(ProgressiveChunk_Values.kChunk_25); //Update DRS encodingContext.DRS.Sub(encodingContext.DTS); //Update DAS encodingContext.DAS.Add(encodingContext.DTS); #endregion #region Chunk 50,75,100, upgrade pass ProgressiveChunk_Values[] upgradeChunks = { ProgressiveChunk_Values.kChunk_50, ProgressiveChunk_Values.kChunk_75, ProgressiveChunk_Values.kChunk_100 }; foreach (ProgressiveChunk_Values tChunk in upgradeChunks) { ProgressiveQuantization(encodingContext, tChunk); RFX_PROGRESSIVE_CODEC_QUANT progquant = RdpegfxTileUtils.GetProgCodecQuant(tChunk); progCTileList.Add(SRLEncode(encodingContext, progquant)); //Update DRS encodingContext.DRS.Sub(encodingContext.DTS); //Update DAS encodingContext.DAS.Add(encodingContext.DTS); encodingContext.prevProgQuant = progquant; } return(progCTileList.ToArray()); #endregion } }
public static void Dequantization(RfxProgressiveCodecContext codecContext) { dequantization_Component(codecContext.YSet, codecContext.CodecQuantVals[codecContext.QuantIdxY], codecContext.UseReduceExtrapolate); dequantization_Component(codecContext.CbSet, codecContext.CodecQuantVals[codecContext.QuantIdxCb], codecContext.UseReduceExtrapolate); dequantization_Component(codecContext.CrSet, codecContext.CodecQuantVals[codecContext.QuantIdxCr], codecContext.UseReduceExtrapolate); }
static DwtTile GetDTS(RfxProgressiveCodecContext encodingContext, ProgressiveChunk_Values chunk) { DwtBands yBD = DwtBands.GetFromLinearizationResult(encodingContext.DRS.Y_DwtQ, encodingContext.UseReduceExtrapolate); DwtBands cbBD = DwtBands.GetFromLinearizationResult(encodingContext.DRS.Cb_DwtQ, encodingContext.UseReduceExtrapolate); DwtBands crBD = DwtBands.GetFromLinearizationResult(encodingContext.DRS.Cr_DwtQ, encodingContext.UseReduceExtrapolate); DTS_Component(yBD, TileComponents.Y, chunk); DTS_Component(cbBD, TileComponents.Cb, chunk); DTS_Component(crBD, TileComponents.Cr, chunk); DwtTile dwtDts = new DwtTile(yBD.GetLinearizationData(), cbBD.GetLinearizationData(), crBD.GetLinearizationData()); return dwtDts; }
public static void SubBandReconstruction(RfxProgressiveCodecContext codecContext) { reconstruction_Component(codecContext.YComponent, out codecContext.YSet, codecContext.UseReduceExtrapolate); reconstruction_Component(codecContext.CbComponent, out codecContext.CbSet, codecContext.UseReduceExtrapolate); reconstruction_Component(codecContext.CrComponent, out codecContext.CrSet, codecContext.UseReduceExtrapolate); }
//InverseDWT public static void InverseDWT(RfxProgressiveCodecContext codecContext) { InverseDWT_Component(codecContext.YSet); InverseDWT_Component(codecContext.CbSet); InverseDWT_Component(codecContext.CrSet); }
public static void Quantization(RfxProgressiveCodecContext encodingContext) { doQuantization_Component(encodingContext.YSet, encodingContext.CodecQuantVals[encodingContext.QuantIdxY], encodingContext.UseReduceExtrapolate); doQuantization_Component(encodingContext.CbSet, encodingContext.CodecQuantVals[encodingContext.QuantIdxCb], encodingContext.UseReduceExtrapolate); doQuantization_Component(encodingContext.CrSet, encodingContext.CodecQuantVals[encodingContext.QuantIdxCr], encodingContext.UseReduceExtrapolate); }
public static void Linearization_NoLL3Delta(RfxProgressiveCodecContext encodingContext) { linearization_Compontent(encodingContext.YSet, encodingContext.UseReduceExtrapolate, out encodingContext.YComponent); linearization_Compontent(encodingContext.CbSet, encodingContext.UseReduceExtrapolate, out encodingContext.CbComponent); linearization_Compontent(encodingContext.CrSet, encodingContext.UseReduceExtrapolate, out encodingContext.CrComponent); }
/// <summary> /// Decode an encoded tile /// </summary> /// <param name="enTile">Represents an encoded tile.</param> /// <param name="tState">The context state of the tile that going to be decoded.</param> public static void DecodeTile(EncodedTile enTile, TileState tState) { RfxProgressiveCodecContext codecContext = new RfxProgressiveCodecContext( enTile.CodecQuantVals, enTile.QuantIdxY, enTile.QuantIdxCb, enTile.QuantIdxCr, enTile.DataType == EncodedTileType.Simple ? false : true, enTile.IsDifferenceTile, enTile.UseReduceExtrapolate); //RLGR/SRL Decode if (enTile.DataType == EncodedTileType.FirstPass || enTile.DataType == EncodedTileType.Simple) { //first pass or simple codecContext.YData = enTile.YEncodedData; codecContext.CbData = enTile.CbEncodedData; codecContext.CrData = enTile.CrEncodedData; RemoteFXDecoder.RLGRDecode(codecContext); ComputeOriginalLL3FromDeltas(codecContext); } else { SRLDecode(codecContext, enTile, tState); } //Progressive Dequantization if (enTile.DataType != EncodedTileType.Simple) { ProgressiveDeQuantization(codecContext, enTile.ProgCodecQuant); } // Create a DwtTile instance for tri-state DwtTile triStateDwt = new DwtTile(codecContext.YComponent, codecContext.CbComponent, codecContext.CrComponent, enTile.CodecQuantVals, enTile.QuantIdxY, enTile.QuantIdxCb, enTile.QuantIdxCr, enTile.UseReduceExtrapolate, enTile.ProgCodecQuant); //Set Tri-State for progressive codec if (enTile.DataType == EncodedTileType.FirstPass) { //DwtTile tileTriStat = SetTriState(diffDwt, enTile.UseReduceExtrapolate); tState.UpdateTriState(triStateDwt); } else if (enTile.DataType == EncodedTileType.UpgradePass) { DwtTile prvStat = tState.GetTriState(); prvStat.Add(triStateDwt); // update ProCodecQuant prvStat.ProgCodecQuant = triStateDwt.ProgCodecQuant; tState.UpdateTriState(prvStat); } // Create another DwtTile instance for DWT Data. // The data in diffDwt is the same as triStateDwt, this will makesure the DWT data and tri-state not share the same DWT tile instance DwtTile diffDwt = new DwtTile(codecContext.YComponent, codecContext.CbComponent, codecContext.CrComponent, enTile.CodecQuantVals, enTile.QuantIdxY, enTile.QuantIdxCb, enTile.QuantIdxCr, enTile.UseReduceExtrapolate, enTile.ProgCodecQuant); //Sum difference if ( enTile.IsDifferenceTile || enTile.DataType == EncodedTileType.UpgradePass) { tState.AddDwt(diffDwt); } else { tState.UpdateDwt(diffDwt); } }
public static void SubBandReconstruction(RfxProgressiveCodecContext codecContext) { reconstruction_Component(codecContext.YComponent, out codecContext.YSet, codecContext.UseReduceExtrapolate); reconstruction_Component(codecContext.CbComponent, out codecContext.CbSet, codecContext.UseReduceExtrapolate); reconstruction_Component(codecContext.CrComponent, out codecContext.CrSet, codecContext.UseReduceExtrapolate); }
/// <summary> /// Decode an encoded tile /// </summary> /// <param name="enTile">Represents an encoded tile.</param> /// <param name="tState">The context state of the tile that going to be decoded.</param> public static void DecodeTile(EncodedTile enTile, TileState tState) { RfxProgressiveCodecContext codecContext = new RfxProgressiveCodecContext( enTile.CodecQuantVals, enTile.QuantIdxY, enTile.QuantIdxCb, enTile.QuantIdxCr, enTile.DataType == EncodedTileType.Simple ? false : true, enTile.IsDifferenceTile, enTile.UseReduceExtrapolate); //RLGR/SRL Decode if (enTile.DataType == EncodedTileType.FirstPass || enTile.DataType == EncodedTileType.Simple) { //first pass or simple codecContext.YData = enTile.YEncodedData; codecContext.CbData = enTile.CbEncodedData; codecContext.CrData = enTile.CrEncodedData; RemoteFXDecoder.RLGRDecode(codecContext); ComputeOriginalLL3FromDeltas(codecContext); } else { SRLDecode(codecContext, enTile, tState); } //Progressive Dequantization if (enTile.DataType != EncodedTileType.Simple) { ProgressiveDeQuantization(codecContext, enTile.ProgCodecQuant); } // Create a DwtTile instance for tri-state DwtTile triStateDwt = new DwtTile(codecContext.YComponent, codecContext.CbComponent, codecContext.CrComponent, enTile.CodecQuantVals, enTile.QuantIdxY, enTile.QuantIdxCb, enTile.QuantIdxCr, enTile.UseReduceExtrapolate, enTile.ProgCodecQuant); //Set Tri-State for progressive codec if (enTile.DataType == EncodedTileType.FirstPass) { //DwtTile tileTriStat = SetTriState(diffDwt, enTile.UseReduceExtrapolate); tState.UpdateTriState(triStateDwt); } else if (enTile.DataType == EncodedTileType.UpgradePass) { DwtTile prvStat = tState.GetTriState(); prvStat.Add(triStateDwt); // update ProCodecQuant prvStat.ProgCodecQuant = triStateDwt.ProgCodecQuant; tState.UpdateTriState(prvStat); } // Create another DwtTile instance for DWT Data. // The data in diffDwt is the same as triStateDwt, this will makesure the DWT data and tri-state not share the same DWT tile instance DwtTile diffDwt = new DwtTile(codecContext.YComponent, codecContext.CbComponent, codecContext.CrComponent, enTile.CodecQuantVals, enTile.QuantIdxY, enTile.QuantIdxCb, enTile.QuantIdxCr, enTile.UseReduceExtrapolate, enTile.ProgCodecQuant); //Sum difference if (enTile.IsDifferenceTile || enTile.DataType == EncodedTileType.UpgradePass) { tState.AddDwt(diffDwt); } else { tState.UpdateDwt(diffDwt); } }
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(); }
public static void ProgressiveDeQuantization(RfxProgressiveCodecContext codecContext, RFX_PROGRESSIVE_CODEC_QUANT progCodecQuant ) { ProgressiveDeQuantization_Component(codecContext.YComponent, progCodecQuant.yQuantValues, codecContext.UseReduceExtrapolate); ProgressiveDeQuantization_Component(codecContext.CbComponent, progCodecQuant.cbQuantValues, codecContext.UseReduceExtrapolate); ProgressiveDeQuantization_Component(codecContext.CrComponent, progCodecQuant.crQuantValues, codecContext.UseReduceExtrapolate); }
//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(); }
//DWT internal static void DWT(RfxProgressiveCodecContext encodingContext) { DWT_Component(encodingContext.YSet); DWT_Component(encodingContext.CbSet); DWT_Component(encodingContext.CrSet); }
/// <summary> /// Decode and Render the tile to an image /// </summary> /// <returns>The image rendered from tile</returns> public Bitmap ToImage() { Bitmap tileImg = new Bitmap(RdpegfxTileUtils.TileSize, RdpegfxTileUtils.TileSize); RfxProgressiveCodecContext codecContext = new RfxProgressiveCodecContext(this.CodecQuantVals, this.QuantIdxY, this.QuantIdxCb, this.QuantIdxCr, UseReduceExtrapolate); codecContext.YComponent = new short[Y_DwtQ.Length]; codecContext.CbComponent = new short[Cb_DwtQ.Length]; codecContext.CrComponent = new short[Cr_DwtQ.Length]; Y_DwtQ.CopyTo(codecContext.YComponent, 0); Cb_DwtQ.CopyTo(codecContext.CbComponent, 0); Cr_DwtQ.CopyTo(codecContext.CrComponent, 0); RfxProgressiveDecoder.DecodeTileFromDwtQ(codecContext); BitmapData bmpData = tileImg.LockBits(new Rectangle(0, 0, tileImg.Width, tileImg.Height), ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb); unsafe { byte* cusor = (byte*)bmpData.Scan0.ToPointer(); for (int y = 0; y < bmpData.Height; y++) { for (int x = 0; x < bmpData.Width; x++) { cusor[0] = codecContext.BSet[x, y]; cusor[1] = codecContext.GSet[x, y]; cusor[2] = codecContext.RSet[x, y]; cusor += 3; } cusor += (bmpData.Stride - 3 * (bmpData.Width)); } } tileImg.UnlockBits(bmpData); return tileImg; }
/// <summary> /// Encode the surface with Progressive Codec /// </summary> /// <param name="quality">The target encoded quality.</param> /// <param name="bProg">Indicates if encode progressively</param> /// <param name="bSubDiff">Indicates if sub-diffing with last frame of this surface</param> /// <param name="bReduceExtrapolate">Indicates if use Reduce Extrapolate method in DWT step.</param> /// <returns>The dictionary of tile index and encoded tile datas.</returns> public Dictionary<TileIndex, EncodedTile[]> ProgressiveEncode(ImageQuality_Values quality, bool bProg, bool bSubDiff, bool bReduceExtrapolate, bool ignoreUnchangedTile=true) { Dictionary<TileIndex, EncodedTile[]> encodedTileDic = new Dictionary<TileIndex, EncodedTile[]>(); TS_RFX_CODEC_QUANT quant = RdpegfxTileUtils.GetCodecQuant(quality); TileIndex[] tileIndexArr; if(!ignoreUnchangedTile) { tileIndexArr = GetAllIndexes(); } else { tileIndexArr = GetDiffIndexes(true); } foreach (TileIndex index in tileIndexArr) { RfxProgressiveCodecContext codecContext = new RfxProgressiveCodecContext( new TS_RFX_CODEC_QUANT[]{quant}, 0, // quantization index of Y, set this paramter to 0 since only one quantization value in the array 0, // quantization index of Cb 0, // quantization index of Cr bProg,//progressive bSubDiff,//sub-diffing bReduceExtrapolate);//reduce extrapolate TileState tState = new TileState(this, index); encodedTileDic.Add(index,RfxProgressiveEncoder.EncodeTile(codecContext, tState)); } return encodedTileDic; }
//InverseDWT public static void InverseDWT(RfxProgressiveCodecContext codecContext) { InverseDWT_Component(codecContext.YSet); InverseDWT_Component(codecContext.CbSet); InverseDWT_Component(codecContext.CrSet); }
public static void ProgressiveQuantization(RfxProgressiveCodecContext encodingContext, ProgressiveChunk_Values chunk) { DwtBands yBD = DwtBands.GetFromLinearizationResult(encodingContext.DRS.Y_DwtQ, encodingContext.UseReduceExtrapolate); DwtBands cbBD = DwtBands.GetFromLinearizationResult(encodingContext.DRS.Cb_DwtQ, encodingContext.UseReduceExtrapolate); DwtBands crBD = DwtBands.GetFromLinearizationResult(encodingContext.DRS.Cr_DwtQ, encodingContext.UseReduceExtrapolate); ProgressiveQuantization_Component(yBD, TileComponents.Y, chunk); ProgressiveQuantization_Component(cbBD, TileComponents.Cb, chunk); ProgressiveQuantization_Component(crBD, TileComponents.Cr, chunk); DwtTile dwtDts = new DwtTile(yBD.GetLinearizationData(), cbBD.GetLinearizationData(), crBD.GetLinearizationData()); encodingContext.ProgQ = dwtDts; //Compute DTS encodingContext.DTS = GetDTS(encodingContext, chunk); }
public static void Dequantization(RfxProgressiveCodecContext codecContext) { dequantization_Component(codecContext.YSet, codecContext.CodecQuantVals[codecContext.QuantIdxY], codecContext.UseReduceExtrapolate); dequantization_Component(codecContext.CbSet, codecContext.CodecQuantVals[codecContext.QuantIdxCb], codecContext.UseReduceExtrapolate); dequantization_Component(codecContext.CrSet, codecContext.CodecQuantVals[codecContext.QuantIdxCr], codecContext.UseReduceExtrapolate); }
//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 ProgressiveDeQuantization(RfxProgressiveCodecContext codecContext, RFX_PROGRESSIVE_CODEC_QUANT progCodecQuant) { ProgressiveDeQuantization_Component(codecContext.YComponent, progCodecQuant.yQuantValues, codecContext.UseReduceExtrapolate); ProgressiveDeQuantization_Component(codecContext.CbComponent, progCodecQuant.cbQuantValues, codecContext.UseReduceExtrapolate); ProgressiveDeQuantization_Component(codecContext.CrComponent, progCodecQuant.crQuantValues, codecContext.UseReduceExtrapolate); }
//Compute the difference tile dwt public static void SubBandDiffing_DT(RfxProgressiveCodecContext encodingContext, TileState enTileInfo) { if (encodingContext.UseDifferenceTile) { DwtTile oldDwt = enTileInfo.GetOldDwt(); if (oldDwt != null) { short[] yDiffDwt, cbDiffDwt, crDiffDwt; int lenOfNonLL3Band = (RdpegfxTileUtils.ComponentElementCount - RdpegfxTileUtils.GetBandSize(BandType_Values.LL3, encodingContext.UseReduceExtrapolate));// ? 81 : 64; int yNewZeroCount, cbNewZeroCount, crNewZeroCount; int yDiffZeroCount, cbDiffZeroCount, crDiffZeroCount; yDiffDwt = RdpegfxTileUtils.SubDiffingDwt(encodingContext.YComponent, oldDwt.Y_DwtQ, lenOfNonLL3Band, out yNewZeroCount, out yDiffZeroCount); cbDiffDwt = RdpegfxTileUtils.SubDiffingDwt(encodingContext.CbComponent, oldDwt.Cb_DwtQ, lenOfNonLL3Band, out cbNewZeroCount, out cbDiffZeroCount); crDiffDwt = RdpegfxTileUtils.SubDiffingDwt(encodingContext.CrComponent, oldDwt.Cr_DwtQ, lenOfNonLL3Band, out crNewZeroCount, out crDiffZeroCount); if ((yDiffDwt != null && cbDiffDwt != null && crDiffDwt != null) && (yNewZeroCount + cbNewZeroCount + crNewZeroCount < yDiffZeroCount + cbDiffZeroCount + crDiffZeroCount)) {//use difference tile encodingContext.YComponent = yDiffDwt; encodingContext.CbComponent = cbDiffDwt; encodingContext.CrComponent = crDiffDwt; return; } } } encodingContext.UseDifferenceTile = false;//use orginal tile }
static void FillRgbData(RfxProgressiveCodecContext encodingContext, RgbTile rgbTile) { encodingContext.RSet = rgbTile.RSet; encodingContext.GSet = rgbTile.GSet; encodingContext.BSet = rgbTile.BSet; }
static void FillRgbData(RfxProgressiveCodecContext encodingContext, RgbTile rgbTile) { encodingContext.RSet = rgbTile.RSet; encodingContext.GSet = rgbTile.GSet; encodingContext.BSet = rgbTile.BSet; }
//DWT internal static void DWT(RfxProgressiveCodecContext encodingContext) { DWT_Component(encodingContext.YSet); DWT_Component(encodingContext.CbSet); DWT_Component(encodingContext.CrSet); }
/// <summary> /// Encode a Tile /// </summary> /// <param name="encodingContext">The tile encoding context</param> /// <param name="enTileInfo">The tile to be encoded</param> /// <returns>A array of CompressedTile which contains the encoded tiles</returns> public static EncodedTile[] EncodeTile(RfxProgressiveCodecContext encodingContext, TileState enTileInfo) { EncodedTileType targetType = encodingContext.UseProgressive ? EncodedTileType.FirstPass : EncodedTileType.Simple; //File RGB FillRgbData(encodingContext, enTileInfo.GetRgb()); //Do color conversion RemoteFXEncoder.RGBToYCbCr(encodingContext); //Do DWT if (encodingContext.UseReduceExtrapolate) { //Do DWT using UseReduce Extrapolate method DWT(encodingContext); } else { RemoteFXEncoder.DWT(encodingContext); } //Do quantiztion Quantization(encodingContext); //Do linearization (LL3 delta not computed) Linearization_NoLL3Delta(encodingContext); //Update new DWT to tile DwtTile dwt = new DwtTile( (short[])encodingContext.YComponent.Clone(), (short[])encodingContext.CbComponent.Clone(), (short[])encodingContext.CrComponent.Clone(), encodingContext.CodecQuantVals, encodingContext.QuantIdxY, encodingContext.QuantIdxCb, encodingContext.QuantIdxCr, encodingContext.UseReduceExtrapolate ); enTileInfo.UpdateDwt(dwt); //Sub-Band Diffing if (encodingContext.UseDifferenceTile) { SubBandDiffing_DT(encodingContext, enTileInfo); } if (targetType == EncodedTileType.Simple) { ComputeLL3Deltas(encodingContext); RemoteFXEncoder.RLGREncode(encodingContext); EncodedTile cpTile = new EncodedTile(); cpTile.YEncodedData = (byte[])encodingContext.YData.Clone(); cpTile.CbEncodedData = (byte[])encodingContext.CbData.Clone(); cpTile.CrEncodedData = (byte[])encodingContext.CrData.Clone(); cpTile.DataType = EncodedTileType.Simple; cpTile.IsDifferenceTile = encodingContext.UseDifferenceTile; cpTile.UseReduceExtrapolate = encodingContext.UseReduceExtrapolate; cpTile.CodecQuantVals = encodingContext.CodecQuantVals; cpTile.QuantIdxY = encodingContext.QuantIdxY; cpTile.QuantIdxCb = encodingContext.QuantIdxCb; cpTile.QuantIdxCr = encodingContext.QuantIdxCr; cpTile.ProgCodecQuant = null; return new EncodedTile[] { cpTile }; } else { List<EncodedTile> progCTileList = new List<EncodedTile>(); //Init DRS, DAS encodingContext.DRS = new DwtTile(encodingContext.YComponent, encodingContext.CbComponent, encodingContext.CrComponent); encodingContext.DAS = new DwtTile(new short[RdpegfxTileUtils.ComponentElementCount], new short[RdpegfxTileUtils.ComponentElementCount], new short[RdpegfxTileUtils.ComponentElementCount]); #region Chunk 25, first pass ProgressiveQuantization(encodingContext, ProgressiveChunk_Values.kChunk_25); //Compute ProgQ LL3 deltas encodingContext.YComponent = encodingContext.ProgQ.Y_DwtQ; encodingContext.CbComponent = encodingContext.ProgQ.Cb_DwtQ; encodingContext.CrComponent = encodingContext.ProgQ.Cr_DwtQ; ComputeLL3Deltas(encodingContext); RemoteFXEncoder.RLGREncode(encodingContext); EncodedTile firstPassTile = new EncodedTile(); firstPassTile.YEncodedData = (byte[])encodingContext.YData.Clone(); firstPassTile.CbEncodedData = (byte[])encodingContext.CbData.Clone(); firstPassTile.CrEncodedData = (byte[])encodingContext.CrData.Clone(); firstPassTile.DataType = EncodedTileType.FirstPass; firstPassTile.IsDifferenceTile = encodingContext.UseDifferenceTile; firstPassTile.UseReduceExtrapolate = encodingContext.UseReduceExtrapolate; firstPassTile.CodecQuantVals = encodingContext.CodecQuantVals; firstPassTile.QuantIdxY = encodingContext.QuantIdxY; firstPassTile.QuantIdxCb = encodingContext.QuantIdxCb; firstPassTile.QuantIdxCr = encodingContext.QuantIdxCr; firstPassTile.ProgCodecQuant = RdpegfxTileUtils.GetProgCodecQuant(ProgressiveChunk_Values.kChunk_25); progCTileList.Add(firstPassTile); encodingContext.prevProgQuant = RdpegfxTileUtils.GetProgCodecQuant(ProgressiveChunk_Values.kChunk_25); //Update DRS encodingContext.DRS.Sub(encodingContext.DTS); //Update DAS encodingContext.DAS.Add(encodingContext.DTS); #endregion #region Chunk 50,75,100, upgrade pass ProgressiveChunk_Values[] upgradeChunks = { ProgressiveChunk_Values.kChunk_50, ProgressiveChunk_Values.kChunk_75, ProgressiveChunk_Values.kChunk_100 }; foreach (ProgressiveChunk_Values tChunk in upgradeChunks) { ProgressiveQuantization(encodingContext, tChunk); RFX_PROGRESSIVE_CODEC_QUANT progquant = RdpegfxTileUtils.GetProgCodecQuant(tChunk); progCTileList.Add(SRLEncode(encodingContext, progquant)); //Update DRS encodingContext.DRS.Sub(encodingContext.DTS); //Update DAS encodingContext.DAS.Add(encodingContext.DTS); encodingContext.prevProgQuant = progquant; } return progCTileList.ToArray(); #endregion } }
/// <summary> /// Decode a tile from DWT /// </summary> /// <param name="codecContext">The codec context which contains the DWT data of a tile.</param> public static void DecodeTileFromDwtQ(RfxProgressiveCodecContext codecContext) { //Sub Band Reconstruction SubBandReconstruction(codecContext); //De-quantization Dequantization(codecContext); //Inverse DWT if (codecContext.UseReduceExtrapolate) { InverseDWT(codecContext); } else { RemoteFXDecoder.InverseDWT(codecContext); } //(Y, U, V) to (R, G, B) RemoteFXDecoder.YCbCrToRGB(codecContext); }