示例#1
0
        internal static byte[] GetIndexedSMask(byte[] Img, int w, int h, byte[] tRNS, int BitsPerPixel)
        {
            int ScanLine = 1 + (w - 1) * BitsPerPixel / 8 + 1;      //RowFilter+Bytes needed for a row.

            byte[] RawImage = DecodeImage(Img, w, h, ScanLine);
            byte[] SMask    = BitsPerPixel == 8? RawImage: new byte[h * (w + 1)];        //no need for a new array if the image depth is 8.

            int ScanPos  = 0;
            int SMaskPos = 1;             //first byte is the row filter, already in 0.

            byte MaxBit = (byte)(8 / BitsPerPixel);

            byte[] Sh = new byte[8];           //Cached for speed.
            byte[] Sr = new byte[8];           //Cached for speed.
            for (int i = 0; i < BitsPerPixel; i++)
            {
                Sh[0] |= (byte)(1 << i);
            }

            for (int bit = 1; bit < MaxBit; bit++)
            {
                Sh[bit] = (byte)(Sh[bit - 1] << BitsPerPixel);
                Sr[bit] = (byte)(Sr[bit - 1] + BitsPerPixel);           //Sr[0]=0
            }

            for (int r = 0; r < h; r++)
            {
                int MaxSMaskPos = SMaskPos + w;                //Some images might use only a part of the last byte.
                for (int c = 1; c < ScanLine; c++)
                {
                    byte b = RawImage[ScanPos + c];

                    for (int bit = MaxBit - 1; bit >= 0; bit--)
                    {
                        if (SMaskPos >= MaxSMaskPos)
                        {
                            break;
                        }
                        byte b0 = (byte)((b & Sh[bit]) >> Sr[bit]); byte x = b0 < tRNS.Length? (byte)tRNS[b0] : (byte)255;
                        SMask[SMaskPos] = x;
                        SMaskPos++;
                    }
                }
                ScanPos += ScanLine;
                SMaskPos++;                  //Rowfilter
            }

            using (TCompressor Cmp = new TCompressor())
            {
                using (MemoryStream ms = new MemoryStream())
                {
                    Cmp.Deflate(SMask, 0, ms);
                    return(ms.ToArray());
                }
            }
        }
示例#2
0
 public static byte[] CompressData(byte[] Data)
 {
     using (TCompressor Cmp = new TCompressor())
     {
         using (MemoryStream ms = new MemoryStream())
         {
             Cmp.Deflate(Data, 0, ms);
             return(ms.ToArray());
         }
     }
 }
示例#3
0
文件: UXlsWmf.cs 项目: mwilian/demos
        //Current implementation of TCompressor is not thread safe.
        //private static TCompressor Cmp=null; //Wont be created until needed. //STATIC*

        //[MethodImpl(MethodImplOptions.NoInlining)]   //We don't want to check for ZLib until we are here.
        internal static void ToXls(Byte[] ImgData, Stream OutStream, bool IsEMF)
        {
#if (FRAMEWORK30 || !COMPACTFRAMEWORK)
            int HeadOfs = 0;
            if (!IsEMF && ImgData.Length > 4 && BitConverter.ToUInt32(ImgData, 0) == 0x9AC6CDD7)
            {
                HeadOfs += 22;                                                                           //A wmf file might have a placeable header or not. If it does, it begins with the magic number 9AC6CDD7 and it must be stripped.
            }
            using (TCompressor Cmp = new TCompressor())
            {
                Cmp.Deflate(ImgData, HeadOfs, OutStream);
            }
#else
            throw new FlexCelException("Operation not supported in CF 2.0");
#endif
        }