From 591103b4e5d15a2bddbd2a1e71d4e651a1c2509d Mon Sep 17 00:00:00 2001 From: bsupnik Date: Thu, 14 Nov 2013 12:58:10 -0500 Subject: [PATCH] more removing 'long' as a type (this fixes BMP loading on mac, as if anyone cares) fixed warnings in compiler added logging for missing texture. --- src/BitmapUtils.cpp | 126 ++++++++++++++++++------------------- src/BitmapUtils.h | 78 +++++++++++------------ src/XObjReadWrite.cpp | 4 +- src/XPMPMultiplayerObj.cpp | 2 + 4 files changed, 106 insertions(+), 104 deletions(-) diff --git a/src/BitmapUtils.cpp b/src/BitmapUtils.cpp index 3f54edb84..68cf2a0fb 100644 --- a/src/BitmapUtils.cpp +++ b/src/BitmapUtils.cpp @@ -31,14 +31,14 @@ #if APL #include #if defined(__POWERPC__) -inline void BMP_EndianFlipLong(long * x) { long t = Endian32_Swap(*x); *x = t; } +inline void BMP_EndianFlipInt(int * x) { int t = Endian32_Swap(*x); *x = t; } inline void BMP_EndianFlipShort(short * x) { short t = Endian16_Swap(*x); *x = t; } #else -#define BMP_EndianFlipLong(x) (x) +#define BMP_EndianFlipInt(x) (x) #define BMP_EndianFlipShort(x) (x) #endif #else - #define BMP_EndianFlipLong(x) (x) + #define BMP_EndianFlipInt(x) (x) #define BMP_EndianFlipShort(x) (x) #endif @@ -75,7 +75,7 @@ int CreateBitmapFromFile(const char * inFilePath, struct ImageInfo * outImageIn { struct BMPHeader header; struct BMPImageDesc imageDesc; - long pad; + int pad; int err = 0; FILE * fi = NULL; @@ -93,11 +93,11 @@ int CreateBitmapFromFile(const char * inFilePath, struct ImageInfo * outImageIn if (fread(&imageDesc, sizeof(imageDesc), 1, fi) != 1) goto bail; - BMP_EndianFlipLong(&header.fileSize); - BMP_EndianFlipLong(&header.dataOffset); + BMP_EndianFlipInt(&header.fileSize); + BMP_EndianFlipInt(&header.dataOffset); - BMP_EndianFlipLong(&imageDesc.imageWidth); - BMP_EndianFlipLong(&imageDesc.imageHeight); + BMP_EndianFlipInt(&imageDesc.imageWidth); + BMP_EndianFlipInt(&imageDesc.imageHeight); BMP_EndianFlipShort(&imageDesc.bitCount); if ((header.signature1 != 'B') || @@ -158,9 +158,9 @@ int WriteBitmapToFile(const struct ImageInfo * inImage, const char * inFilePath header.fileSize = sizeof(struct BMPHeader) + sizeof(struct BMPImageDesc) + ((inImage->width * 3 + inImage->pad) * inImage->height); header.reserved = 0; header.dataOffset = sizeof(struct BMPHeader) + sizeof(struct BMPImageDesc); - BMP_EndianFlipLong(&header.fileSize); - BMP_EndianFlipLong(&header.reserved); - BMP_EndianFlipLong(&header.dataOffset); + BMP_EndianFlipInt(&header.fileSize); + BMP_EndianFlipInt(&header.reserved); + BMP_EndianFlipInt(&header.dataOffset); imageDesc.structSize = sizeof(imageDesc); imageDesc.imageWidth = inImage->width; @@ -174,17 +174,17 @@ int WriteBitmapToFile(const struct ImageInfo * inImage, const char * inFilePath imageDesc.colorsUsed = 0; imageDesc.colorsImportant = 0; - BMP_EndianFlipLong(&imageDesc.structSize); - BMP_EndianFlipLong(&imageDesc.imageWidth); - BMP_EndianFlipLong(&imageDesc.imageHeight); + BMP_EndianFlipInt(&imageDesc.structSize); + BMP_EndianFlipInt(&imageDesc.imageWidth); + BMP_EndianFlipInt(&imageDesc.imageHeight); BMP_EndianFlipShort(&imageDesc.planes); BMP_EndianFlipShort(&imageDesc.bitCount); - BMP_EndianFlipLong(&imageDesc.compressionType); - BMP_EndianFlipLong(&imageDesc.imageSize); - BMP_EndianFlipLong(&imageDesc.xPixelsPerM); - BMP_EndianFlipLong(&imageDesc.yPixelsPerM); - BMP_EndianFlipLong(&imageDesc.colorsUsed); - BMP_EndianFlipLong(&imageDesc.colorsImportant); + BMP_EndianFlipInt(&imageDesc.compressionType); + BMP_EndianFlipInt(&imageDesc.imageSize); + BMP_EndianFlipInt(&imageDesc.xPixelsPerM); + BMP_EndianFlipInt(&imageDesc.yPixelsPerM); + BMP_EndianFlipInt(&imageDesc.colorsUsed); + BMP_EndianFlipInt(&imageDesc.colorsImportant); fi = fopen(inFilePath, "wb"); if (fi == NULL) @@ -211,7 +211,7 @@ bail: return err; } -int CreateNewBitmap(long inWidth, long inHeight, short inChannels, struct ImageInfo * outImageInfo) +int CreateNewBitmap(int inWidth, int inHeight, int inChannels, struct ImageInfo * outImageInfo) { outImageInfo->width = inWidth; outImageInfo->height = inHeight; @@ -238,14 +238,14 @@ void DestroyBitmap(const struct ImageInfo * inImageInfo) void CopyBitmapSection( const struct ImageInfo * inSrc, const struct ImageInfo * inDst, - long inSrcLeft, - long inSrcTop, - long inSrcRight, - long inSrcBottom, - long inDstLeft, - long inDstTop, - long inDstRight, - long inDstBottom) + int inSrcLeft, + int inSrcTop, + int inSrcRight, + int inSrcBottom, + int inDstLeft, + int inDstTop, + int inDstRight, + int inDstBottom) { /* This routine copies a subsection of one bitmap onto a subsection of another, using bicubic interpolation for scaling. */ @@ -271,9 +271,9 @@ void CopyBitmapSection( double dx, dy; - long srcRowBytes = inSrc->width * inSrc->channels + inSrc->pad; - long srcRowBytes2 = srcRowBytes * 2; - long dstRowBytes = inDst->width * inSrc->channels + inDst->pad; + int srcRowBytes = inSrc->width * inSrc->channels + inSrc->pad; + int srcRowBytes2 = srcRowBytes * 2; + int dstRowBytes = inDst->width * inSrc->channels + inDst->pad; unsigned char * srcBaseAddr = inSrc->data; unsigned char * dstBaseAddr = inDst->data; @@ -289,8 +289,8 @@ void CopyBitmapSection( double sx = ((dx - dstLeft) / dstWidth * srcWidth) + srcLeft; double sy = ((dy - dstTop) / dstHeight * srcHeight) + srcTop; - unsigned char * dstPixel = dstBaseAddr + ((long) dx * inDst->channels) + ((long) dy * dstRowBytes); - unsigned char * srcPixel = srcBaseAddr + ((long) sx * inSrc->channels) + ((long) sy * srcRowBytes); + unsigned char * dstPixel = dstBaseAddr + ((int) dx * inDst->channels) + ((int) dy * dstRowBytes); + unsigned char * srcPixel = srcBaseAddr + ((int) sx * inSrc->channels) + ((int) sy * srcRowBytes); /* If we would need pixels from off the edge of the image for bicubic interpolation, just use bilinear. */ @@ -355,18 +355,18 @@ inline double Interp2(double frac, double sml, double big) void CopyBitmapSectionWarped( const struct ImageInfo * inSrc, const struct ImageInfo * inDst, - long inTopLeftX, - long inTopLeftY, - long inTopRightX, - long inTopRightY, - long inBotRightX, - long inBotRightY, - long inBotLeftX, - long inBotLeftY, - long inDstLeft, - long inDstTop, - long inDstRight, - long inDstBottom) + int inTopLeftX, + int inTopLeftY, + int inTopRightX, + int inTopRightY, + int inBotRightX, + int inBotRightY, + int inBotLeftX, + int inBotLeftY, + int inDstLeft, + int inDstTop, + int inDstRight, + int inDstBottom) { /* This routine copies a subsection of one bitmap onto a subsection of another, using bicubic interpolation for scaling. */ @@ -391,9 +391,9 @@ void CopyBitmapSectionWarped( double dx, dy; - long srcRowBytes = inSrc->width * inSrc->channels + inSrc->pad; - long srcRowBytes2 = srcRowBytes * 2; - long dstRowBytes = inDst->width * inSrc->channels + inDst->pad; + int srcRowBytes = inSrc->width * inSrc->channels + inSrc->pad; + int srcRowBytes2 = srcRowBytes * 2; + int dstRowBytes = inDst->width * inSrc->channels + inDst->pad; unsigned char * srcBaseAddr = inSrc->data; unsigned char * dstBaseAddr = inDst->data; @@ -412,8 +412,8 @@ void CopyBitmapSectionWarped( double sx = Interp2(frac_y, Interp2(frac_x, topLeftX, topRightX), Interp2(frac_x, botLeftX, botRightX)); double sy = Interp2(frac_x, Interp2(frac_y, topLeftY, botLeftY), Interp2(frac_y, topRightY, botRightY)); - unsigned char * dstPixel = dstBaseAddr + ((long) dx * inDst->channels) + ((long) dy * dstRowBytes); - unsigned char * srcPixel = srcBaseAddr + ((long) sx * inSrc->channels) + ((long) sy * srcRowBytes); + unsigned char * dstPixel = dstBaseAddr + ((int) dx * inDst->channels) + ((int) dy * dstRowBytes); + unsigned char * srcPixel = srcBaseAddr + ((int) sx * inSrc->channels) + ((int) sy * srcRowBytes); /* If we would need pixels from off the edge of the image for bicubic interpolation, just use bilinear. */ @@ -476,22 +476,22 @@ void RotateBitmapCCW( /* We have to allocate a new bitmap to transfer our old data to. The new bitmap might not have the same * storage size as the old bitmap because of padding! */ - long newWidth = ioBitmap->height; - long newHeight = ioBitmap->width; - long newPad = ((newWidth * ioBitmap->channels + 3) & ~3) - (newWidth * ioBitmap->channels); + int newWidth = ioBitmap->height; + int newHeight = ioBitmap->width; + int newPad = ((newWidth * ioBitmap->channels + 3) & ~3) - (newWidth * ioBitmap->channels); unsigned char * newData = (unsigned char *) malloc(((newWidth * ioBitmap->channels) + newPad) * newHeight); if (newData == NULL) return; - for (long y = 0; y < ioBitmap->height; ++y) - for (long x = 0; x < ioBitmap->width; ++x) + for (int y = 0; y < ioBitmap->height; ++y) + for (int x = 0; x < ioBitmap->width; ++x) { - long nx = ioBitmap->height - y - 1; - long ny = x; + int nx = ioBitmap->height - y - 1; + int ny = x; unsigned char * srcP = ioBitmap->data + (x * ioBitmap->channels) + (y * (ioBitmap->channels * ioBitmap->width + ioBitmap->pad)); unsigned char * dstP = newData + (nx * ioBitmap->channels) + (ny * (ioBitmap->channels * newWidth + newPad)); - long chCount = ioBitmap->channels; + int chCount = ioBitmap->channels; while (chCount--) { *dstP++ = *srcP++; @@ -510,8 +510,8 @@ int ConvertBitmapToAlpha( struct ImageInfo * ioImage) { unsigned char * oldData, * newData, * srcPixel, * dstPixel; - long count; - long x,y; + int count; + int x,y; if (ioImage->channels == 4) return 0; @@ -567,8 +567,8 @@ int ConvertAlphaToBitmap( struct ImageInfo * ioImage) { unsigned char * oldData, * newData, * srcPixel, * dstPixel; - long count; - long x,y; + int count; + int x,y; if (ioImage->channels == 3) return 0; diff --git a/src/BitmapUtils.h b/src/BitmapUtils.h index dece79c2b..81ddd7c30 100644 --- a/src/BitmapUtils.h +++ b/src/BitmapUtils.h @@ -34,7 +34,7 @@ */ #if APL -#pragma options align=mac68k +#pragma pack(push, 2) #endif #if IBM #pragma pack(push, 2) @@ -43,27 +43,27 @@ struct BMPHeader { char signature1; char signature2; - long fileSize; - long reserved; - long dataOffset; + int fileSize; + int reserved; + int dataOffset; }; struct BMPImageDesc { - long structSize; - long imageWidth; - long imageHeight; + int structSize; + int imageWidth; + int imageHeight; short planes; short bitCount; - long compressionType; - long imageSize; - long xPixelsPerM; //130B0000? B013 = 45075? - long yPixelsPerM; - long colorsUsed; - long colorsImportant; + int compressionType; + int imageSize; + int xPixelsPerM; //130B0000? B013 = 45075? + int yPixelsPerM; + int colorsUsed; + int colorsImportant; }; #if APL -#pragma options align=reset +#pragma pack(pop) #endif #if IBM #pragma pack(pop) @@ -82,10 +82,10 @@ struct BMPImageDesc { struct ImageInfo { unsigned char * data; - long width; - long height; - long pad; - short channels; + int width; + int height; + int pad; + int channels; }; /* Given a file path and an uninitialized imageInfo structure, this routine fills @@ -110,7 +110,7 @@ int WriteBitmapToFile(const struct ImageInfo * inImage, const char * inFilePath /* This routine creates a new bitmap and fills in an uninitialized imageInfo structure. * The contents of the bitmap are undetermined and must be 'cleared' by you. */ -int CreateNewBitmap(long inWidth, long inHeight, short inChannels, struct ImageInfo * outImageInfo); +int CreateNewBitmap(int inWidth, int inHeight, int inChannels, struct ImageInfo * outImageInfo); /* Given a bitmap, this routine fills the whole bitmap in with a gray level of c, where * c = 0 means black and c = 255 means white. */ @@ -127,30 +127,30 @@ void DestroyBitmap(const struct ImageInfo * inImageInfo); void CopyBitmapSection( const struct ImageInfo * inSrc, const struct ImageInfo * inDst, - long inSrcLeft, - long inSrcTop, - long inSrcRight, - long inSrcBottom, - long inDstLeft, - long inDstTop, - long inDstRight, - long inDstBottom); + int inSrcLeft, + int inSrcTop, + int inSrcRight, + int inSrcBottom, + int inDstLeft, + int inDstTop, + int inDstRight, + int inDstBottom); void CopyBitmapSectionWarped( const struct ImageInfo * inSrc, const struct ImageInfo * inDst, - long inTopLeftX, - long inTopLeftY, - long inTopRightX, - long inTopRightY, - long inBotRightX, - long inBotRightY, - long inBotLeftX, - long inBotLeftY, - long inDstLeft, - long inDstTop, - long inDstRight, - long inDstBottom); + int inTopLeftX, + int inTopLeftY, + int inTopRightX, + int inTopRightY, + int inBotRightX, + int inBotRightY, + int inBotLeftX, + int inBotLeftY, + int inDstLeft, + int inDstTop, + int inDstRight, + int inDstBottom); /* This routine rotates a bitmap counterclockwise 90 degrees, exchanging its width * and height. */ diff --git a/src/XObjReadWrite.cpp b/src/XObjReadWrite.cpp index b57e8c9c1..41f78868d 100644 --- a/src/XObjReadWrite.cpp +++ b/src/XObjReadWrite.cpp @@ -360,7 +360,7 @@ bool XObjWrite(const char * inFile, const XObj& inObj) case type_PtLine: if (gCmds[index].elem_count == 0) - fprintf(fi,"%s %d\t\t//" CRLF, gCmds[index].name, iter->rgb.size()); + fprintf(fi,"%s %zd\t\t//" CRLF, gCmds[index].name, iter->rgb.size()); else fprintf(fi,"%s\t\t//" CRLF, gCmds[index].name); @@ -378,7 +378,7 @@ bool XObjWrite(const char * inFile, const XObj& inObj) case type_Poly: if (gCmds[index].elem_count == 0) - fprintf(fi,"%s %d\t\t//" CRLF, gCmds[index].name, iter->st.size()); + fprintf(fi,"%s %zd\t\t//" CRLF, gCmds[index].name, iter->st.size()); else fprintf(fi,"%s\t\t//" CRLF, gCmds[index].name); diff --git a/src/XPMPMultiplayerObj.cpp b/src/XPMPMultiplayerObj.cpp index ed0c1a6c0..397169686 100644 --- a/src/XPMPMultiplayerObj.cpp +++ b/src/XPMPMultiplayerObj.cpp @@ -345,6 +345,8 @@ int OBJ_LoadModel(const char * inFilePath) tex_path += sObjects.back().obj.texture; tex_path += ".png"; sObjects.back().texnum = OBJ_LoadTexture(tex_path.c_str(), false); + if(sObjects.back().texnum == 0) + printf("WARNING: %s failed to load for %s.\n", tex_path.c_str(),inFilePath); tex_path = path; p = tex_path.find_last_of("\\:/");//XPLMGetDirectorySeparator());