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.
This commit is contained in:
bsupnik
2013-11-14 12:58:10 -05:00
parent 9a6c6a9778
commit 591103b4e5
4 changed files with 106 additions and 104 deletions

View File

@@ -31,14 +31,14 @@
#if APL #if APL
#include <Carbon/Carbon.h> #include <Carbon/Carbon.h>
#if defined(__POWERPC__) #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; } inline void BMP_EndianFlipShort(short * x) { short t = Endian16_Swap(*x); *x = t; }
#else #else
#define BMP_EndianFlipLong(x) (x) #define BMP_EndianFlipInt(x) (x)
#define BMP_EndianFlipShort(x) (x) #define BMP_EndianFlipShort(x) (x)
#endif #endif
#else #else
#define BMP_EndianFlipLong(x) (x) #define BMP_EndianFlipInt(x) (x)
#define BMP_EndianFlipShort(x) (x) #define BMP_EndianFlipShort(x) (x)
#endif #endif
@@ -75,7 +75,7 @@ int CreateBitmapFromFile(const char * inFilePath, struct ImageInfo * outImageIn
{ {
struct BMPHeader header; struct BMPHeader header;
struct BMPImageDesc imageDesc; struct BMPImageDesc imageDesc;
long pad; int pad;
int err = 0; int err = 0;
FILE * fi = NULL; FILE * fi = NULL;
@@ -93,11 +93,11 @@ int CreateBitmapFromFile(const char * inFilePath, struct ImageInfo * outImageIn
if (fread(&imageDesc, sizeof(imageDesc), 1, fi) != 1) if (fread(&imageDesc, sizeof(imageDesc), 1, fi) != 1)
goto bail; goto bail;
BMP_EndianFlipLong(&header.fileSize); BMP_EndianFlipInt(&header.fileSize);
BMP_EndianFlipLong(&header.dataOffset); BMP_EndianFlipInt(&header.dataOffset);
BMP_EndianFlipLong(&imageDesc.imageWidth); BMP_EndianFlipInt(&imageDesc.imageWidth);
BMP_EndianFlipLong(&imageDesc.imageHeight); BMP_EndianFlipInt(&imageDesc.imageHeight);
BMP_EndianFlipShort(&imageDesc.bitCount); BMP_EndianFlipShort(&imageDesc.bitCount);
if ((header.signature1 != 'B') || 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.fileSize = sizeof(struct BMPHeader) + sizeof(struct BMPImageDesc) + ((inImage->width * 3 + inImage->pad) * inImage->height);
header.reserved = 0; header.reserved = 0;
header.dataOffset = sizeof(struct BMPHeader) + sizeof(struct BMPImageDesc); header.dataOffset = sizeof(struct BMPHeader) + sizeof(struct BMPImageDesc);
BMP_EndianFlipLong(&header.fileSize); BMP_EndianFlipInt(&header.fileSize);
BMP_EndianFlipLong(&header.reserved); BMP_EndianFlipInt(&header.reserved);
BMP_EndianFlipLong(&header.dataOffset); BMP_EndianFlipInt(&header.dataOffset);
imageDesc.structSize = sizeof(imageDesc); imageDesc.structSize = sizeof(imageDesc);
imageDesc.imageWidth = inImage->width; imageDesc.imageWidth = inImage->width;
@@ -174,17 +174,17 @@ int WriteBitmapToFile(const struct ImageInfo * inImage, const char * inFilePath
imageDesc.colorsUsed = 0; imageDesc.colorsUsed = 0;
imageDesc.colorsImportant = 0; imageDesc.colorsImportant = 0;
BMP_EndianFlipLong(&imageDesc.structSize); BMP_EndianFlipInt(&imageDesc.structSize);
BMP_EndianFlipLong(&imageDesc.imageWidth); BMP_EndianFlipInt(&imageDesc.imageWidth);
BMP_EndianFlipLong(&imageDesc.imageHeight); BMP_EndianFlipInt(&imageDesc.imageHeight);
BMP_EndianFlipShort(&imageDesc.planes); BMP_EndianFlipShort(&imageDesc.planes);
BMP_EndianFlipShort(&imageDesc.bitCount); BMP_EndianFlipShort(&imageDesc.bitCount);
BMP_EndianFlipLong(&imageDesc.compressionType); BMP_EndianFlipInt(&imageDesc.compressionType);
BMP_EndianFlipLong(&imageDesc.imageSize); BMP_EndianFlipInt(&imageDesc.imageSize);
BMP_EndianFlipLong(&imageDesc.xPixelsPerM); BMP_EndianFlipInt(&imageDesc.xPixelsPerM);
BMP_EndianFlipLong(&imageDesc.yPixelsPerM); BMP_EndianFlipInt(&imageDesc.yPixelsPerM);
BMP_EndianFlipLong(&imageDesc.colorsUsed); BMP_EndianFlipInt(&imageDesc.colorsUsed);
BMP_EndianFlipLong(&imageDesc.colorsImportant); BMP_EndianFlipInt(&imageDesc.colorsImportant);
fi = fopen(inFilePath, "wb"); fi = fopen(inFilePath, "wb");
if (fi == NULL) if (fi == NULL)
@@ -211,7 +211,7 @@ bail:
return err; 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->width = inWidth;
outImageInfo->height = inHeight; outImageInfo->height = inHeight;
@@ -238,14 +238,14 @@ void DestroyBitmap(const struct ImageInfo * inImageInfo)
void CopyBitmapSection( void CopyBitmapSection(
const struct ImageInfo * inSrc, const struct ImageInfo * inSrc,
const struct ImageInfo * inDst, const struct ImageInfo * inDst,
long inSrcLeft, int inSrcLeft,
long inSrcTop, int inSrcTop,
long inSrcRight, int inSrcRight,
long inSrcBottom, int inSrcBottom,
long inDstLeft, int inDstLeft,
long inDstTop, int inDstTop,
long inDstRight, int inDstRight,
long inDstBottom) int inDstBottom)
{ {
/* This routine copies a subsection of one bitmap onto a subsection of another, using bicubic interpolation /* This routine copies a subsection of one bitmap onto a subsection of another, using bicubic interpolation
for scaling. */ for scaling. */
@@ -271,9 +271,9 @@ void CopyBitmapSection(
double dx, dy; double dx, dy;
long srcRowBytes = inSrc->width * inSrc->channels + inSrc->pad; int srcRowBytes = inSrc->width * inSrc->channels + inSrc->pad;
long srcRowBytes2 = srcRowBytes * 2; int srcRowBytes2 = srcRowBytes * 2;
long dstRowBytes = inDst->width * inSrc->channels + inDst->pad; int dstRowBytes = inDst->width * inSrc->channels + inDst->pad;
unsigned char * srcBaseAddr = inSrc->data; unsigned char * srcBaseAddr = inSrc->data;
unsigned char * dstBaseAddr = inDst->data; unsigned char * dstBaseAddr = inDst->data;
@@ -289,8 +289,8 @@ void CopyBitmapSection(
double sx = ((dx - dstLeft) / dstWidth * srcWidth) + srcLeft; double sx = ((dx - dstLeft) / dstWidth * srcWidth) + srcLeft;
double sy = ((dy - dstTop) / dstHeight * srcHeight) + srcTop; double sy = ((dy - dstTop) / dstHeight * srcHeight) + srcTop;
unsigned char * dstPixel = dstBaseAddr + ((long) dx * inDst->channels) + ((long) dy * dstRowBytes); unsigned char * dstPixel = dstBaseAddr + ((int) dx * inDst->channels) + ((int) dy * dstRowBytes);
unsigned char * srcPixel = srcBaseAddr + ((long) sx * inSrc->channels) + ((long) sy * srcRowBytes); 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, /* If we would need pixels from off the edge of the image for bicubic interpolation,
just use bilinear. */ just use bilinear. */
@@ -355,18 +355,18 @@ inline double Interp2(double frac, double sml, double big)
void CopyBitmapSectionWarped( void CopyBitmapSectionWarped(
const struct ImageInfo * inSrc, const struct ImageInfo * inSrc,
const struct ImageInfo * inDst, const struct ImageInfo * inDst,
long inTopLeftX, int inTopLeftX,
long inTopLeftY, int inTopLeftY,
long inTopRightX, int inTopRightX,
long inTopRightY, int inTopRightY,
long inBotRightX, int inBotRightX,
long inBotRightY, int inBotRightY,
long inBotLeftX, int inBotLeftX,
long inBotLeftY, int inBotLeftY,
long inDstLeft, int inDstLeft,
long inDstTop, int inDstTop,
long inDstRight, int inDstRight,
long inDstBottom) int inDstBottom)
{ {
/* This routine copies a subsection of one bitmap onto a subsection of another, using bicubic interpolation /* This routine copies a subsection of one bitmap onto a subsection of another, using bicubic interpolation
for scaling. */ for scaling. */
@@ -391,9 +391,9 @@ void CopyBitmapSectionWarped(
double dx, dy; double dx, dy;
long srcRowBytes = inSrc->width * inSrc->channels + inSrc->pad; int srcRowBytes = inSrc->width * inSrc->channels + inSrc->pad;
long srcRowBytes2 = srcRowBytes * 2; int srcRowBytes2 = srcRowBytes * 2;
long dstRowBytes = inDst->width * inSrc->channels + inDst->pad; int dstRowBytes = inDst->width * inSrc->channels + inDst->pad;
unsigned char * srcBaseAddr = inSrc->data; unsigned char * srcBaseAddr = inSrc->data;
unsigned char * dstBaseAddr = inDst->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 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)); 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 * dstPixel = dstBaseAddr + ((int) dx * inDst->channels) + ((int) dy * dstRowBytes);
unsigned char * srcPixel = srcBaseAddr + ((long) sx * inSrc->channels) + ((long) sy * srcRowBytes); 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, /* If we would need pixels from off the edge of the image for bicubic interpolation,
just use bilinear. */ 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 /* 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! */ * storage size as the old bitmap because of padding! */
long newWidth = ioBitmap->height; int newWidth = ioBitmap->height;
long newHeight = ioBitmap->width; int newHeight = ioBitmap->width;
long newPad = ((newWidth * ioBitmap->channels + 3) & ~3) - (newWidth * ioBitmap->channels); int newPad = ((newWidth * ioBitmap->channels + 3) & ~3) - (newWidth * ioBitmap->channels);
unsigned char * newData = (unsigned char *) malloc(((newWidth * ioBitmap->channels) + newPad) * newHeight); unsigned char * newData = (unsigned char *) malloc(((newWidth * ioBitmap->channels) + newPad) * newHeight);
if (newData == NULL) if (newData == NULL)
return; return;
for (long y = 0; y < ioBitmap->height; ++y) for (int y = 0; y < ioBitmap->height; ++y)
for (long x = 0; x < ioBitmap->width; ++x) for (int x = 0; x < ioBitmap->width; ++x)
{ {
long nx = ioBitmap->height - y - 1; int nx = ioBitmap->height - y - 1;
long ny = x; int ny = x;
unsigned char * srcP = ioBitmap->data + (x * ioBitmap->channels) + (y * (ioBitmap->channels * ioBitmap->width + ioBitmap->pad)); 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)); unsigned char * dstP = newData + (nx * ioBitmap->channels) + (ny * (ioBitmap->channels * newWidth + newPad));
long chCount = ioBitmap->channels; int chCount = ioBitmap->channels;
while (chCount--) while (chCount--)
{ {
*dstP++ = *srcP++; *dstP++ = *srcP++;
@@ -510,8 +510,8 @@ int ConvertBitmapToAlpha(
struct ImageInfo * ioImage) struct ImageInfo * ioImage)
{ {
unsigned char * oldData, * newData, * srcPixel, * dstPixel; unsigned char * oldData, * newData, * srcPixel, * dstPixel;
long count; int count;
long x,y; int x,y;
if (ioImage->channels == 4) if (ioImage->channels == 4)
return 0; return 0;
@@ -567,8 +567,8 @@ int ConvertAlphaToBitmap(
struct ImageInfo * ioImage) struct ImageInfo * ioImage)
{ {
unsigned char * oldData, * newData, * srcPixel, * dstPixel; unsigned char * oldData, * newData, * srcPixel, * dstPixel;
long count; int count;
long x,y; int x,y;
if (ioImage->channels == 3) if (ioImage->channels == 3)
return 0; return 0;

View File

@@ -34,7 +34,7 @@
*/ */
#if APL #if APL
#pragma options align=mac68k #pragma pack(push, 2)
#endif #endif
#if IBM #if IBM
#pragma pack(push, 2) #pragma pack(push, 2)
@@ -43,27 +43,27 @@
struct BMPHeader { struct BMPHeader {
char signature1; char signature1;
char signature2; char signature2;
long fileSize; int fileSize;
long reserved; int reserved;
long dataOffset; int dataOffset;
}; };
struct BMPImageDesc { struct BMPImageDesc {
long structSize; int structSize;
long imageWidth; int imageWidth;
long imageHeight; int imageHeight;
short planes; short planes;
short bitCount; short bitCount;
long compressionType; int compressionType;
long imageSize; int imageSize;
long xPixelsPerM; //130B0000? B013 = 45075? int xPixelsPerM; //130B0000? B013 = 45075?
long yPixelsPerM; int yPixelsPerM;
long colorsUsed; int colorsUsed;
long colorsImportant; int colorsImportant;
}; };
#if APL #if APL
#pragma options align=reset #pragma pack(pop)
#endif #endif
#if IBM #if IBM
#pragma pack(pop) #pragma pack(pop)
@@ -82,10 +82,10 @@ struct BMPImageDesc {
struct ImageInfo { struct ImageInfo {
unsigned char * data; unsigned char * data;
long width; int width;
long height; int height;
long pad; int pad;
short channels; int channels;
}; };
/* Given a file path and an uninitialized imageInfo structure, this routine fills /* 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. /* 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. */ * 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 /* 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. */ * c = 0 means black and c = 255 means white. */
@@ -127,30 +127,30 @@ void DestroyBitmap(const struct ImageInfo * inImageInfo);
void CopyBitmapSection( void CopyBitmapSection(
const struct ImageInfo * inSrc, const struct ImageInfo * inSrc,
const struct ImageInfo * inDst, const struct ImageInfo * inDst,
long inSrcLeft, int inSrcLeft,
long inSrcTop, int inSrcTop,
long inSrcRight, int inSrcRight,
long inSrcBottom, int inSrcBottom,
long inDstLeft, int inDstLeft,
long inDstTop, int inDstTop,
long inDstRight, int inDstRight,
long inDstBottom); int inDstBottom);
void CopyBitmapSectionWarped( void CopyBitmapSectionWarped(
const struct ImageInfo * inSrc, const struct ImageInfo * inSrc,
const struct ImageInfo * inDst, const struct ImageInfo * inDst,
long inTopLeftX, int inTopLeftX,
long inTopLeftY, int inTopLeftY,
long inTopRightX, int inTopRightX,
long inTopRightY, int inTopRightY,
long inBotRightX, int inBotRightX,
long inBotRightY, int inBotRightY,
long inBotLeftX, int inBotLeftX,
long inBotLeftY, int inBotLeftY,
long inDstLeft, int inDstLeft,
long inDstTop, int inDstTop,
long inDstRight, int inDstRight,
long inDstBottom); int inDstBottom);
/* This routine rotates a bitmap counterclockwise 90 degrees, exchanging its width /* This routine rotates a bitmap counterclockwise 90 degrees, exchanging its width
* and height. */ * and height. */

View File

@@ -360,7 +360,7 @@ bool XObjWrite(const char * inFile, const XObj& inObj)
case type_PtLine: case type_PtLine:
if (gCmds[index].elem_count == 0) 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 else
fprintf(fi,"%s\t\t//" CRLF, gCmds[index].name); fprintf(fi,"%s\t\t//" CRLF, gCmds[index].name);
@@ -378,7 +378,7 @@ bool XObjWrite(const char * inFile, const XObj& inObj)
case type_Poly: case type_Poly:
if (gCmds[index].elem_count == 0) 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 else
fprintf(fi,"%s\t\t//" CRLF, gCmds[index].name); fprintf(fi,"%s\t\t//" CRLF, gCmds[index].name);

View File

@@ -345,6 +345,8 @@ int OBJ_LoadModel(const char * inFilePath)
tex_path += sObjects.back().obj.texture; tex_path += sObjects.back().obj.texture;
tex_path += ".png"; tex_path += ".png";
sObjects.back().texnum = OBJ_LoadTexture(tex_path.c_str(), false); 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; tex_path = path;
p = tex_path.find_last_of("\\:/");//XPLMGetDirectorySeparator()); p = tex_path.find_last_of("\\:/");//XPLMGetDirectorySeparator());