/// <summary> /// Get the band type with the given element index /// </summary> /// <param name="eleIdx">the index of an element</param> /// <param name="useReduceExtrapolate">indicates if Reduce-Extrapolate method used</param> /// <returns>The band type</returns> public static BandType_Values GetBandByIndex(int eleIdx, bool useReduceExtrapolate) { BandType_Values[] bandArr = new BandType_Values[] { BandType_Values.HL1, BandType_Values.LH1, BandType_Values.HH1, BandType_Values.HL2, BandType_Values.LH2, BandType_Values.HH2, BandType_Values.HL3, BandType_Values.LH3, BandType_Values.HH3, BandType_Values.LL3 }; if (useReduceExtrapolate) { for (int i = 0; i < bandArr.Length; i++) { if (BandIndexRange_ReduceExtrapolate[i, 0] <= eleIdx && eleIdx <= BandIndexRange_ReduceExtrapolate[i, 1]) { return(bandArr[i]); } } } else { for (int i = 0; i < bandArr.Length; i++) { if (BandIndexRange[i, 0] <= eleIdx && eleIdx <= BandIndexRange[i, 1]) { return(bandArr[i]); } } } throw new InvalidProgramException("GetBandByIndex::eleIdx is invalid: " + eleIdx); }
/// <summary> /// Get the bit-pos from a codec quantity for a specified band /// </summary> /// <param name="quant">codec quantity</param> /// <param name="band">a band tye</param> /// <returns>The bit-pos of the given band</returns> public static int GetBitPosFromQuant(RFX_COMPONMENT_CODEC_QUANT quant, BandType_Values band) { switch (band) { case BandType_Values.HL1: return((quant.HH2_HL1 & 0xf0) >> 4); case BandType_Values.LH1: return(quant.LH1_HH1 & 0x0f); case BandType_Values.HH1: return((quant.LH1_HH1 & 0xf0) >> 4); case BandType_Values.HL2: return(quant.HL2_LH2 & 0x0f); case BandType_Values.LH2: return((quant.HL2_LH2 & 0xf0) >> 4); case BandType_Values.HH2: return(quant.HH2_HL1 & 0x0f); case BandType_Values.HL3: return((quant.LL3_HL3 & 0xf0) >> 4); case BandType_Values.LH3: return(quant.LH3_HH3 & 0x0f); case BandType_Values.HH3: return((quant.LH3_HH3 & 0xf0) >> 4); case BandType_Values.LL3: return(quant.LL3_HL3 & 0x0f); default: return(0); } }
protected static void dequantization_Component(short[,] compontent, TS_RFX_CODEC_QUANT tsRfxCodecQuant, bool useReduceExtrapolate) { // Quantization factor: HL1, LH1, HH1, HL2, LH2, HH2, HL3, LH3, HH3, LL3 Hashtable scaleValueTable = new Hashtable(); int HL1_Factor = tsRfxCodecQuant.HL1_HH1 & 0x0f; int LH1_Factor = (tsRfxCodecQuant.HH2_LH1 & 0xf0) >> 4; int HH1_Factor = (tsRfxCodecQuant.HL1_HH1 & 0xf0) >> 4; int HL2_Factor = (tsRfxCodecQuant.LH2_HL2 & 0xf0) >> 4; int LH2_Factor = tsRfxCodecQuant.LH2_HL2 & 0x0f; int HH2_Factor = tsRfxCodecQuant.HH2_LH1 & 0x0f; int HL3_Factor = tsRfxCodecQuant.HL3_HH3 & 0x0f; int LH3_Factor = (tsRfxCodecQuant.LL3_LH3 & 0xf0) >> 4; int HH3_Factor = (tsRfxCodecQuant.HL3_HH3 & 0xf0) >> 4; int LL3_Factor = tsRfxCodecQuant.LL3_LH3 & 0x0f; int[] HL_Factor = { HL1_Factor, HL2_Factor, HL3_Factor }; int[] LH_Factor = { LH1_Factor, LH2_Factor, LH3_Factor }; int[] HH_Factor = { HH1_Factor, HH2_Factor, HH3_Factor }; BandType_Values[] bandArr = new BandType_Values[] { BandType_Values.HL1, BandType_Values.LH1, BandType_Values.HH1, BandType_Values.HL2, BandType_Values.LH2, BandType_Values.HH2, BandType_Values.HL3, BandType_Values.LH3, BandType_Values.HH3, BandType_Values.LL3 }; int[] bandFactor = new int[] { HL1_Factor, LH1_Factor, HH1_Factor, HL2_Factor, LH2_Factor, HH2_Factor, HL3_Factor, LH3_Factor, HH3_Factor, LL3_Factor }; for (int i = 0; i < bandArr.Length; i++) { BandRect br = RdpegfxTileUtils.GetBandRect(bandArr[i], useReduceExtrapolate); doDequantization_Subband(compontent, br.left, br.top, br.right, br.bottom, bandFactor[i]); } }
/// <summary> /// Get the band size for a specified band /// </summary> /// <param name="band">the band type</param> /// <param name="useReduceExtrapolate">indicates if Reduce-Extrapolate method used.</param> /// <returns>The band size</returns> public static int GetBandSize(BandType_Values band, bool useReduceExtrapolate) { switch (band) { case BandType_Values.LL3: { return(useReduceExtrapolate ? 9 * 9 : 8 * 8); } case BandType_Values.LH3: { return(useReduceExtrapolate ? 9 * 8 : 8 * 8); } case BandType_Values.HL3: { return(useReduceExtrapolate ? 8 * 9 : 8 * 8); } case BandType_Values.HH3: { return(8 * 8); } case BandType_Values.LH2: { return(useReduceExtrapolate ? 16 * 17 : 16 * 16); } case BandType_Values.HL2: { return(useReduceExtrapolate ? 16 * 17 : 16 * 16); } case BandType_Values.HH2: { return(16 * 16); } case BandType_Values.LH1: { return(useReduceExtrapolate ? 31 * 33 : 32 * 32); } case BandType_Values.HL1: { return(useReduceExtrapolate ? 31 * 33 : 32 * 32); } case BandType_Values.HH1: { return(useReduceExtrapolate ? 31 * 31 : 32 * 32); } default: return(0); } }
static void DTS_Band(short[] bandData, BandType_Values band, TileComponents component, RFX_PROGRESSIVE_CODEC_QUANT quants) { int bitPos = RdpegfxTileUtils.GetBitPosForQuant(quants, component, band); for (int i = 0; i < bandData.Length; i++) { bandData[i] = FunDTS(bandData[i], bitPos, band); } }
static void DTS_Band(short[] bandData, BandType_Values band, TileComponents component, ProgressiveChunk_Values chunk) { int bitPos = RdpegfxTileUtils.GetBitPosForChunk(chunk, component, band); for (int i = 0; i < bandData.Length; i++) { bandData[i] = FunDTS(bandData[i], bitPos, band); } }
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); } }
static short FunProgDeQ(short v, int bitPos, BandType_Values band) { if (band != BandType_Values.LL3) { if (v >= 0) { return((short)(v << bitPos)); } return((short)-((-v) << bitPos)); } else { return((short)(v << bitPos)); } }
static short FunDTS(short v, int bitPos, BandType_Values band) { if (band != BandType_Values.LL3) { if (v >= 0) { return((short)((v >> bitPos) << bitPos)); } return((short)-(((-v) >> bitPos) << bitPos)); } else { return((short)(v >> bitPos << bitPos)); } }
public static void reconstruction_Component(short[] component1D, out short[,] compontent2D, bool useReduceExtrapolate) { //sequence: HL1, LH1, HH1, HL2, LH2, HH2, HL3, LH3, HH3, and LL3 //lineOutput = new short[TileSize * TileSize]; compontent2D = new short[RdpegfxTileUtils.TileSize, RdpegfxTileUtils.TileSize]; BandType_Values[] bandArr = new BandType_Values[] { BandType_Values.HL1, BandType_Values.LH1, BandType_Values.HH1, BandType_Values.HL2, BandType_Values.LH2, BandType_Values.HH2, BandType_Values.HL3, BandType_Values.LH3, BandType_Values.HH3, BandType_Values.LL3 }; int offset = 0; BandRect curBand; for (int i = 0; i < bandArr.Length; i++) { curBand = RdpegfxTileUtils.GetBandRect(bandArr[i], useReduceExtrapolate); reconstruction_SubBand(compontent2D, curBand.left, curBand.top, curBand.right, curBand.bottom, component1D, ref offset); } }
protected static void linearization_Compontent(short[,] compontent, bool useReduceExtrapolate, out short[] lineOutput) { //sequence: HL1, LH1, HH1, HL2, LH2, HH2, HL3, LH3, HH3, and LL3 lineOutput = new short[TileSize * TileSize]; int curIdx = 0; BandType_Values[] bandArr = new BandType_Values[] { BandType_Values.HL1, BandType_Values.LH1, BandType_Values.HH1, BandType_Values.HL2, BandType_Values.LH2, BandType_Values.HH2, BandType_Values.HL3, BandType_Values.LH3, BandType_Values.HH3, BandType_Values.LL3 }; short[] bandOutput; BandRect curBand; for (int i = 0; i < bandArr.Length; i++) { curBand = RdpegfxTileUtils.GetBandRect(bandArr[i], useReduceExtrapolate); linearization_SubBand(compontent, curBand.left, curBand.top, curBand.right, curBand.bottom, out bandOutput); Array.Copy(bandOutput, 0, lineOutput, curIdx, bandOutput.Length); curIdx += bandOutput.Length; } }
/// <summary> /// Get the Rect area of a band /// </summary> /// <param name="band">the band type</param> /// <param name="useReduceExtrapolate">indicates if Reduce-Extrapolate method used</param> /// <returns>The band rect area</returns> public static BandRect GetBandRect(BandType_Values band, bool useReduceExtrapolate) { BandRect br = new BandRect(); int bandIdx = (int)band; if (useReduceExtrapolate) { br.left = BandRectMap_ReduceExtrapolate[bandIdx, 0]; br.top = BandRectMap_ReduceExtrapolate[bandIdx, 1]; br.right = BandRectMap_ReduceExtrapolate[bandIdx, 2]; br.bottom = BandRectMap_ReduceExtrapolate[bandIdx, 3]; } else { br.left = BandRectMap[bandIdx, 0]; br.top = BandRectMap[bandIdx, 1]; br.right = BandRectMap[bandIdx, 2]; br.bottom = BandRectMap[bandIdx, 3]; } return(br); }
protected static void doQuantization_Component(short[,] component, TS_RFX_CODEC_QUANT tsRfxCodecQuant, bool useReduceExtrapolate) { // Quantization factor: HL1, LH1, HH1, HL2, LH2, HH2, HL3, LH3, HH3, LL3 Hashtable scaleValueTable = new Hashtable(); int HL1_Factor = tsRfxCodecQuant.HL1_HH1 & 0x0f; int LH1_Factor = (tsRfxCodecQuant.HH2_LH1 & 0xf0) >> 4; int HH1_Factor = (tsRfxCodecQuant.HL1_HH1 & 0xf0) >> 4; int HL2_Factor = (tsRfxCodecQuant.LH2_HL2 & 0xf0) >> 4; int LH2_Factor = tsRfxCodecQuant.LH2_HL2 & 0x0f; int HH2_Factor = tsRfxCodecQuant.HH2_LH1 & 0x0f; int HL3_Factor = tsRfxCodecQuant.HL3_HH3 & 0x0f; int LH3_Factor = (tsRfxCodecQuant.LL3_LH3 & 0xf0) >> 4; int HH3_Factor = (tsRfxCodecQuant.HL3_HH3 & 0xf0) >> 4; int LL3_Factor = tsRfxCodecQuant.LL3_LH3 & 0x0f; BandType_Values[] bandArr = new BandType_Values[] { BandType_Values.HL1, BandType_Values.LH1, BandType_Values.HH1, BandType_Values.HL2, BandType_Values.LH2, BandType_Values.HH2, BandType_Values.HL3, BandType_Values.LH3, BandType_Values.HH3, BandType_Values.LL3 }; int[] bandFactor = new int[] { HL1_Factor, LH1_Factor, HH1_Factor, HL2_Factor, LH2_Factor, HH2_Factor, HL3_Factor, LH3_Factor, HH3_Factor, LL3_Factor }; for (int i = 0; i < bandArr.Length; i++) { BandRect br = RdpegfxTileUtils.GetBandRect(bandArr[i], useReduceExtrapolate); doQuantization_Subband(component, br.left, br.top, br.right, br.bottom, bandFactor[i]); } }
/// <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 the bit-pos from a codec quantity for a specified band /// </summary> /// <param name="quant">codec quantity</param> /// <param name="band">a band tye</param> /// <returns>The bit-pos of the given band</returns> public static int GetBitPosFromQuant(RFX_COMPONMENT_CODEC_QUANT quant, BandType_Values band) { switch (band) { case BandType_Values.HL1: return (quant.HH2_HL1 & 0xf0) >> 4; case BandType_Values.LH1: return (quant.LH1_HH1 & 0x0f); case BandType_Values.HH1: return (quant.LH1_HH1 & 0xf0) >> 4; case BandType_Values.HL2: return (quant.HL2_LH2 & 0x0f); case BandType_Values.LH2: return (quant.HL2_LH2 & 0xf0) >> 4; case BandType_Values.HH2: return (quant.HH2_HL1 & 0x0f); case BandType_Values.HL3: return (quant.LL3_HL3 & 0xf0) >> 4; case BandType_Values.LH3: return (quant.LH3_HH3 & 0x0f); case BandType_Values.HH3: return (quant.LH3_HH3 & 0xf0) >> 4; case BandType_Values.LL3: return (quant.LL3_HL3 & 0x0f); default: return 0; } }
/// <summary> /// Get the bit-pos for a given chunk /// </summary> /// <param name="chunk">The chunk</param> /// <param name="component">The compoent</param> /// <param name="band">The band</param> /// <returns>The bit-pos of the given band for the given chunk</returns> public static int GetBitPosForQuant(RFX_PROGRESSIVE_CODEC_QUANT quants, TileComponents component, BandType_Values band) { RFX_COMPONMENT_CODEC_QUANT quantsComponet = quants.yQuantValues; switch (component) { case TileComponents.Y: quantsComponet = quants.yQuantValues; break; case TileComponents.Cb: quantsComponet = quants.cbQuantValues; break; case TileComponents.Cr: quantsComponet = quants.crQuantValues; break; } switch (band) { case BandType_Values.LL3: return quantsComponet.LL3_HL3 & 0x0F; case BandType_Values.HL3: return quantsComponet.LL3_HL3 >> 4; case BandType_Values.LH3: return quantsComponet.LH3_HH3 & 0x0F; case BandType_Values.HH3: return quantsComponet.LH3_HH3 >> 4; case BandType_Values.HL2: return quantsComponet.HL2_LH2 & 0x0F; case BandType_Values.LH2: return quantsComponet.HL2_LH2 >> 4; case BandType_Values.HH2: return quantsComponet.HH2_HL1 & 0x0F; case BandType_Values.HL1: return quantsComponet.HH2_HL1 >> 4; case BandType_Values.LH1: return quantsComponet.LH1_HH1 & 0x0F; case BandType_Values.HH1: return quantsComponet.LH1_HH1 >> 4; default: return 0; } }
/// <summary> /// Get the bit-pos for a given chunk /// </summary> /// <param name="chunk">The chunk</param> /// <param name="component">The compoent</param> /// <param name="band">The band</param> /// <returns>The bit-pos of the given band for the given chunk</returns> public static int GetBitPosForChunk(ProgressiveChunk_Values chunk, TileComponents component, BandType_Values band) { if (chunk == ProgressiveChunk_Values.kChunk_None) return 15; // no matter what the band or the component else if (chunk == ProgressiveChunk_Values.kChunk_100) return 0; return gProgressiveBitPosArray[(int)component, (int)chunk, (int)band]; }
/// <summary> /// Get the band size for a specified band /// </summary> /// <param name="band">the band type</param> /// <param name="useReduceExtrapolate">indicates if Reduce-Extrapolate method used.</param> /// <returns>The band size</returns> public static int GetBandSize(BandType_Values band, bool useReduceExtrapolate) { switch (band) { case BandType_Values.LL3: { return useReduceExtrapolate ? 9 * 9 : 8 * 8; } case BandType_Values.LH3: { return useReduceExtrapolate ? 9 * 8 : 8 * 8; } case BandType_Values.HL3: { return useReduceExtrapolate ? 8 * 9 : 8 * 8; } case BandType_Values.HH3: { return 8 * 8; } case BandType_Values.LH2: { return useReduceExtrapolate ? 16 * 17 : 16 * 16; } case BandType_Values.HL2: { return useReduceExtrapolate ? 16 * 17 : 16 * 16; } case BandType_Values.HH2: { return 16 * 16; } case BandType_Values.LH1: { return useReduceExtrapolate ? 31 * 33 : 32 * 32; } case BandType_Values.HL1: { return useReduceExtrapolate ? 31 * 33 : 32 * 32; } case BandType_Values.HH1: { return useReduceExtrapolate ? 31 * 31 : 32 * 32; } default: return 0; } }
/// <summary> /// Get the Rect area of a band /// </summary> /// <param name="band">the band type</param> /// <param name="useReduceExtrapolate">indicates if Reduce-Extrapolate method used</param> /// <returns>The band rect area</returns> public static BandRect GetBandRect(BandType_Values band, bool useReduceExtrapolate) { BandRect br = new BandRect(); int bandIdx = (int)band; if (useReduceExtrapolate) { br.left = BandRectMap_ReduceExtrapolate[bandIdx, 0]; br.top = BandRectMap_ReduceExtrapolate[bandIdx, 1]; br.right = BandRectMap_ReduceExtrapolate[bandIdx, 2]; br.bottom = BandRectMap_ReduceExtrapolate[bandIdx, 3]; } else { br.left = BandRectMap[bandIdx, 0]; br.top = BandRectMap[bandIdx, 1]; br.right = BandRectMap[bandIdx, 2]; br.bottom = BandRectMap[bandIdx, 3]; } return br; }
/// <summary> /// Get the band type with the given element index /// </summary> /// <param name="eleIdx">the index of an element</param> /// <param name="useReduceExtrapolate">indicates if Reduce-Extrapolate method used</param> /// <returns>The band type</returns> public static BandType_Values GetBandByIndex(int eleIdx, bool useReduceExtrapolate) { BandType_Values[] bandArr = new BandType_Values[] { BandType_Values.HL1, BandType_Values.LH1, BandType_Values.HH1, BandType_Values.HL2, BandType_Values.LH2, BandType_Values.HH2, BandType_Values.HL3, BandType_Values.LH3, BandType_Values.HH3, BandType_Values.LL3 }; if (useReduceExtrapolate) { for (int i = 0; i < bandArr.Length; i++) { if (BandIndexRange_ReduceExtrapolate[i, 0] <= eleIdx && eleIdx <= BandIndexRange_ReduceExtrapolate[i, 1]) { return bandArr[i]; } } } else { for (int i = 0; i < bandArr.Length; i++) { if (BandIndexRange[i, 0] <= eleIdx && eleIdx <= BandIndexRange[i, 1]) { return bandArr[i]; } } } throw new InvalidProgramException("GetBandByIndex::eleIdx is invalid: " + eleIdx); }
/// <summary> /// Get the bit-pos for a given chunk /// </summary> /// <param name="chunk">The chunk</param> /// <param name="component">The compoent</param> /// <param name="band">The band</param> /// <returns>The bit-pos of the given band for the given chunk</returns> public static int GetBitPosForQuant(RFX_PROGRESSIVE_CODEC_QUANT quants, TileComponents component, BandType_Values band) { RFX_COMPONMENT_CODEC_QUANT quantsComponet = quants.yQuantValues; switch (component) { case TileComponents.Y: quantsComponet = quants.yQuantValues; break; case TileComponents.Cb: quantsComponet = quants.cbQuantValues; break; case TileComponents.Cr: quantsComponet = quants.crQuantValues; break; } switch (band) { case BandType_Values.LL3: return(quantsComponet.LL3_HL3 & 0x0F); case BandType_Values.HL3: return(quantsComponet.LL3_HL3 >> 4); case BandType_Values.LH3: return(quantsComponet.LH3_HH3 & 0x0F); case BandType_Values.HH3: return(quantsComponet.LH3_HH3 >> 4); case BandType_Values.HL2: return(quantsComponet.HL2_LH2 & 0x0F); case BandType_Values.LH2: return(quantsComponet.HL2_LH2 >> 4); case BandType_Values.HH2: return(quantsComponet.HH2_HL1 & 0x0F); case BandType_Values.HL1: return(quantsComponet.HH2_HL1 >> 4); case BandType_Values.LH1: return(quantsComponet.LH1_HH1 & 0x0F); case BandType_Values.HH1: return(quantsComponet.LH1_HH1 >> 4); default: return(0); } }
/// <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 the bit-pos for a given chunk /// </summary> /// <param name="chunk">The chunk</param> /// <param name="component">The compoent</param> /// <param name="band">The band</param> /// <returns>The bit-pos of the given band for the given chunk</returns> public static int GetBitPosForChunk(ProgressiveChunk_Values chunk, TileComponents component, BandType_Values band) { if (chunk == ProgressiveChunk_Values.kChunk_None) { return(15); // no matter what the band or the component } else if (chunk == ProgressiveChunk_Values.kChunk_100) { return(0); } return(gProgressiveBitPosArray[(int)component, (int)chunk, (int)band]); }
static void ProgressiveQuantization_Band(short[] bandData, BandType_Values band, TileComponents component, ProgressiveChunk_Values chunk) { int bitPos = RdpegfxTileUtils.GetBitPosForChunk(chunk, component, band); for (int i = 0; i < bandData.Length; i++) { bandData[i] = FunProgQ(bandData[i], bitPos, band); } }
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(); }
static short FunProgQ(short v, int bitPos, BandType_Values band) { if (band != BandType_Values.LL3) { if (v >= 0) return (short)(v >> bitPos); return (short)-((-v) >> bitPos); } else { return (short)(v >> bitPos); } }
//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); }
static void ProgressiveQuantization_Band(short[] bandData, BandType_Values band, TileComponents component, RFX_PROGRESSIVE_CODEC_QUANT quants) { int bitPos = RdpegfxTileUtils.GetBitPosForQuant(quants, component, band); for (int i = 0; i < bandData.Length; i++) { bandData[i] = FunProgQ(bandData[i], bitPos, band); } }