/// <summary>
        /// It decode band layer byte stream into CLEARCODEC_BAND_DATA structure
        /// </summary>
        /// <param name = "bands"> The structure that decode result save to. </param>
        /// <return> true if decode success, otherwise return false </return>
        public bool Decode(ref CLEARCODEC_BAND_DATA bands)
        {
            if (decodeData == null) return false;

            List<CLEARCODEC_BAND> bandList = new List<CLEARCODEC_BAND>();
            while (offset < decodeData.Count())
            {
                CLEARCODEC_BAND band = new CLEARCODEC_BAND();
                if (!DecodeBand(ref band)) return false;
                bandList.Add(band);
            }
            bands.bandArr = bandList.ToArray();
            return true;
        }
        /// <summary>
        /// Encode all the band images saved in CLEARCODEC_BAND_DATA structure into byte stream.
        /// </summary>
        /// <param name = "bandsData">The structure data to be converted into byte stream.</param>
        public byte[] ToBytes(CLEARCODEC_BAND_DATA bandsData)
        {
            List <byte> bufList = new List <byte>();

            if (bandsData.bandArr == null)
            {
                return(null);
            }
            for (int i = 0; i < bandsData.bandArr.Length; i++)
            {
                bufList.AddRange(ToBytes(bandsData.bandArr[i]));
            }
            return(bufList.ToArray());
        }
        /// <summary>
        /// Encode multiple band bitmap into byte stream
        /// </summary>
        /// <param name="bandDict">The structure saves multiple band bitmap and position.</param>
        /// <param name="vbarCacheEnabled">if vbar or short vbar cache is used when encoding band</param>
        public CLEARCODEC_BAND_DATA Encode(Dictionary <ClearCodec_RECT16, Bitmap> bandDict)
        {
            List <CLEARCODEC_BAND> bandList = new List <CLEARCODEC_BAND>();

            foreach (KeyValuePair <ClearCodec_RECT16, Bitmap> band in bandDict)
            {
                if (band.Value == null)
                {
                    continue;
                }
                CLEARCODEC_BAND bandData = EncodeBand(band.Value, band.Key);

                bandList.Add(bandData);
            }

            CLEARCODEC_BAND_DATA bands = new CLEARCODEC_BAND_DATA();

            bands.bandArr = bandList.ToArray();
            return(bands);
        }
Пример #4
0
        /// <summary>
        /// It decode band layer byte stream into CLEARCODEC_BAND_DATA structure
        /// </summary>
        /// <param name = "bands"> The structure that decode result save to. </param>
        /// <return> true if decode success, otherwise return false </return>
        public bool Decode(ref CLEARCODEC_BAND_DATA bands)
        {
            if (decodeData == null)
            {
                return(false);
            }

            List <CLEARCODEC_BAND> bandList = new List <CLEARCODEC_BAND>();

            while (offset < decodeData.Count())
            {
                CLEARCODEC_BAND band = new CLEARCODEC_BAND();
                if (!DecodeBand(ref band))
                {
                    return(false);
                }
                bandList.Add(band);
            }
            bands.bandArr = bandList.ToArray();
            return(true);
        }
 /// <summary>
 /// Encode all the band images saved in CLEARCODEC_BAND_DATA structure into byte stream.
 /// </summary>
 /// <param name = "bandsData">The structure data to be converted into byte stream.</param>
 public byte[] ToBytes(CLEARCODEC_BAND_DATA bandsData)
 {
     List<byte> bufList = new List<byte>();
     if (bandsData.bandArr == null) return null;
     for (int i = 0; i < bandsData.bandArr.Length; i++)
     {
         bufList.AddRange(ToBytes(bandsData.bandArr[i]));
     }
     return bufList.ToArray();
 }
        /// <summary>
        /// Encode the residual, band, and subcodec layer images into a bytestream.
        /// </summary>
        public byte[] EncodeCompositePayload()
        {
            List <byte> buf = new List <byte>();

            if (resBmp != null)
            {
                CLEARCODEC_RESIDUAL_DATA resData = ClearCodecResidualEncoder.Encode(resBmp);
                compPayload.residualData = ToBytes(resData);
                if (compPayload.residualData == null)
                {
                    return(null);
                }
                compPayload.residualByteCount = (uint)compPayload.residualData.Count();
            }
            else
            {
                compPayload.residualByteCount = 0;
                compPayload.residualData      = null;
            }

            if (bandDict.Count() != 0)  // Band image are loaded before.
            {
                ClearCodecBandEncoder bandencoder = ClearCodecBandEncoder.GetInstance();
                if ((this.flags & ClearCodec_BitmapStream.CLEARCODEC_FLAG_CACHE_RESET) != 0)
                {
                    bandencoder.ResetVBarStorage();
                }
                CLEARCODEC_BAND_DATA bandsData = bandencoder.Encode(bandDict);
                compPayload.bandData = ToBytes(bandsData);
                if (compPayload.bandData == null)
                {
                    return(null);
                }
                compPayload.bandByteCount = (uint)compPayload.bandData.Count();
            }
            else
            {
                compPayload.bandByteCount = 0;
                compPayload.bandData      = null;
            }

            if (subcodecDict.Count() != 0)  // Subcodec image are loaded before.
            {
                CLEARCODEC_SUBCODEC_DATA subcodecs = ClearCodecSubCodecEncoder.Encode(subcodecDict);
                compPayload.subcodecData = ToBytes(subcodecs);
                if (compPayload.subcodecData == null)
                {
                    return(null);
                }
                compPayload.subcodecByteCount = (uint)compPayload.subcodecData.Count();
            }
            else
            {
                compPayload.subcodecByteCount = 0;
                compPayload.subcodecData      = null;
            }

            buf.AddRange(TypeMarshal.ToBytes <uint>(compPayload.residualByteCount));
            buf.AddRange(TypeMarshal.ToBytes <uint>(compPayload.bandByteCount));
            buf.AddRange(TypeMarshal.ToBytes <uint>(compPayload.subcodecByteCount));

            if (compPayload.residualByteCount > 0)
            {
                buf.AddRange(compPayload.residualData);
            }

            if (compPayload.bandByteCount > 0)
            {
                buf.AddRange(compPayload.bandData);
            }

            if (compPayload.subcodecByteCount > 0)
            {
                buf.AddRange(compPayload.subcodecData);
            }

            return(buf.ToArray());
        }
        /// <summary>
        /// Encode multiple band bitmap into byte stream
        /// </summary>
        /// <param name="bandDict">The structure saves multiple band bitmap and position.</param>
        /// <param name="vbarCacheEnabled">if vbar or short vbar cache is used when encoding band</param>
        public CLEARCODEC_BAND_DATA Encode(Dictionary<ClearCodec_RECT16, Bitmap> bandDict)
        {
            List<CLEARCODEC_BAND> bandList = new List<CLEARCODEC_BAND>();

            foreach (KeyValuePair<ClearCodec_RECT16, Bitmap> band in bandDict)
            {
                if (band.Value == null) continue;
                CLEARCODEC_BAND bandData = EncodeBand(band.Value, band.Key);

                bandList.Add(bandData);
            }

            CLEARCODEC_BAND_DATA bands = new CLEARCODEC_BAND_DATA();
            bands.bandArr = bandList.ToArray();
            return bands;
        }