/* ============ GetWavinfo ============ */ static wavinfo_t GetWavinfo( char *name, byte *wav, int wavlength ) { wavinfo_t info; Com_Memset( &info, 0, sizeof( info ) ); if ( !wav ) { return info; } iff_data = wav; iff_end = wav + wavlength; // find "RIFF" chunk FindChunk( "RIFF" ); if ( !( data_p && !strncmp( (char *)data_p + 8, "WAVE", 4 ) ) ) { Com_Printf( "Missing RIFF/WAVE chunks\n" ); return info; } // get "fmt " chunk iff_data = data_p + 12; // DumpChunks (); FindChunk( "fmt " ); if ( !data_p ) { Com_Printf( "Missing fmt chunk\n" ); return info; } data_p += 8; info.format = GetLittleShort(); info.channels = GetLittleShort(); info.rate = GetLittleLong(); data_p += 4 + 2; info.width = GetLittleShort() / 8; if ( info.format != 1 ) { #if defined RTCW_ET Com_Printf( "Unsupported format: %s\n", GetWaveFormatName( info.format ) ); #endif // RTCW_XX Com_Printf( "Microsoft PCM format only\n" ); return info; } // find data chunk FindChunk( "data" ); if ( !data_p ) { Com_Printf( "Missing data chunk\n" ); return info; } data_p += 4; info.samples = GetLittleLong() / info.width; info.dataofs = data_p - wav; return info; }
// Note: .Cut support has not been tested yet! // A .cut can only have 1 bpp. // We need to add support for the .pal's PSP outputs with these... ILboolean iLoadCutInternal() { CUT_HEAD Header; ILuint Size, i = 0, j; ILubyte Count, Run; if (iCurImage == NULL) { ilSetError(IL_ILLEGAL_OPERATION); return IL_FALSE; } Header.Width = GetLittleShort(); Header.Height = GetLittleShort(); Header.Dummy = GetLittleInt(); if (Header.Width == 0 || Header.Height == 0) { ilSetError(IL_INVALID_FILE_HEADER); return IL_FALSE; } if (!ilTexImage(Header.Width, Header.Height, 1, 1, IL_COLOUR_INDEX, IL_UNSIGNED_BYTE, NULL)) { // always 1 bpp return IL_FALSE; } iCurImage->Origin = IL_ORIGIN_LOWER_LEFT; Size = Header.Width * Header.Height; while (i < Size) { Count = igetc(); if (Count == 0) { // end of row igetc(); // Not supposed to be here, but igetc(); // PSP is putting these two bytes here...WHY?! continue; } if (Count & BIT_7) { // rle-compressed ClearBits(Count, BIT_7); Run = igetc(); for (j = 0; j < Count; j++) { iCurImage->Data[i++] = Run; } } else { // run of pixels for (j = 0; j < Count; j++) { iCurImage->Data[i++] = igetc(); } } } iCurImage->Origin = IL_ORIGIN_UPPER_LEFT; // Not sure /*iCurImage->Pal.Palette = SharedPal.Palette; iCurImage->Pal.PalSize = SharedPal.PalSize; iCurImage->Pal.PalType = SharedPal.PalType;*/ return ilFixImage(); }
// Internal function used to get the .bmp header from the current file. ILboolean iGetBmpHead(BMPHEAD * const Header) { Header->bfType = GetLittleUShort(); Header->bfSize = GetLittleInt(); Header->bfReserved = GetLittleUInt(); Header->bfDataOff = GetLittleInt(); Header->biSize = GetLittleInt(); Header->biWidth = GetLittleInt(); Header->biHeight = GetLittleInt(); Header->biPlanes = GetLittleShort(); Header->biBitCount = GetLittleShort(); Header->biCompression = GetLittleInt(); Header->biSizeImage = GetLittleInt(); Header->biXPelsPerMeter = GetLittleInt(); Header->biYPelsPerMeter = GetLittleInt(); Header->biClrUsed = GetLittleInt(); Header->biClrImportant = GetLittleInt(); return IL_TRUE; }
/* ============ GetWavinfo ============ */ wavinfo_t GetWavinfo (char *name, byte *wav, int wavlength) { wavinfo_t info; int i; int format; int samples; memset (&info, 0, sizeof(info)); if (!wav) return info; iff_data = wav; iff_end = wav + wavlength; // find "RIFF" chunk FindChunk("RIFF"); if (!(data_p && !strncmp((char *)data_p+8, "WAVE", 4))) { Com_Printf("Missing RIFF/WAVE chunks\n"); return info; } // get "fmt " chunk iff_data = data_p + 12; // DumpChunks (); FindChunk("fmt "); if (!data_p) { Com_Printf("Missing fmt chunk\n"); return info; } data_p += 8; format = GetLittleShort(); if (format != 1) { Com_Printf("Microsoft PCM format only\n"); return info; } info.channels = GetLittleShort(); info.rate = GetLittleLong(); data_p += 4+2; info.width = GetLittleShort() / 8; // get cue chunk FindChunk("cue "); if (data_p) { data_p += 32; info.loopstart = GetLittleLong(); // Com_Printf("loopstart=%d\n", sfx->loopstart); // if the next chunk is a LIST chunk, look for a cue length marker FindNextChunk ("LIST"); if (data_p) { if (!strncmp ((char *)data_p + 28, "mark", 4)) { // this is not a proper parse, but it works with cooledit... data_p += 24; i = GetLittleLong (); // samples in loop info.samples = info.loopstart + i; // Com_Printf("looped length: %i\n", i); } } } else info.loopstart = -1; // find data chunk FindChunk("data"); if (!data_p) { Com_Printf("Missing data chunk\n"); return info; } data_p += 4; samples = GetLittleLong () / info.width; if (info.samples) { if (samples < info.samples) Com_Error (ERR_DROP, "Sound %s has a bad loop length", name); } else info.samples = samples; info.dataofs = data_p - wav; return info; }
// From the DTE sources (mostly by Denton Woods with corrections by Randy Heit) ILboolean iLoadDoomInternal() { ILshort width, height, graphic_header[2], column_loop, row_loop; ILint column_offset, pointer_position, first_pos; ILubyte post, topdelta, length; ILubyte *NewData; ILuint i; if (iCurImage == NULL) { ilSetError(IL_ILLEGAL_OPERATION); return IL_FALSE; } first_pos = itell(); // Needed to go back to the offset table width = GetLittleShort(); height = GetLittleShort(); graphic_header[0] = GetLittleShort(); // Not even used graphic_header[1] = GetLittleShort(); // Not even used if (!ilTexImage(width, height, 1, 1, IL_COLOUR_INDEX, IL_UNSIGNED_BYTE, NULL)) { return IL_FALSE; } iCurImage->Origin = IL_ORIGIN_UPPER_LEFT; iCurImage->Pal.Palette = (ILubyte*)ialloc(IL_DOOMPAL_SIZE); if (iCurImage->Pal.Palette == NULL) { return IL_FALSE; } iCurImage->Pal.PalSize = IL_DOOMPAL_SIZE; iCurImage->Pal.PalType = IL_PAL_RGB24; memcpy(iCurImage->Pal.Palette, ilDefaultDoomPal, IL_DOOMPAL_SIZE); // 247 is always the transparent colour (usually cyan) memset(iCurImage->Data, 247, iCurImage->SizeOfData); for (column_loop = 0; column_loop < width; column_loop++) { column_offset = GetLittleInt(); pointer_position = itell(); iseek(first_pos + column_offset, IL_SEEK_SET); while (1) { if (iread(&topdelta, 1, 1) != 1) return IL_FALSE; if (topdelta == 255) break; if (iread(&length, 1, 1) != 1) return IL_FALSE; if (iread(&post, 1, 1) != 1) return IL_FALSE; // Skip extra byte for scaling for (row_loop = 0; row_loop < length; row_loop++) { if (iread(&post, 1, 1) != 1) return IL_FALSE; if (row_loop + topdelta < height) iCurImage->Data[(row_loop+topdelta) * width + column_loop] = post; } iread(&post, 1, 1); // Skip extra scaling byte } iseek(pointer_position, IL_SEEK_SET); } // Converts palette entry 247 (cyan) to transparent. if (ilGetBoolean(IL_CONV_PAL) == IL_TRUE) { NewData = (ILubyte*)ialloc(iCurImage->SizeOfData * 4); if (NewData == NULL) { return IL_FALSE; } for (i = 0; i < iCurImage->SizeOfData; i++) { NewData[i * 4] = iCurImage->Pal.Palette[iCurImage->Data[i]]; NewData[i * 4] = iCurImage->Pal.Palette[iCurImage->Data[i]]; NewData[i * 4] = iCurImage->Pal.Palette[iCurImage->Data[i]]; NewData[i * 4 + 3] = iCurImage->Data[i] != 247 ? 255 : 0; } if (!ilTexImage(iCurImage->Width, iCurImage->Height, iCurImage->Depth, 4, IL_RGBA, iCurImage->Type, NewData)) { ifree(NewData); return IL_FALSE; } iCurImage->Origin = IL_ORIGIN_UPPER_LEFT; ifree(NewData); } ilFixImage(); return IL_TRUE; }