/// <summary> /// Add a new pixel and run length count to list /// </summary> /// <param name = "resRLSegList"> the list to save all pixel and its run length count </param> /// <param name = "compPixel"> the new pixel to be added </param> /// <param name = "count"> the run length factor of new pixel to be added </param> public static void addPixelToRLSegList(List <CLEARCODEC_RGB_RUN_SEGMENT> resRLSegList, Color compPixel, uint count) { CLEARCODEC_RGB_RUN_SEGMENT rgbSeg = new CLEARCODEC_RGB_RUN_SEGMENT(); rgbSeg.buleValue = compPixel.B; rgbSeg.greenValue = compPixel.G; rgbSeg.redValue = compPixel.R; rgbSeg.rlFactor = count; resRLSegList.Add(rgbSeg); }
/// <summary> /// It decode byte stream into CLEARCODEC_RESIDUAL_DATA structure /// </summary> /// <param name = "residualSegs"> the structure that decode result save to </param> /// <return> true if decode success, otherwise return false </return> public bool Decode(ref CLEARCODEC_RESIDUAL_DATA residualSegs) { if (decodeData == null) return false; List<CLEARCODEC_RGB_RUN_SEGMENT> segList = new List<CLEARCODEC_RGB_RUN_SEGMENT>(); while (offset < decodeData.Count()) { CLEARCODEC_RGB_RUN_SEGMENT runSeg = new CLEARCODEC_RGB_RUN_SEGMENT(); if (!DecodeByte(ref runSeg.buleValue)) return false; if (!DecodeByte(ref runSeg.greenValue)) return false; if (!DecodeByte(ref runSeg.redValue)) return false; // decode rlfactor if (!DecodeRulLengthFactor(ref runSeg.rlFactor)) return false; segList.Add(runSeg); } residualSegs.resRLSegArr = segList.ToArray(); return true; }
/// <summary> /// It decode byte stream into CLEARCODEC_RESIDUAL_DATA structure /// </summary> /// <param name = "residualSegs"> the structure that decode result save to </param> /// <return> true if decode success, otherwise return false </return> public bool Decode(ref CLEARCODEC_RESIDUAL_DATA residualSegs) { if (decodeData == null) { return(false); } List <CLEARCODEC_RGB_RUN_SEGMENT> segList = new List <CLEARCODEC_RGB_RUN_SEGMENT>(); while (offset < decodeData.Count()) { CLEARCODEC_RGB_RUN_SEGMENT runSeg = new CLEARCODEC_RGB_RUN_SEGMENT(); if (!DecodeByte(ref runSeg.buleValue)) { return(false); } if (!DecodeByte(ref runSeg.greenValue)) { return(false); } if (!DecodeByte(ref runSeg.redValue)) { return(false); } // decode rlfactor if (!DecodeRulLengthFactor(ref runSeg.rlFactor)) { return(false); } segList.Add(runSeg); } residualSegs.resRLSegArr = segList.ToArray(); return(true); }
/// <summary> /// Add a new pixel and run length count to list /// </summary> /// <param name = "resRLSegList"> the list to save all pixel and its run length count </param> /// <param name = "compPixel"> the new pixel to be added </param> /// <param name = "count"> the run length factor of new pixel to be added </param> public static void addPixelToRLSegList(List<CLEARCODEC_RGB_RUN_SEGMENT> resRLSegList, Color compPixel, uint count) { CLEARCODEC_RGB_RUN_SEGMENT rgbSeg = new CLEARCODEC_RGB_RUN_SEGMENT(); rgbSeg.buleValue = compPixel.B; rgbSeg.greenValue = compPixel.G; rgbSeg.redValue = compPixel.R; rgbSeg.rlFactor = count; resRLSegList.Add(rgbSeg); }
/// <summary> /// Convert encoded residual layer structure into byte stream. /// </summary> /// <param name = "resData">The structure data to be converted into byte stream.</param> public byte[] ToBytes(CLEARCODEC_RESIDUAL_DATA resData) { if (resData.resRLSegArr == null) { return(null); } List <byte> bufList = new List <byte>(); for (int i = 0; i < resData.resRLSegArr.Count(); i++) { CLEARCODEC_RGB_RUN_SEGMENT seg = resData.resRLSegArr[i]; bufList.AddRange(TypeMarshal.ToBytes <byte>(seg.buleValue)); bufList.AddRange(TypeMarshal.ToBytes <byte>(seg.greenValue)); bufList.AddRange(TypeMarshal.ToBytes <byte>(seg.redValue)); if (ccTestType == RdpegfxNegativeTypes.ClearCodec_Residual_ZeroRunLengthFactor) { bufList.AddRange(TypeMarshal.ToBytes <byte>(0x00)); break; } if (seg.rlFactor < 255) // RLF1 exists, RLF2 & 3 doesn't exit. { bufList.AddRange(TypeMarshal.ToBytes <byte>((byte)seg.rlFactor)); } else if (seg.rlFactor < 65535) // RLF1 is 0xff, RLF2 exists, RLF3 doesn't exit. { if (ccTestType != RdpegfxNegativeTypes.ClearCodec_Residual_RedundantRunLengthFactor2) { bufList.AddRange(TypeMarshal.ToBytes <byte>(0xff)); } else { bufList.AddRange(TypeMarshal.ToBytes <byte>(0xf0)); } if (ccTestType != RdpegfxNegativeTypes.ClearCodec_Residual_AbsentRunLengthFactor2) { bufList.AddRange(TypeMarshal.ToBytes <ushort>((ushort)seg.rlFactor)); } } else // RLF1 is 0xff, RLF2 is 0xffff, RLF3 exists. { if (ccTestType != RdpegfxNegativeTypes.ClearCodec_Residual_RedundantRunLengthFactor2) { bufList.AddRange(TypeMarshal.ToBytes <byte>(0xff)); } else { bufList.AddRange(TypeMarshal.ToBytes <byte>(0xf0)); } if (ccTestType != RdpegfxNegativeTypes.ClearCodec_Residual_RedundantRunLengthFactor3) { bufList.AddRange(TypeMarshal.ToBytes <ushort>(0xffff)); } else { bufList.AddRange(TypeMarshal.ToBytes <ushort>(0xf0f0)); // Change RLF3 highest byte to avoid RLF3 is parsed into a color(3 bytes) plus RLF1=0 // when RLF1 is zero, all the left area will be filled by the color, no error triggers. seg.rlFactor |= 0xf0000000; } if (ccTestType != RdpegfxNegativeTypes.ClearCodec_Residual_AbsentRunLengthFactor3) { bufList.AddRange(TypeMarshal.ToBytes <uint>((uint)seg.rlFactor)); } } } return(bufList.ToArray()); }