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; }
/// <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; }
/// <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; }
/// <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; } }
public void ReleaseMap() { m_pTGAInfo = null; m_pPosToAtlasIndex = null; }
private void LoadTgAfile(string file) { Debug.Assert(!string.IsNullOrEmpty(file), "file must be non-nil"); m_pTGAInfo = ImageTGA.Load(CCFileUtils.FullPathFromRelativePath(file)); }
bool LoadRLEImageData(byte[] Buffer, UInt64 bufSize, ImageTGA psInfo) { throw new NotImplementedException(); }
/// <summary> /// converts RGB to greyscale /// </summary> /// <param name="psInfo"></param> public static void RGBToGreyscale(ImageTGA psInfo) { throw new NotImplementedException(); }