Ejemplo n.º 1
0
        /// <summary>
        /// loads the image pixels. You shouldn't call this function directly
        /// </summary>
        /// <param name="buffer">red,green,blue pixel values</param>
        /// <returns></returns>
        public static bool LoadImageData(byte[] buffer, int bufSize, CCImageTGA psInfo)
        {
            int mode;
            int headerSkip = (1 + 2) * 6; // sizeof(char) + sizeof(short) = size of the header

            // mode equal the number of components for each pixel
            mode = psInfo.PixelDepth / 8;

            // mode=3 or 4 implies that the image is RGB(A). However TGA
            // stores it as BGR(A) so we'll have to swap R and B.
            if (mode >= 3)
            {
                int cx = 0;
                for (int i = headerSkip; i < buffer.Length; i += mode)
                {
                    psInfo.ImageData[cx].R = buffer[i + 2];
                    psInfo.ImageData[cx].G = buffer[i + 1];
                    psInfo.ImageData[cx].B = buffer[i];
                    if (mode == 4)
                    {
                        psInfo.ImageData[cx].A = buffer[i + 3];
                    }
                    else
                    {
                        psInfo.ImageData[cx].A = 255;
                    }
                }
            }
            else
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 2
0
        public static CCImageTGA Load(byte[] buffer)
        {
            var info = new CCImageTGA();

            LoadHeader(buffer, buffer.Length, info);

            return(info);
        }
Ejemplo n.º 3
0
        CCTileMapAtlas(string tile, int tileWidth, int tileHeight, CCImageTGA tgaInfo, int numOfItemsToRender)
            : base(tile, tileWidth, tileHeight, numOfItemsToRender)
        {
            TGAInfo            = tgaInfo;
            NumOfItemsToRender = numOfItemsToRender;

            PositionToAtlasIndex = new Dictionary <CCGridSize, int>();
            UpdateAtlasValues();
            ContentSize = new CCSize(TGAInfo.Width * ItemWidth, TGAInfo.Height * ItemHeight);
        }
Ejemplo n.º 4
0
        CCTileMapAtlas(string tile, int tileWidth, int tileHeight, CCImageTGA tgaInfo, int numOfItemsToRender)
            : base(tile, tileWidth, tileHeight, numOfItemsToRender)
        {
            TGAInfo = tgaInfo;
            NumOfItemsToRender = numOfItemsToRender;

            PositionToAtlasIndex = new Dictionary<CCGridSize, int>();
            UpdateAtlasValues();
            ContentSize = new CCSize(TGAInfo.Width * ItemWidth, TGAInfo.Height * ItemHeight);
        }
Ejemplo n.º 5
0
        // Just used during construction
        static int CalculateItemsToRender(CCImageTGA tgaInfo)
        {
            Debug.Assert(tgaInfo != null, "tgaInfo must be non-nil");

            int itemsToRender = 0;
            var data = tgaInfo.ImageData;
            for (int i = 0, count = tgaInfo.Width * tgaInfo.Height; i < count;  i++)
            {
                if (data[i].R != 0)
                {
                    ++itemsToRender;
                }
            }

            return itemsToRender;
        }
Ejemplo n.º 6
0
        // Just used during construction
        static int CalculateItemsToRender(CCImageTGA tgaInfo)
        {
            Debug.Assert(tgaInfo != null, "tgaInfo must be non-nil");

            int itemsToRender = 0;
            var data          = tgaInfo.ImageData;

            for (int i = 0, count = tgaInfo.Width * tgaInfo.Height; i < count; i++)
            {
                if (data[i].R != 0)
                {
                    ++itemsToRender;
                }
            }

            return(itemsToRender);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// loads the image pixels. You shouldn't call this function directly
        /// </summary>
        /// <param name="buffer">red,green,blue pixel values</param>
        /// <returns></returns>
        public static bool LoadImageData(byte[] buffer, int bufSize, CCImageTGA psInfo)
        {
            int mode;
            int headerSkip = (1 + 2) * 6; // sizeof(char) + sizeof(short) = size of the header

            // mode equal the number of components for each pixel
			mode = psInfo.PixelDepth / 8;

            // mode=3 or 4 implies that the image is RGB(A). However TGA
            // stores it as BGR(A) so we'll have to swap R and B.
            if (mode >= 3)
            {
                int cx = 0;
                for (int i = headerSkip; i < buffer.Length; i += mode)
                {
                    psInfo.ImageData[cx].R = buffer[i + 2];
                    psInfo.ImageData[cx].G = buffer[i + 1];
                    psInfo.ImageData[cx].B = buffer[i];
                    if (mode == 4)
                    {
                        psInfo.ImageData[cx].A = buffer[i + 3];
                    }
                    else
                    {
                        psInfo.ImageData[cx].A = 255;
                    }
                }
            }
            else
            {
                return (false);
            }
            return true;

        }
Ejemplo n.º 8
0
 public void ReleaseMap()
 {
     TGAInfo = null;
     PositionToAtlasIndex = null;
 }
Ejemplo n.º 9
0
 CCTileMapAtlas(string tile, string mapFile, int tileWidth, int tileHeight, CCImageTGA tgaInfo)
     : this(tile, tileWidth, tileHeight, tgaInfo, CalculateItemsToRender(tgaInfo))
 {
 }
Ejemplo n.º 10
0
 bool LoadRLEImageData(byte[] Buffer, UInt64 bufSize, CCImageTGA psInfo) 
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 11
0
 /// <summary>
 /// converts RGB to greyscale
 /// </summary>
 /// <param name="psInfo"></param>
 public static void RGBToGreyscale(CCImageTGA psInfo)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 12
0
        /// <summary>
        /// this is the function to call when we want to load an image
        /// </summary>
        /// <param name="?"></param>
        /// <returns></returns>
        public static CCImageTGA Load(string filename)
        {
            //int mode, total;
            CCImageTGA info = null;

            //CCFileData data = new CCFileData(pszFilename, "rb");
            //UInt64 nSize = data.Size;
            //byte[] pBuffer = data.Buffer;

            //do
            //{
            //    if (pBuffer == null)
            //    {
            //        break;
            //    }
            //    //info = malloc(sizeof(tImageTGA)) as tImageTGA;

            //    // get the file header info
            //    if (tgaLoadHeader(pBuffer, nSize, info) == null)
            //    {
            //        info.status = (int)TGAEnum.TGA_ERROR_MEMORY;
            //        break;
            //    }

            //    // check if the image is color indexed
            //    if (info.type == 1)
            //    {
            //        info.status = (int)TGAEnum.TGA_ERROR_INDEXED_COLOR;
            //        break;
            //    }

            //    // check for other types (compressed images)
            //    if ((info.type != 2) && (info.type != 3) && (info.type != 10))
            //    {
            //        info.status = (int)TGAEnum.TGA_ERROR_COMPRESSED_FILE;
            //        break;
            //    }

            //    // mode equals the number of image components
            //    mode = info.pixelDepth / 8;
            //    // total is the number of unsigned chars to read
            //    total = info.height * info.width * mode;
            //    // allocate memory for image pixels
            //    // info.imageData = (char[])malloc(sizeof(unsigned char) * total);

            //    // check to make sure we have the memory required
            //    if (info.imageData == null)
            //    {
            //        info.status = (int)TGAEnum.TGA_ERROR_MEMORY;
            //        break;
            //    }

            //    bool bLoadImage = false;
            //    // finally load the image pixels
            //    if (info.type == 10)
            //    {
            //        bLoadImage = tgaLoadRLEImageData(pBuffer,nSize, info);
            //    }
            //    else
            //    {
            //        bLoadImage = tgaLoadImageData(pBuffer, nSize, info);
            //    }

            //    // check for errors when reading the pixels
            //    if (!bLoadImage)
            //    {
            //        info.status = TGAEnum.TGA_ERROR_READING_FILE;
            //        break;
            //    }
            //    info->status = TGA_OK;

            //    if (info->flipped)
            //    {
            //        tgaFlipImage(info);
            //        if (info->flipped)
            //        {
            //            info->status = TGA_ERROR_MEMORY;
            //        }
            //    }
            //} while (0);

            return(info);
        }
Ejemplo n.º 13
0
 public void ReleaseMap()
 {
     TGAInfo = null;
     PositionToAtlasIndex = null;
 }
Ejemplo n.º 14
0
        public static CCImageTGA Load(byte[] buffer)
        {
            var info = new CCImageTGA();

            LoadHeader(buffer, buffer.Length, info);

            return info;
        }
Ejemplo n.º 15
0
 bool LoadRLEImageData(byte[] Buffer, UInt64 bufSize, CCImageTGA psInfo)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 16
0
 /// <summary>
 /// converts RGB to greyscale
 /// </summary>
 /// <param name="psInfo"></param>
 public static void RGBToGreyscale(CCImageTGA psInfo) 
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 17
0
        /// <summary>
        /// load the image header fields. We only keep those that matter!
        /// </summary>
        /// <param name="?"></param>
        /// <returns></returns>
        public static bool LoadHeader(byte[] buffer, int bufSize, CCImageTGA psInfo)
        {
            TGAHeader header;
            int       pos = 0;

            header.Idlength = ReadByte(buffer, pos);
            pos++;
            header.Colourmaptype = ReadByte(buffer, pos);
            pos++;
            header.Datatypecode = ReadByte(buffer, pos);
            pos++;
            header.Colourmaporigin = ReadShort(buffer, pos);
            pos += 2;
            header.Colourmaplength = ReadShort(buffer, pos);
            pos += 2;
            header.Colourmapdepth = ReadByte(buffer, pos);
            pos++;
            header.Xorigin      = ReadShort(buffer, pos);
            pos                += 2;
            header.Yorigin      = ReadShort(buffer, pos);
            pos                += 2;
            header.Width        = ReadShort(buffer, pos);
            pos                += 2;
            header.Height       = ReadShort(buffer, pos);
            pos                += 2;
            header.Bitsperpixel = ReadByte(buffer, pos);
            pos++;
            header.Imagedescriptor = ReadByte(buffer, pos);
            pos++;

            /*
             *
             * bool bRet = false;
             *
             * do
             * {
             *  int step = sizeof (byte) * 2;
             *  if ((step + sizeof (byte)) > bufSize)
             *  {
             *      break;
             *  }
             *
             *  psInfo.type = ReadByte(buffer, step);
             *
             *  step += sizeof (byte) * 2;
             *  step += sizeof (short) * 4;
             *  if ((step + sizeof (short) * 2 + sizeof (char)) > bufSize)
             *  {
             *      break;
             *  }
             *
             *  psInfo.width = ReadShort(buffer, step);
             *  psInfo.height = ReadShort(buffer, step + sizeof (short));
             *  psInfo.pixelDepth = ReadByte(buffer, step + sizeof (short) * 2);
             *
             *  step += sizeof (char);
             *  step += sizeof (short) * 2;
             *  if ((step + sizeof (byte)) > bufSize)
             *  {
             *      break;
             *  }
             *
             *  byte cGarbage = ReadByte(buffer, step);
             *
             *  psInfo.flipped = 0;
             *  if ((cGarbage & 0x20) != 0)
             *  {
             *      psInfo.flipped = 1;
             *  }
             *  bRet = true;
             * } while (true);
             */

            return(true);
        }
Ejemplo n.º 18
0
        /// <summary>
        /// load the image header fields. We only keep those that matter!
        /// </summary>
        /// <param name="?"></param>
        /// <returns></returns>
        public static bool LoadHeader(byte[] buffer, int bufSize, CCImageTGA psInfo)
        {
            TGAHeader header;
            int pos = 0;

			header.Idlength = ReadByte(buffer, pos);
            pos++;
			header.Colourmaptype = ReadByte(buffer, pos);
            pos++;
			header.Datatypecode = ReadByte(buffer, pos);
            pos++;
			header.Colourmaporigin = ReadShort(buffer, pos);
            pos += 2;
			header.Colourmaplength = ReadShort(buffer, pos);
            pos += 2;
			header.Colourmapdepth = ReadByte(buffer, pos);
            pos++;
			header.Xorigin = ReadShort(buffer, pos);
            pos += 2;
			header.Yorigin = ReadShort(buffer, pos);
            pos += 2;
			header.Width = ReadShort(buffer, pos);
            pos += 2;
			header.Height = ReadShort(buffer, pos);
            pos += 2;
			header.Bitsperpixel = ReadByte(buffer, pos);
            pos++;
			header.Imagedescriptor = ReadByte(buffer, pos);
            pos++;

            /*

            bool bRet = false;

            do
            {
                int step = sizeof (byte) * 2;
                if ((step + sizeof (byte)) > bufSize)
                {
                    break;
                }

                psInfo.type = ReadByte(buffer, step);

                step += sizeof (byte) * 2;
                step += sizeof (short) * 4;
                if ((step + sizeof (short) * 2 + sizeof (char)) > bufSize)
                {
                    break;
                }

                psInfo.width = ReadShort(buffer, step);
                psInfo.height = ReadShort(buffer, step + sizeof (short));
                psInfo.pixelDepth = ReadByte(buffer, step + sizeof (short) * 2);

                step += sizeof (char);
                step += sizeof (short) * 2;
                if ((step + sizeof (byte)) > bufSize)
                {
                    break;
                }

                byte cGarbage = ReadByte(buffer, step);

                psInfo.flipped = 0;
                if ((cGarbage & 0x20) != 0)
                {
                    psInfo.flipped = 1;
                }
                bRet = true;
            } while (true);
            */

            return true;
        }
Ejemplo n.º 19
0
 CCTileMapAtlas(string tile, string mapFile, int tileWidth, int tileHeight, CCImageTGA tgaInfo)
     : this(tile, tileWidth, tileHeight, tgaInfo, CalculateItemsToRender(tgaInfo))
 {
 }