Exemplo n.º 1
0
 public RawTGABitmap(int width, int height, byte[] data, TGAPixelFormat format)
 {
     Width = width;
     Height = height;
     Data = data;
     Format = format;
 }
Exemplo n.º 2
0
 public RawTGABitmap(int width, int height, byte[] data, TGAPixelFormat format)
 {
     Width  = width;
     Height = height;
     Data   = data;
     Format = format;
 }
Exemplo n.º 3
0
        /// <summary>
        /// Loads the thumbnail of the loaded image file, if any.
        /// </summary>
        /// <param name="binReader">A BinaryReader that points the loaded file byte stream.</param>
        /// <param name="pfPixelFormat">A PixelFormat value indicating what pixel format to use when loading the thumbnail.</param>
        private void LoadThumbnail(BinaryReader binReader, TGAPixelFormat pfPixelFormat)
        {
            // read the Thumbnail image data into a byte array
            // take into account stride has to be a multiple of 4
            // use padding to make sure multiple of 4

            byte[] data = null;
            if (binReader != null && binReader.BaseStream != null && binReader.BaseStream.Length > 0 && binReader.BaseStream.CanSeek == true)
            {
                if (this.ExtensionArea.PostageStampOffset > 0)
                {

                    // seek to the beginning of the image data using the ImageDataOffset value
                    binReader.BaseStream.Seek(this.ExtensionArea.PostageStampOffset, SeekOrigin.Begin);

                    int iWidth = (int)binReader.ReadByte();
                    int iHeight = (int)binReader.ReadByte();

                    int iStride = ((iWidth * (int)this.objTargaHeader.PixelDepth + 31) & ~31) >> 3; // width in bytes
                    int iPadding = iStride - (((iWidth * (int)this.objTargaHeader.PixelDepth) + 7) / 8);

                    System.Collections.Generic.List<System.Collections.Generic.List<byte>> objRows = new System.Collections.Generic.List<System.Collections.Generic.List<byte>>();
                    System.Collections.Generic.List<byte> objRow = new System.Collections.Generic.List<byte>();

                    byte[] padding = new byte[iPadding];
                    MemoryStream msData = null;
                    bool blnEachRowReverse = false;
                    bool blnRowsReverse = false;

                    using (msData = new MemoryStream())
                    {
                        // get the size in bytes of each row in the image
                        int intImageRowByteSize = iWidth * ((int)this.objTargaHeader.PixelDepth / 8);

                        // get the size in bytes of the whole image
                        int intImageByteSize = intImageRowByteSize * iHeight;

                        // thumbnails are never compressed
                        for (int i = 0; i < iHeight; i++)
                        {
                            for (int j = 0; j < intImageRowByteSize; j++)
                            {
                                objRow.Add(binReader.ReadByte());
                            }
                            objRows.Add(objRow);
                            objRow = new System.Collections.Generic.List<byte>();
                        }

                        switch (this.objTargaHeader.FirstPixelDestination)
                        {
                            case FirstPixelDestination.TOP_LEFT:
                                break;

                            case FirstPixelDestination.TOP_RIGHT:
                                blnRowsReverse = false;
                                blnEachRowReverse = false;
                                break;

                            case FirstPixelDestination.BOTTOM_LEFT:
                                break;

                            case FirstPixelDestination.BOTTOM_RIGHT:
                            case FirstPixelDestination.UNKNOWN:
                                blnRowsReverse = true;
                                blnEachRowReverse = false;

                                break;
                        }

                        if (blnRowsReverse == true)
                            objRows.Reverse();

                        for (int i = 0; i < objRows.Count; i++)
                        {
                            if (blnEachRowReverse == true)
                                objRows[i].Reverse();

                            byte[] brow = objRows[i].ToArray();
                            msData.Write(brow, 0, brow.Length);
                            msData.Write(padding, 0, padding.Length);
                        }
                        data = msData.ToArray();
                    }

                    if (data != null && data.Length > 0)
                    {
                        this.bmpImageThumbnail = new RawTGABitmap(iWidth, iHeight, data, pfPixelFormat);

                    }

                }
            }
        }