public static CCData dataWithContentsOfFile(string strPath) { CCFileData data = new CCFileData(strPath, "rb"); ulong nSize = data.Size; byte[] pBuffer = data.Buffer; if (pBuffer == null) { return(null); } CCData pRet = new CCData(); pRet.m_pData = pBuffer; //memcpy(pRet->m_pData, pBuffer, nSize); return(pRet); }
/// <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); }