Look up the given pixel and return its colormap index. */
| 27 | |
| 28 | /* Look up the given pixel and return its colormap index. */ |
| 29 | static unsigned char |
| 30 | pix_to_colormap(pixel pix) |
| 31 | { |
| 32 | unsigned long i; |
| 33 | |
| 34 | for (i = 0; i < header.ncolors; i++) { |
| 35 | if (pix.r == ColorMap[CM_RED][i] |
| 36 | && pix.g == ColorMap[CM_GREEN][i] |
| 37 | && pix.b == ColorMap[CM_BLUE][i]) |
| 38 | break; |
| 39 | } |
| 40 | |
| 41 | if (i == header.ncolors) { |
| 42 | Fprintf(stderr, "can't find color: [%u,%u,%u]\n", pix.r, pix.g, |
| 43 | pix.b); |
| 44 | exit(1); |
| 45 | } |
| 46 | return (unsigned char) (i & 0xFF); |
| 47 | } |
| 48 | |
| 49 | /* Convert the tiles in the file to our format of bytes. */ |
| 50 | static unsigned long |