From 6214177f1f0b59fdd41fe56609bfb61e7b8b8185 Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Fri, 4 Sep 2009 22:59:41 +0000 Subject: [PATCH] - Fixed: S_LoadSound() did not byte-swap the frequency and length it reads from DMX sounds. SVN r1792 (trunk) --- docs/rh-log.txt | 9 +++++- src/m_png.cpp | 2 +- src/s_sound.cpp | 4 +-- src/textures/bitmap.cpp | 2 +- src/textures/patchtexture.cpp | 2 +- src/textures/pngtexture.cpp | 59 +++++++++++++++++++++-------------- 6 files changed, 48 insertions(+), 30 deletions(-) diff --git a/docs/rh-log.txt b/docs/rh-log.txt index b2875688f..128520ac3 100644 --- a/docs/rh-log.txt +++ b/docs/rh-log.txt @@ -1,6 +1,13 @@ -September 5, 2009 (Changes by Graf Zahl) +September 5, 2009 (Changes by Graf Zahl) - made menu dimming a mapping option but kept the CVARS as user override. +September 4, 2009 +- Fixed: S_LoadSound() did not byte-swap the frequency and length it reads + from DMX sounds. +- Fixed: PNGTexture must not use the FArchive >> operator as a short hand + for reading 4-byte integers, because that operator works with little + endian numbers--a no-op on Intel processors, but bad joojoo on PowerPCs. + September 3, 2009 (Changes by Graf Zahl) - fixed: Weapons must first check if they can be switched and afterwards if they can be fired. These checks were reversed. diff --git a/src/m_png.cpp b/src/m_png.cpp index 1a33221e2..4c329815f 100644 --- a/src/m_png.cpp +++ b/src/m_png.cpp @@ -181,7 +181,7 @@ bool M_CreatePNG (FILE *file, const BYTE *buffer, const PalEntry *palette, // // M_CreateDummyPNG // -// Like M_CreatePNG, but the image is always a grayscale 1x1 blacksquare. +// Like M_CreatePNG, but the image is always a grayscale 1x1 black square. // //========================================================================== diff --git a/src/s_sound.cpp b/src/s_sound.cpp index a766affcd..099565925 100644 --- a/src/s_sound.cpp +++ b/src/s_sound.cpp @@ -1255,7 +1255,7 @@ sfxinfo_t *S_LoadSound(sfxinfo_t *sfx) FWadLump wlump = Wads.OpenLumpNum(sfx->lumpnum); sfxstart = sfxdata = new BYTE[size]; wlump.Read(sfxdata, size); - SDWORD len = ((SDWORD *)sfxdata)[1]; + SDWORD len = LittleLong(((SDWORD *)sfxdata)[1]); // If the sound is raw, just load it as such. // Otherwise, try the sound as DMX format. @@ -1272,7 +1272,7 @@ sfxinfo_t *S_LoadSound(sfxinfo_t *sfx) } else { - frequency = ((WORD *)sfxdata)[1]; + frequency = LittleShort(((WORD *)sfxdata)[1]); if (frequency == 0) { frequency = 11025; diff --git a/src/textures/bitmap.cpp b/src/textures/bitmap.cpp index 702b2b5f5..c985e1494 100644 --- a/src/textures/bitmap.cpp +++ b/src/textures/bitmap.cpp @@ -131,7 +131,7 @@ void iCopyColors(BYTE *pout, const BYTE *pin, int count, int step, FCopyInfo *in break; case BLEND_GREENMAP: - // Skulltags's Guardsphere map + // Skulltag's Guardsphere map for(i=0;iheight); int width = LittleShort(foo->width); diff --git a/src/textures/pngtexture.cpp b/src/textures/pngtexture.cpp index 253014070..26e552de4 100644 --- a/src/textures/pngtexture.cpp +++ b/src/textures/pngtexture.cpp @@ -115,8 +115,9 @@ FTexture *PNGTexture_TryCreate(FileReader & data, int lumpnum) // The PNG looks valid so far. Check the IHDR to make sure it's a // type of PNG we support. - data >> width >> height - >> bitdepth >> colortype >> compression >> filter >> interlace; + data.Read(&width, 4); + data.Read(&height, 4); + data >> bitdepth >> colortype >> compression >> filter >> interlace; if (compression != 0 || filter != 0 || interlace > 1) { @@ -164,8 +165,9 @@ FTexture *PNGTexture_CreateFromFile(PNGHandle *png, const FString &filename) } // Check the IHDR to make sure it's a type of PNG we support. - (*png->File) >> width >> height - >> bitdepth >> colortype >> compression >> filter >> interlace; + png->File->Read(&width, 4); + png->File->Read(&height, 4); + (*png->File) >> bitdepth >> colortype >> compression >> filter >> interlace; if (compression != 0 || filter != 0 || interlace > 1) { @@ -215,12 +217,13 @@ FPNGTexture::FPNGTexture (FileReader &lump, int lumpnum, const FString &filename Height = height; CalcBitSize (); - memset (trans, 255, 256); + memset(trans, 255, 256); // Parse pre-IDAT chunks. I skip the CRCs. Is that bad? - lump.Seek (33, SEEK_SET); + lump.Seek(33, SEEK_SET); - lump >> len >> id; + lump.Read(&len, 4); + lump.Read(&id, 4); while (id != MAKE_ID('I','D','A','T') && id != MAKE_ID('I','E','N','D')) { len = BigLong((unsigned int)len); @@ -236,7 +239,8 @@ FPNGTexture::FPNGTexture (FileReader &lump, int lumpnum, const FString &filename DWORD hotx, hoty; int ihotx, ihoty; - lump >> hotx >> hoty; + lump.Read(&hotx, 4); + lump.Read(&hoty, 4); ihotx = BigLong((int)hotx); ihoty = BigLong((int)hoty); if (ihotx < -32768 || ihotx > 32767) @@ -249,8 +253,8 @@ FPNGTexture::FPNGTexture (FileReader &lump, int lumpnum, const FString &filename Printf ("Y-Offset for PNG texture %s is bad: %d (0x%08x)\n", Wads.GetLumpFullName (lumpnum), ihoty, ihoty); ihoty = 0; } - LeftOffset = (int)ihotx; - TopOffset = (int)ihoty; + LeftOffset = ihotx; + TopOffset = ihoty; } break; @@ -277,9 +281,10 @@ FPNGTexture::FPNGTexture (FileReader &lump, int lumpnum, const FString &filename bMasked = true; break; } - lump >> len >> len; // Skip CRC + lump.Seek(4, SEEK_CUR); // Skip CRC + lump.Read(&len, 4); id = MAKE_ID('I','E','N','D'); - lump >> id; + lump.Read(&id, 4); } StartOfIDAT = lump.Tell() - 8; @@ -460,7 +465,8 @@ void FPNGTexture::MakeTexture () { DWORD len, id; lump->Seek (StartOfIDAT, SEEK_SET); - (*lump) >> len >> id; + lump->Read(&len, 4); + lump->Read(&id, 4); if (ColorType == 0 || ColorType == 3) /* Grayscale and paletted */ { @@ -583,9 +589,9 @@ int FPNGTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int w, int h, i PalEntry pe[256]; DWORD len, id; FileReader *lump; - static char bpp[]={1, 0, 3, 1, 2, 0, 4}; + static char bpp[] = {1, 0, 3, 1, 2, 0, 4}; int pixwidth = Width * bpp[ColorType]; - int transpal=false; + int transpal = false; if (w < 0 || w > Width) w = Width; if (h < 0 || h > Height) h = Height; @@ -599,10 +605,12 @@ int FPNGTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int w, int h, i lump = new FileReader(SourceFile.GetChars()); } - lump->Seek (33, SEEK_SET); - for(int i=0;i<256;i++) pe[i]=PalEntry(255,i,i,i); // default to a gray map + lump->Seek(33, SEEK_SET); + for(int i = 0; i < 256; i++) // default to a gray map + pe[i] = PalEntry(255,i,i,i); - (*lump) >> len >> id; + lump->Read(&len, 4); + lump->Read(&id, 4); while (id != MAKE_ID('I','D','A','T') && id != MAKE_ID('I','E','N','D')) { len = BigLong((unsigned int)len); @@ -613,29 +621,32 @@ int FPNGTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int w, int h, i break; case MAKE_ID('P','L','T','E'): - for(int i=0;i> pe[i].r >> pe[i].g >> pe[i].b; } break; case MAKE_ID('t','R','N','S'): - for(DWORD i=0;i> pe[i].a; - if (pe[i].a!=0 && pe[i].a!=255) transpal = true; + if (pe[i].a != 0 && pe[i].a != 255) + transpal = true; } break; } - (*lump) >> len >> len; // Skip CRC + lump->Seek(4, SEEK_CUR); // Skip CRC + lump->Read(&len, 4); id = MAKE_ID('I','E','N','D'); - (*lump) >> id; + lump->Read(&id, 4); } BYTE * Pixels = new BYTE[pixwidth * Height]; lump->Seek (StartOfIDAT, SEEK_SET); - (*lump) >> len >> id; + lump->Read(&len, 4); + lump->Read(&len, 4); M_ReadIDAT (lump, Pixels, Width, Height, pixwidth, BitDepth, ColorType, Interlace, BigLong((unsigned int)len)); delete lump;