/// <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); }
public static CCImageTGA Load(byte[] buffer) { var info = new CCImageTGA(); LoadHeader(buffer, buffer.Length, info); return(info); }
/// <summary> /// releases the memory used for the image /// </summary> /// <param name="psInfo"></param> public static void Destroy(CCImageTGA psInfo) { if (psInfo != null) { if (psInfo.imageData != null) { psInfo.imageData = null; //free(); } psInfo = null; } }
/// <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, CCImageTGA 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); }
/// <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.x_origin = ReadShort(buffer, pos); pos += 2; header.y_origin = 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); }
private void LoadTgAfile(string file) { Debug.Assert(!string.IsNullOrEmpty(file), "file must be non-nil"); m_pTGAInfo = new CCImageTGA(CCFileUtils.FullPathFromRelativePath(file)); }
public void ReleaseMap() { m_pTGAInfo = null; m_pPosToAtlasIndex = null; }
/// <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, CCImageTGA 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; }
/// <summary> /// converts RGB to greyscale /// </summary> /// <param name="psInfo"></param> public static void RGBToGreyscale(CCImageTGA psInfo) { throw new NotImplementedException(); }
bool LoadRLEImageData(byte[] Buffer, UInt64 bufSize, CCImageTGA psInfo) { throw new NotImplementedException(); }
public static CCImageTGA Load(byte[] buffer) { var info = new CCImageTGA(); LoadHeader(buffer, buffer.Length, info); return info; }
/// <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; }
/// <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.x_origin = ReadShort(buffer, pos); pos += 2; header.y_origin = 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; }
/// <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 pszFilename) { //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); }