/// <summary>
 /// create a single instance of band encoder
 /// </summary>
 public static ClearCodecBandEncoder GetInstance()
 {
     lock (synclock)
     {
         if (null == _instance)
         {
             _instance = new ClearCodecBandEncoder();
         }
     }
     return(_instance);
 }
        /// <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>
 /// create a single instance of band encoder
 /// </summary>
 public static ClearCodecBandEncoder GetInstance()
 {
     lock (synclock)
     {
         if (null == _instance)
         {
             _instance = new ClearCodecBandEncoder();
         }
     }
     return _instance;
 }