// 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(); }
// 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; }
// 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; }