Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | daniel-mar | 1 | /** |
2 | * Bitmap Import for Imagination Pilots Entertainment 32-bit games (IPE32) |
||
3 | * - Where's Waldo? Exploring Geography |
||
4 | * - Eraser Turnabout by Imagination Pilots |
||
5 | * - Virtual K'Nex by Imagination Pilots |
||
6 | * ART file packer and unpacker by Daniel Marschall, ViaThinkSoft (C) 2014-2018 |
||
7 | * Revision: 2018-02-15 |
||
8 | **/ |
||
9 | |||
10 | #include <stdio.h> |
||
11 | #include <stdint.h> |
||
12 | #include <stdlib.h> |
||
13 | #include <string.h> |
||
14 | #include <math.h> |
||
15 | |||
16 | #include "bitmap.h" |
||
17 | #include "utils.h" |
||
18 | #include "ipe32_bmpimport.h" |
||
19 | |||
20 | #define BI_BITFIELDS 3 |
||
21 | |||
22 | bool bmp_has_gap1(BITMAPFILEHEADER bitmapFileHeader, BITMAPINFOHEADER bitmapInfoHeader) { |
||
23 | int expected = 0; |
||
24 | expected = sizeof(bitmapFileHeader) + bitmapInfoHeader.biSize; |
||
25 | |||
26 | if (bitmapInfoHeader.biCompression == BI_BITFIELDS) { |
||
27 | expected += 3*sizeof(DWORD); |
||
28 | } |
||
29 | |||
30 | int numColorEntries; |
||
31 | if (bitmapInfoHeader.biClrUsed == 0) { |
||
32 | if ((bitmapInfoHeader.biBitCount == 1) || (bitmapInfoHeader.biBitCount == 4) || (bitmapInfoHeader.biBitCount == 8)) { |
||
33 | numColorEntries = pow(2, bitmapInfoHeader.biBitCount); |
||
34 | } else { |
||
35 | numColorEntries = 0; |
||
36 | } |
||
37 | } else { |
||
38 | numColorEntries = bitmapInfoHeader.biClrUsed; |
||
39 | } |
||
40 | expected += sizeof(RGBQUAD)*numColorEntries; |
||
41 | |||
42 | return bitmapFileHeader.bfOffBits != expected; |
||
43 | } |
||
44 | |||
45 | bool ipe32_bmp_import(FILE* fibBitmap, Ipe32BmpImportData* result) { |
||
46 | BITMAPFILEHEADER bitmapFileHeader; |
||
47 | BITMAPINFOHEADER bitmapInfoHeader; |
||
48 | |||
49 | #define EXIT_ERROR(msg) { sprintf(result->error, msg); return false; } |
||
50 | |||
51 | fseek(fibBitmap, 0, SEEK_SET); |
||
52 | |||
53 | if (!fread(&bitmapFileHeader, sizeof(BITMAPFILEHEADER), 1, fibBitmap) || |
||
54 | (bitmapFileHeader.bfType != BI_SIGNATURE) || |
||
55 | !fread(&bitmapInfoHeader, sizeof(BITMAPINFOHEADER), 1, fibBitmap)) { |
||
56 | EXIT_ERROR("Not a bitmap file"); |
||
57 | } |
||
58 | |||
59 | if (bmp_has_gap1(bitmapFileHeader, bitmapInfoHeader)) { |
||
60 | EXIT_ERROR("Picture may not have a gap between header and bitmap data"); |
||
61 | } |
||
62 | |||
63 | // TODO: Find out if the game has limitations in regards to compression, top-down/bottom-up, Bitmap version etc. |
||
64 | /* |
||
65 | if (bitmapInfoHeader.biCompression != BI_RGB) { |
||
66 | EXIT_ERROR("At the moment, only uncompressed files can be read."); |
||
67 | } |
||
68 | |||
69 | if (bitmapInfoHeader.biBitCount != 8) { |
||
70 | EXIT_ERROR("The color depth has to be 8 bpp."); |
||
71 | } |
||
72 | */ |
||
73 | |||
74 | fseek(fibBitmap, sizeof(bitmapFileHeader), SEEK_SET); |
||
75 | |||
76 | result->error[0] = 0; |
||
77 | result->dataSize = file_size(fibBitmap)-sizeof(bitmapFileHeader); |
||
78 | return true; |
||
79 | } |
||
80 | |||
81 | void ipe32_free_bmpimport_result(Ipe32BmpImportData *res) { |
||
82 | } |
||
83 |