/// <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); }
/// <summary> /// Get codec quant with the specified quality /// </summary> /// <param name="quality">the encoding quality</param> /// <returns>The codec quant</returns> public static TS_RFX_CODEC_QUANT GetCodecQuant(ImageQuality_Values quality) { TS_RFX_CODEC_QUANT quant = new TS_RFX_CODEC_QUANT(); quant.LL3_LH3 = (byte)(GetQuantValue(quality, BandType_Values.LL3) | (GetQuantValue(quality, BandType_Values.LH3) << 4)); quant.HL3_HH3 = (byte)(GetQuantValue(quality, BandType_Values.HL3) | (GetQuantValue(quality, BandType_Values.HH3) << 4)); quant.LH2_HL2 = (byte)(GetQuantValue(quality, BandType_Values.LH2) | (GetQuantValue(quality, BandType_Values.HL2) << 4)); quant.HH2_LH1 = (byte)(GetQuantValue(quality, BandType_Values.HH2) | (GetQuantValue(quality, BandType_Values.LH1) << 4)); quant.HL1_HH1 = (byte)(GetQuantValue(quality, BandType_Values.HL1) | (GetQuantValue(quality, BandType_Values.HH1) << 4)); return(quant); }
/// <summary> /// Encode bitmap data by RFX Progressive codec (one tile in one rfx_progressive_datablock frame). /// </summary> /// <param name="image"> The bitmap image to be sent </param> /// <param name="surf"> The surface that bitmap image is sent to </param> /// <param name="pixFormat">The pixel format to draw surface.</param> /// <param name="hasSync">Indicates if sync block exists in FRX Progressive bitmap stream.</param> /// <param name="hasContext">Indicates if context block exists in FRX Progressive bitmap stream.</param> /// <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> A list of layer byte stream, each layer is built by a dictionary with frameId and byte stream frame pair </returns> public List<Dictionary<uint, byte[]>> RfxProgressiveCodecEncode(Surface surf, Image image, PixelFormat pixFormat, bool hasSync, bool hasContext, ImageQuality_Values quality, bool bProg, bool bSubDiff, bool bReduceExtrapolate) { bool multipleTileInRegion = true; List<Dictionary<TileIndex, EncodedTile>> layerTileList = new List<Dictionary<TileIndex,EncodedTile>>(); if (image == null) return null; uint fid = 0; List<Dictionary<uint, byte[]>> layerDataList = new List<Dictionary<uint, byte[]>>(); // To save different layer data encoded by RFX Prog Codec. RdpegfxRfxProgCodecBlockManagerDecorator blockMngr = new RdpegfxRfxProgCodecBlockManagerDecorator(currentTestType); surf.UpdateFromBitmap((System.Drawing.Bitmap)image); Dictionary<TileIndex, EncodedTile[]> tileDict = surf.ProgressiveEncode(quality, bProg, bSubDiff, bReduceExtrapolate, false); if(multipleTileInRegion) { layerTileList = ConvertTileDictToLayer(tileDict); } if (this.bcgrAdapter.SimulatedScreen != null) { this.bcgrAdapter.SimulatedScreen.RenderProgressiveCodec(surf.Id, tileDict, (ushort)image.Width, (ushort)image.Height); } if (bProg) // Progressive codec is enabled { for (int i = 0; i < layerTileList.Count; i++) { Dictionary<uint, byte[]> tileFrameDict = new Dictionary<uint, byte[]>(); fid = MakeStartFramePdu(); RFXProgCodecBlockType blockType = i == 0 ? RFXProgCodecBlockType.WBT_TILE_PROGRESSIVE_FIRST : RFXProgCodecBlockType.WBT_TILE_PROGRESSIVE_UPGRADE; byte[] tileUpgradeData = blockMngr.PackRfxProgCodecDataBlock(hasSync, hasContext, bSubDiff, bReduceExtrapolate, layerTileList[i], blockType); MakeWireToSurfacePdu2(surf.Id, pixFormat, tileUpgradeData); MakeEndFramePdu(fid); // Save frame into encoded tile first frame Dictionary tileFrameDict.Add(fid, EncodePdusToSent()); // Add tile first frames into layer data list layerDataList.Add(tileFrameDict); } } else // Non-progressive encoding(i.e. tile_simple) { Dictionary<uint, byte[]> tileSimpleFrameDict = new Dictionary<uint, byte[]>(); fid = MakeStartFramePdu(); foreach (Dictionary<TileIndex, EncodedTile> layerTileDict in layerTileList) { byte[] tileUpgradeData = blockMngr.PackRfxProgCodecDataBlock(hasSync, hasContext, bSubDiff, bReduceExtrapolate, layerTileDict, RFXProgCodecBlockType.WBT_TILE_SIMPLE); MakeWireToSurfacePdu2(surf.Id, pixFormat, tileUpgradeData); } MakeEndFramePdu(fid); // Save frame into encoded tile simple frame Dictionary tileSimpleFrameDict.Add(fid, EncodePdusToSent()); // Add tile first frames into layer data list layerDataList.Add(tileSimpleFrameDict); } return layerDataList; }
/// <summary> /// Get codec quant value for a band /// </summary> /// <param name="quality">the quality</param> /// <param name="band">the band</param> /// <returns>The codec quant value of the band</returns> public static int GetQuantValue(ImageQuality_Values quality, BandType_Values band) { return QualityQuantMap[(int)quality, (int)(9 - band)]; }
/// <summary> /// Get codec quant with the specified quality /// </summary> /// <param name="quality">the encoding quality</param> /// <returns>The codec quant</returns> public static TS_RFX_CODEC_QUANT GetCodecQuant(ImageQuality_Values quality) { TS_RFX_CODEC_QUANT quant = new TS_RFX_CODEC_QUANT(); quant.LL3_LH3 = (byte)(GetQuantValue(quality, BandType_Values.LL3) | (GetQuantValue(quality, BandType_Values.LH3) << 4)); quant.HL3_HH3 = (byte)(GetQuantValue(quality, BandType_Values.HL3) | (GetQuantValue(quality, BandType_Values.HH3) << 4)); quant.LH2_HL2 = (byte)(GetQuantValue(quality, BandType_Values.LH2) | (GetQuantValue(quality, BandType_Values.HL2) << 4)); quant.HH2_LH1 = (byte)(GetQuantValue(quality, BandType_Values.HH2) | (GetQuantValue(quality, BandType_Values.LH1) << 4)); quant.HL1_HH1 = (byte)(GetQuantValue(quality, BandType_Values.HL1) | (GetQuantValue(quality, BandType_Values.HH1) << 4)); return quant; }
/// <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; }
/// <summary> /// Get codec quant value for a band /// </summary> /// <param name="quality">the quality</param> /// <param name="band">the band</param> /// <returns>The codec quant value of the band</returns> public static int GetQuantValue(ImageQuality_Values quality, BandType_Values band) { return(QualityQuantMap[(int)quality, (int)(9 - band)]); }