/*
* 2ooM: The Master of Orion II Reverse Engineering Project
* Netpbm output routines for lbximg extration.
/*
* 2ooM: The Master of Orion II Reverse Engineering Project
* Netpbm output routines for lbximg extration.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
*/
int img_output_pbm(FILE *f, const char *filename,
unsigned width, unsigned height,
*/
int img_output_pbm(FILE *f, const char *filename,
unsigned width, unsigned height,
- unsigned char **framedata, unsigned char **mask,
- struct lbx_colour *palette)
+ unsigned char *pixels, unsigned char *mask,
+ struct lbx_colour *palette)
- if (mask[y][x]) {
- if (fputc(to_ascii('0'), f) == EOF)
- goto err;
- } else {
- if (fputc(to_ascii('1'), f) == EOF)
- goto err;
- }
+ if (fputc(to_ascii(vis ? '0' : '1'), f) == EOF)
+ goto err;
* normal output format.
*/
static int write_pgm(FILE *f, unsigned width, unsigned height,
* normal output format.
*/
static int write_pgm(FILE *f, unsigned width, unsigned height,
- if (!mask[y][x]) {
- if (fprintf_ascii(f, " 0") < 0)
- return -1;
- } else {
- if (fprintf_ascii(f, "%3hhu", framedata[y][x]) < 0)
- return -1;
- }
+ if (fprintf_ascii(f, "%3hhu", vis ? pixels[offset] : 0) < 0)
+ return -1;
*/
int img_output_ppm(FILE *f, const char *filename,
unsigned width, unsigned height,
*/
int img_output_ppm(FILE *f, const char *filename,
unsigned width, unsigned height,
- unsigned char **framedata, unsigned char **mask,
- struct lbx_colour *palette)
+ unsigned char *pixels, unsigned char *mask,
+ struct lbx_colour *palette)
* For no-palette mode, write a PGM instead which is basically
* the same format but has only one value per pixel.
*/
* For no-palette mode, write a PGM instead which is basically
* the same format but has only one value per pixel.
*/
- if (write_pgm(f, width, height, framedata, mask) < 0)
+ if (write_pgm(f, width, height, pixels, mask) < 0)
- if (fprintf_ascii(f, "%2d %2d %2d",
- c->red, c->green, c->blue) < 0)
- goto err;
- }
+ if (fprintf_ascii(f, "%2d %2d %2d", c.red, c.green, c.blue) < 0)
+ goto err;
*/
int img_output_pam(FILE *f, const char *filename,
unsigned width, unsigned height,
*/
int img_output_pam(FILE *f, const char *filename,
unsigned width, unsigned height,
- unsigned char **framedata, unsigned char **mask,
- struct lbx_colour *palette)
+ unsigned char *pixels, unsigned char *mask,
+ struct lbx_colour *palette)
if (fwrite(buf, 1, depth, f) < depth)
goto err;
if (fwrite(buf, 1, depth, f) < depth)
goto err;
- buf[0] = framedata[y][x];
- buf[1] = mask[y][x] ? 0xff : 0;
+ vis = mask[offset/CHAR_BIT] & (1u << offset%CHAR_BIT);
+ buf[0] = pixels[offset];
+ buf[1] = vis ? 255 : 0;
if (fwrite(buf, 1, depth, f) < depth)
goto err;
if (fwrite(buf, 1, depth, f) < depth)
goto err;