Exemple #1
0
        /// <summary>
        /// releases the memory used for the image
        /// </summary>
        /// <param name="psInfo"></param>
        public static void tgaDestroy(tImageTGA psInfo)
        {
            if (psInfo != null)
            {
                if (psInfo.imageData != null)
                {
                    psInfo.imageData = null;
                    //free();
                }

                psInfo = null;
            }
        }
Exemple #2
0
        /// <summary>
        /// load the image header fields. We only keep those that matter!
        /// </summary>
        /// <param name="?"></param>
        /// <returns></returns>
        public static bool tgaLoadHeader(byte[] Buffer, UInt64 bufSize, tImageTGA 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);
        }
Exemple #3
0
        /// <summary>
        /// loads the image pixels. You shouldn't call this function directly
        /// </summary>
        /// <param name="?"></param>
        /// <returns></returns>
        public static bool tgaLoadImageData(byte[] Buffer, UInt64 bufSize, tImageTGA 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);
        }
Exemple #4
0
 bool tgaLoadRLEImageData(byte[] Buffer, UInt64 bufSize, tImageTGA psInfo)
 {
     throw new NotImplementedException();
 }
Exemple #5
0
 /// <summary>
 /// converts RGB to greyscale
 /// </summary>
 /// <param name="psInfo"></param>
 public static void tgaRGBtogreyscale(tImageTGA psInfo)
 {
     throw new NotImplementedException();
 }
Exemple #6
0
        /// <summary>
        /// this is the function to call when we want to load an image
        /// </summary>
        /// <param name="?"></param>
        /// <returns></returns>
        public static tImageTGA tgaLoad(string pszFilename)
        {
            int        mode, total;
            tImageTGA  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);
        }