Ejemplo n.º 1
0
        /// <summary>
        /// releases the memory used for the image
        /// </summary>
        /// <param name="psInfo"></param>
        public static void Destroy(ImageTGA psInfo)
        {
            if (psInfo != null)
            {
                if (psInfo.imageData != null)
                {
                    psInfo.imageData = null;
                    //free();
                }

                psInfo = null;
            }
        }
Ejemplo n.º 2
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, UInt64 bufSize, ImageTGA psInfo)
        {
            bool bRet = false;

            //do
            //{
            //    UInt64 step = sizeof(char) * 2;
            //    if ((step + sizeof(char)) > bufSize)
            //    {
            //        break;
            //    }

            //    memcpy(psInfo.type, Buffer + step, sizeof(char));

            //    step += sizeof(char) * 2;
            //    step += sizeof(short) * 4;
            //    if ((step + sizeof(short) * 2 + sizeof(char)) > bufSize)
            //    {
            //        break;
            //    }
            //    memcpy(psInfo.width, Buffer + step, sizeof(short));
            //    memcpy(psInfo.height, Buffer + step + sizeof(short), sizeof(short));
            //    memcpy(psInfo.pixelDepth, Buffer + step + sizeof(short) * 2, sizeof(char));

            //    step += sizeof(char);
            //    step += sizeof(short) * 2;
            //    if ((step + sizeof(char)) > bufSize)
            //    {
            //        break;
            //    }
            //    char cGarbage;
            //    memcpy(cGarbage, Buffer + step, sizeof(char));

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

            return(bRet);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// loads the image pixels. You shouldn't call this function directly
        /// </summary>
        /// <param name="?"></param>
        /// <returns></returns>
        public static bool LoadImageData(byte[] Buffer, UInt64 bufSize, ImageTGA psInfo)
        {
            bool bRet = false;

            //do
            //{
            //    int mode, total, i;
            //    char aux;
            //    UInt64 step = (sizeof(char) + sizeof(short)) * 6;

            //    // mode equal the number of components for each pixel
            //    mode = psInfo.pixelDepth / 8;
            //    // total is the number of unsigned chars we'll have to read
            //    total = psInfo.height * psInfo.width * mode;

            //    size_t dataSize = sizeof(char) * total;
            //    if ((step + dataSize) > bufSize)
            //    {
            //        break;
            //    }
            //    memcpy(psInfo.imageData, Buffer + step, dataSize);

            //    // 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)
            //    {
            //        for (i = 0; i < total; i += mode)
            //        {
            //            aux = psInfo.imageData[i];
            //            psInfo.imageData[i] = psInfo.imageData[i + 2];
            //            psInfo.imageData[i + 2] = aux;
            //        }
            //    }

            //    bRet = true;
            //} while (0);

            return(bRet);
        }
Ejemplo n.º 4
0
        public static ImageTGA Load(string filename)
        {
            var tex = CCApplication.SharedApplication.Content.Load<Texture2D>(filename);

            var image = new ImageTGA();

            image.width = (short) tex.Width;
            image.height = (short) tex.Height;

            image.imageData = new Color[tex.Width * tex.Height];
            tex.GetData(image.imageData);

            var tmp = new Color[tex.Width];
            for (int i = 0; i < tex.Height / 2; i++)
            {
                Array.Copy(image.imageData, i * tex.Width, tmp, 0, tex.Width);
                Array.Copy(image.imageData, (tex.Height - i - 1) * tex.Width, image.imageData, i * tex.Width, tex.Width);
                Array.Copy(tmp, 0, image.imageData, (tex.Height - i - 1) * tex.Width, tex.Width);
            }
            
            return image;
        }
Ejemplo n.º 5
0
        public static ImageTGA Load(string filename)
        {
            var tex = CCApplication.SharedApplication.Content.Load <Texture2D>(filename);

            var image = new ImageTGA();

            image.width  = (short)tex.Width;
            image.height = (short)tex.Height;

            image.imageData = new Color[tex.Width * tex.Height];
            tex.GetData(image.imageData);

            var tmp = new Color[tex.Width];

            for (int i = 0; i < tex.Height / 2; i++)
            {
                Array.Copy(image.imageData, i * tex.Width, tmp, 0, tex.Width);
                Array.Copy(image.imageData, (tex.Height - i - 1) * tex.Width, image.imageData, i * tex.Width, tex.Width);
                Array.Copy(tmp, 0, image.imageData, (tex.Height - i - 1) * tex.Width, tex.Width);
            }

            return(image);
        }
Ejemplo n.º 6
0
 bool LoadRLEImageData(byte[] Buffer, UInt64 bufSize, ImageTGA psInfo)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 7
0
 /// <summary>
 /// converts RGB to greyscale
 /// </summary>
 /// <param name="psInfo"></param>
 public static void RGBToGreyscale(ImageTGA psInfo)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 8
0
        /// <summary>
        /// this is the function to call when we want to load an image
        /// </summary>
        /// <param name="?"></param>
        /// <returns></returns>
        public static ImageTGA Load(string pszFilename)
        {
            //int mode, total;
            ImageTGA 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.º 9
0
        private void LoadTgAfile(string file)
        {
            Debug.Assert(!string.IsNullOrEmpty(file), "file must be non-nil");

            m_pTGAInfo = ImageTGA.Load(CCFileUtils.FullPathFromRelativePath(file));
        }
Ejemplo n.º 10
0
 /// <summary>
 /// converts RGB to greyscale
 /// </summary>
 /// <param name="psInfo"></param>
 public static void RGBToGreyscale(ImageTGA psInfo) 
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 11
0
        private void LoadTgAfile(string file)
        {
            Debug.Assert(!string.IsNullOrEmpty(file), "file must be non-nil");

            m_pTGAInfo = ImageTGA.Load(CCFileUtils.FullPathFromRelativePath(file));
        }
Ejemplo n.º 12
0
 public void ReleaseMap()
 {
     m_pTGAInfo         = null;
     m_pPosToAtlasIndex = null;
 }
Ejemplo n.º 13
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, UInt64 bufSize, ImageTGA psInfo)
        {
            bool bRet = false;

            //do
            //{
            //    UInt64 step = sizeof(char) * 2;
            //    if ((step + sizeof(char)) > bufSize)
            //    {
            //        break;
            //    }

            //    memcpy(psInfo.type, Buffer + step, sizeof(char));

            //    step += sizeof(char) * 2;
            //    step += sizeof(short) * 4;
            //    if ((step + sizeof(short) * 2 + sizeof(char)) > bufSize)
            //    {
            //        break;
            //    }
            //    memcpy(psInfo.width, Buffer + step, sizeof(short));
            //    memcpy(psInfo.height, Buffer + step + sizeof(short), sizeof(short));
            //    memcpy(psInfo.pixelDepth, Buffer + step + sizeof(short) * 2, sizeof(char));

            //    step += sizeof(char);
            //    step += sizeof(short) * 2;
            //    if ((step + sizeof(char)) > bufSize)
            //    {
            //        break;
            //    }
            //    char cGarbage;
            //    memcpy(cGarbage, Buffer + step, sizeof(char));

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

            return bRet;
        }
Ejemplo n.º 14
0
 bool LoadRLEImageData(byte[] Buffer, UInt64 bufSize, ImageTGA psInfo) 
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 15
0
        /// <summary>
        /// releases the memory used for the image
        /// </summary>
        /// <param name="psInfo"></param>
        public static void Destroy(ImageTGA psInfo)
        {
            if (psInfo != null)
            {
                if (psInfo.imageData != null)
                {
                    psInfo.imageData = null;
                    //free();
                }

                psInfo = null;
            }
        }
Ejemplo n.º 16
0
 public void ReleaseMap()
 {
     m_pTGAInfo = null;
     m_pPosToAtlasIndex = null;
 }
Ejemplo n.º 17
0
        /// <summary>
        /// loads the image pixels. You shouldn't call this function directly
        /// </summary>
        /// <param name="?"></param>
        /// <returns></returns>
        public static bool LoadImageData(byte[] Buffer, UInt64 bufSize, ImageTGA psInfo)
        {
            bool bRet = false;

            //do
            //{
            //    int mode, total, i;
            //    char aux;
            //    UInt64 step = (sizeof(char) + sizeof(short)) * 6;

            //    // mode equal the number of components for each pixel
            //    mode = psInfo.pixelDepth / 8;
            //    // total is the number of unsigned chars we'll have to read
            //    total = psInfo.height * psInfo.width * mode;

            //    size_t dataSize = sizeof(char) * total;
            //    if ((step + dataSize) > bufSize)
            //    {
            //        break;
            //    }
            //    memcpy(psInfo.imageData, Buffer + step, dataSize);

            //    // 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)
            //    {
            //        for (i = 0; i < total; i += mode)
            //        {
            //            aux = psInfo.imageData[i];
            //            psInfo.imageData[i] = psInfo.imageData[i + 2];
            //            psInfo.imageData[i + 2] = aux;
            //        }
            //    }

            //    bRet = true;
            //} while (0);

            return bRet;
          
        }