| 1 |
#ifndef SRF_H_INCLUDED |
| 2 |
#define SRF_H_INCLUDED |
| 3 |
|
| 4 |
/* |
| 5 |
* Structures for working with SRF (Garmin vehicle) files |
| 6 |
* http://www.techmods.net/nuvi/ |
| 7 |
* |
| 8 |
* Written by Mike Frysinger <[email protected]> |
| 9 |
* Released into the public domain |
| 10 |
*/ |
| 11 |
|
| 12 |
#include "pm_config.h" |
| 13 |
#include "pam.h" |
| 14 |
|
| 15 |
struct srf_pstring { |
| 16 |
uint32_t len; |
| 17 |
char * val; |
| 18 |
}; |
| 19 |
|
| 20 |
#define SRF_NUM_FRAMES 36 |
| 21 |
|
| 22 |
/* |
| 23 |
File Header |
| 24 |
16 bytes - string - "GARMIN BITMAP 01" |
| 25 |
32 bytes - two 32-bit ints, [4, 4] -- purpose unknown |
| 26 |
4 bytes - 32-bit int -- number of images (usually just 2) |
| 27 |
4 bytes - 32-bit int, [5] -- purpose unknown |
| 28 |
7 bytes - PString - "578" |
| 29 |
4 bytes - 32-bit int, [6] -- purpose unknown |
| 30 |
8 bytes - PString - version number ("1.00", "2.00", "2.10", or "2.20") |
| 31 |
4 bytes - 32-bit int, [7] -- purpose unknown |
| 32 |
16 bytes - PString - "006-D0578-XX" (where "XX" changes) -- |
| 33 |
I assume this is Garmin's product code? |
| 34 |
*/ |
| 35 |
#define SRF_MAGIC "GARMIN BITMAP 01" |
| 36 |
|
| 37 |
struct srf_header { |
| 38 |
char magic[16 + 1]; |
| 39 |
|
| 40 |
uint32_t _int4[2]; |
| 41 |
|
| 42 |
uint32_t img_cnt; |
| 43 |
|
| 44 |
uint32_t _int5; |
| 45 |
|
| 46 |
struct srf_pstring s578; |
| 47 |
|
| 48 |
uint32_t _int6; |
| 49 |
|
| 50 |
struct srf_pstring ver; |
| 51 |
|
| 52 |
uint32_t _int7; |
| 53 |
|
| 54 |
struct srf_pstring prod; |
| 55 |
}; |
| 56 |
|
| 57 |
/* |
| 58 |
Image Header |
| 59 |
12 bytes - three 32-bit ints, [0,16,0] -- purpose unknown |
| 60 |
2 bytes - 16-bit int -- height of image (just the 3D section, so it's 80) |
| 61 |
2 bytes - 16-bit int -- width of image (just the 3D section, 2880 or 2881) |
| 62 |
2 bytes - [16, 8] -- purpose unknown |
| 63 |
2 bytes - 16-bit int -- byte length of each line of image RGB data |
| 64 |
(16-bit RGB), so "width * 2" |
| 65 |
4 bytes - all zeroes -- purpose unknown |
| 66 |
*/ |
| 67 |
struct srf_img_header { |
| 68 |
uint32_t _ints[3]; |
| 69 |
|
| 70 |
uint16_t height, width; |
| 71 |
|
| 72 |
char _bytes[2]; |
| 73 |
|
| 74 |
uint16_t line_len; |
| 75 |
|
| 76 |
uint32_t zeros; |
| 77 |
}; |
| 78 |
|
| 79 |
/* |
| 80 |
Image Alpha Mask |
| 81 |
|
| 82 |
4 bytes - 32-bit int, [11] -- Might specify the type of data that |
| 83 |
follows? |
| 84 |
|
| 85 |
4 bytes - 32-bit int, length of following data (width*height of 3D |
| 86 |
section) |
| 87 |
|
| 88 |
width*height bytes - alpha mask data, 0 = opaque, 128 = transparent |
| 89 |
(across, then down) |
| 90 |
|
| 91 |
Notes: The Garmin format has 129 values: [0..128] [opaque..transparent] |
| 92 |
The PNG format has 256 values: [0..255] [transparent..opaque] |
| 93 |
So we have to do a little edge case tweaking to keep things lossless. |
| 94 |
*/ |
| 95 |
|
| 96 |
#define SRF_ALPHA_OPAQUE 0 |
| 97 |
#define SRF_ALPHA_TRANS 128 |
| 98 |
|
| 99 |
struct srf_img_alpha { |
| 100 |
uint32_t type; |
| 101 |
|
| 102 |
uint32_t data_len; |
| 103 |
unsigned char * data; |
| 104 |
}; |
| 105 |
|
| 106 |
/* |
| 107 |
Image RGB Data |
| 108 |
4 bytes - 32-bit int, [1] -- Might specify the type of data that follows? |
| 109 |
4 bytes - 32-bit int, length of following data (width*height*2 of 3D |
| 110 |
section, as the RGB data is 16-bit) |
| 111 |
width*height*2 bytes - RBG values as "rrrrrggggg0bbbbb" bits |
| 112 |
(across, then down) |
| 113 |
*/ |
| 114 |
|
| 115 |
struct srf_img_data { |
| 116 |
uint32_t type; |
| 117 |
|
| 118 |
uint32_t data_len; |
| 119 |
uint16_t * data; |
| 120 |
}; |
| 121 |
|
| 122 |
struct srf_img { |
| 123 |
struct srf_img_header header; |
| 124 |
struct srf_img_alpha alpha; |
| 125 |
struct srf_img_data data; |
| 126 |
}; |
| 127 |
|
| 128 |
/* |
| 129 |
Footer |
| 130 |
arbitrary number of bytes - all 0xFF -- these are used (as well as the |
| 131 |
checksum byte) to pad the file |
| 132 |
size to a multiple of 256. |
| 133 |
|
| 134 |
1 byte - checksum byte -- use this byte to adjust so that the ascii sum |
| 135 |
of all bytes in the file is a multiple of 256. |
| 136 |
*/ |
| 137 |
|
| 138 |
struct srf { |
| 139 |
struct srf_header header; |
| 140 |
struct srf_img * imgs; |
| 141 |
}; |
| 142 |
|
| 143 |
uint8_t |
| 144 |
srf_alpha_srftopam(uint8_t const d); |
| 145 |
|
| 146 |
uint8_t |
| 147 |
srf_alpha_pamtosrf(uint8_t const d); |
| 148 |
|
| 149 |
void |
| 150 |
srf_read(FILE * const ifP, |
| 151 |
bool const verbose, |
| 152 |
struct srf * const srfP); |
| 153 |
|
| 154 |
void |
| 155 |
srf_write(FILE * const ofP, |
| 156 |
struct srf * const srfP); |
| 157 |
|
| 158 |
void |
| 159 |
srf_term(struct srf * const srfP); |
| 160 |
|
| 161 |
void |
| 162 |
srf_init(struct srf * const srfP); |
| 163 |
|
| 164 |
void |
| 165 |
srf_create_img(struct srf * const srfP, |
| 166 |
uint16_t const width, |
| 167 |
uint16_t const height); |
| 168 |
|
| 169 |
#endif |
| 170 |
|