Exemplo n.º 1
0
 protected void EncodeRowFromByte(byte[] row)
 {
     if (row.Length == ImgInfo.SamplesPerRowPacked && !needsPack)
     {
         // some duplication of code - because this case is typical and it works faster this way
         int j = 1;
         if (ImgInfo.BitDepth <= 8)
         {
             foreach (byte x in row)                      // optimized
             {
                 rowb[j++] = x;
             }
         }
         else
         {
             // 16 bitspc
             foreach (byte x in row)                      // optimized
             {
                 rowb[j] = x;
                 j      += 2;
             }
         }
     }
     else
     {
         // perhaps we need to pack?
         if (row.Length >= ImgInfo.SamplesPerRow && needsPack)
         {
             ImageLine.PackInplaceByte(ImgInfo, row, row, false);                          // row is packed in place!
         }
         if (ImgInfo.BitDepth <= 8)
         {
             for (int i = 0, j = 1; i < ImgInfo.SamplesPerRowPacked; i++)
             {
                 rowb[j++] = row[i];
             }
         }
         else
         {
             // 16 bitspc
             for (int i = 0, j = 1; i < ImgInfo.SamplesPerRowPacked; i++)
             {
                 rowb[j++] = row[i];
                 rowb[j++] = 0;
             }
         }
     }
 }
Exemplo n.º 2
0
        public static byte[] Pack(ImageInfo imgInfo, byte[] src, byte[] dst, bool scale)
        {
            int len0 = imgInfo.SamplesPerRowPacked;

            if (dst == null || dst.Length < len0)
            {
                dst = new byte[len0];
            }
            if (imgInfo.Packed)
            {
                ImageLine.PackInplaceByte(imgInfo, src, dst, scale);
            }
            else
            {
                Array.Copy(src, 0, dst, 0, len0);
            }
            return(dst);
        }