Skip to content

Commit

Permalink
patterns/pif: Add PIF image pattern (#76)
Browse files Browse the repository at this point in the history
* Added PIF pattern

* tests/patterns: Added test file for pif pattern

* Added pif pattern to list

* Delete pif.hexpat.pif

* patterns: Added pif image format pattern
  • Loading branch information
gfcwfzkm authored Jan 16, 2023
1 parent 8ab2ff4 commit d4045b7
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ Hex patterns, include patterns and magic files for the use with the ImHex Hex Ed
| CCHVA | | [`patterns/cchva.hexpat`](patterns/cchva.hexpat) | Command and Conquer Voxel Animation |
| CCVXL | | [`patterns/ccvxl.hexpat`](patterns/ccvxl.hexpat) | Command and Conquer Voxel Model |
| CCPAL | | [`patterns/ccpal.hexpat`](patterns/ccpal.hexpat) | Command and Conquer Voxel Palette |
| PIF | `image/pif` | [`patterns/pif.hexpat`](patterns/pif.hexpat) | PIF Image Format |

### Scripts

Expand Down
76 changes: 76 additions & 0 deletions patterns/pif.hexpat
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/* PIF - Portable Image Format
*
* Basic decoder for the PIF file structure
* https://github.com/gfcwfzkm/PIF-Image-Format
*/

#pragma MIME image/pif
#pragma endian little

enum imageType_t : u16 {
RGB888 = 0x433C,
RGB565 = 0xE5C5,
RGB332 = 0x1E53,
RGB16C = 0xB895,
BLWH = 0x7DAA,
IND24 = 0x4952,
IND16 = 0x4947,
IND8 = 0x4942
};

enum compression_t : u16 {
NO_COMPRESSION = 0,
RLE_COMPRESSION = 0x7DDE
};

struct PIFFileHeader {
char Signature[4];
u32 FileSize;
u32 ImageOffset;
};

struct PIFInfoHeader {
imageType_t ImageType;
u16 BitsPerPixel;
u16 ImageWidth;
u16 ImageHeight;
u32 ImageSize;
u16 ColorTableSize;
compression_t Compression;
};

struct PIF {
PIFFileHeader PIF_FileHeader;
PIFInfoHeader PIF_ImageHeader;

if (PIF_ImageHeader.ImageType == imageType_t::IND24)
{
u24 ColorTable[PIF_ImageHeader.ColorTableSize/3];
}
else if (PIF_ImageHeader.ImageType == imageType_t::IND16)
{
u16 ColorTable[PIF_ImageHeader.ColorTableSize/2];
}
else if (PIF_ImageHeader.ImageType == imageType_t::IND8)
{
u8 ColorTable[PIF_ImageHeader.ColorTableSize];
}

if ((PIF_ImageHeader.ImageType == imageType_t::RGB888) ||
(PIF_ImageHeader.ImageType == imageType_t::IND24))
{
u24 ImageData[(PIF_FileHeader.FileSize - PIF_FileHeader.ImageOffset)/3];
}
else if ((PIF_ImageHeader.ImageType == imageType_t::RGB565) ||
(PIF_ImageHeader.ImageType == imageType_t::IND16))
{
u16 ImageData[(PIF_FileHeader.FileSize - PIF_FileHeader.ImageOffset)/2];
}
else if ((PIF_ImageHeader.ImageType == imageType_t::RGB332) ||
(PIF_ImageHeader.ImageType == imageType_t::IND8))
{
u8 ImageData[(PIF_FileHeader.FileSize - PIF_FileHeader.ImageOffset)/1];
}
};

PIF pif @ 0x00;
Binary file added tests/patterns/test_data/pif.hexpat.pif
Binary file not shown.

0 comments on commit d4045b7

Please sign in to comment.