Shinya Kitaoka 810553
#pragma once
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifndef __FILEBMP_INCLUDED__
Toshihiro Shimizu 890ddd
#define __FILEBMP_INCLUDED__
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef __cplusplus
Toshihiro Shimizu 890ddd
extern "C" {
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
/*
Shinya Kitaoka 9f5a1b
#if defined(_WIN32)
Toshihiro Shimizu 890ddd
typedef struct {unsigned char b,g,r,m;}  LPIXEL;
Toshihiro Shimizu 890ddd
#elif defined(__sgi)
Toshihiro Shimizu 890ddd
typedef struct { unsigned char  m,b,g,r; } LPIXEL;
Rozhuk Ivan ac51ab
#elif defined(LINUX) || defined(FREEBSD)
Toshihiro Shimizu 890ddd
typedef struct { unsigned char  r,g,b,m; } LPIXEL;
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
#error	Not yet implemented
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
enum BMP_ERROR_CODE {
Shinya Kitaoka 120a6e
  OK,
Shinya Kitaoka 120a6e
  UNSUPPORTED_BMP_FORMAT = -1,
Shinya Kitaoka 120a6e
  OUT_OF_MEMORY          = -2,
Shinya Kitaoka 120a6e
  UNEXPECTED_EOF         = -3,
Shinya Kitaoka 120a6e
  CANT_OPEN_FILE         = -4,
Shinya Kitaoka 120a6e
  WRITE_ERROR            = -5
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
typedef const wchar_t *MYSTRING;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int writebmp(const MYSTRING filename, int xsize, int ysize, void *buffer,
Shinya Kitaoka 120a6e
             int bpp);
Toshihiro Shimizu 890ddd
int readbmp(const MYSTRING filename, int *xsize, int *ysize, void **buffer);
Shinya Kitaoka 120a6e
int readbmpregion(const MYSTRING fname, void **pimg, int x1, int y1, int x2,
Shinya Kitaoka 120a6e
                  int y2, int scale);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
int readbmp_size(const MYSTRING fname, int *lx, int *ly);
Toshihiro Shimizu 890ddd
int readbmp_bbox(const MYSTRING fname, int *x0, int *y0, int *x1, int *y1);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
typedef enum {
Shinya Kitaoka 120a6e
  BMP_NONE,
Shinya Kitaoka 120a6e
  BMP_BW,
Shinya Kitaoka 120a6e
  BMP_GREY16,
Shinya Kitaoka 120a6e
  BMP_GREY16C,
Shinya Kitaoka 120a6e
  BMP_GREY256,
Shinya Kitaoka 120a6e
  BMP_GREY256C,
Shinya Kitaoka 120a6e
  BMP_CMAPPED16,
Shinya Kitaoka 120a6e
  BMP_CMAPPED16C,
Shinya Kitaoka 120a6e
  BMP_CMAPPED256,
Shinya Kitaoka 120a6e
  BMP_CMAPPED256C,
Shinya Kitaoka 120a6e
  BMP_RGB
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
} BMP_SUBTYPE;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
typedef struct {
Shinya Kitaoka 120a6e
  UINT bfSize;
Shinya Kitaoka 120a6e
  UINT bfOffBits;
Shinya Kitaoka 120a6e
  UINT biSize;
Shinya Kitaoka 120a6e
  UINT biWidth;
Shinya Kitaoka 120a6e
  UINT biHeight;
Shinya Kitaoka 120a6e
  UINT biPlanes;
Shinya Kitaoka 120a6e
  UINT biBitCount;
Shinya Kitaoka 120a6e
  UINT biCompression;
Shinya Kitaoka 120a6e
  UINT biSizeImage;
Shinya Kitaoka 120a6e
  UINT biXPelsPerMeter;
Shinya Kitaoka 120a6e
  UINT biYPelsPerMeter;
Shinya Kitaoka 120a6e
  UINT biClrUsed;
Shinya Kitaoka 120a6e
  UINT biClrImportant;
Shinya Kitaoka 120a6e
  UINT biFilesize;
Shinya Kitaoka 120a6e
  UINT biPad;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
} BMP_HEADER;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
int load_bmp_header(FILE *fp, BMP_HEADER **pHd);
Toshihiro Shimizu 890ddd
int write_bmp_header(FILE *fp, BMP_HEADER *hd);
Toshihiro Shimizu 890ddd
void release_bmp_header(BMP_HEADER *hd);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
int write_bmp_palette(FILE *fp, int nc, UCHAR *b, UCHAR *g, UCHAR *r);
Toshihiro Shimizu 890ddd
int make_bmp_palette(int colors, int grey, UCHAR *r, UCHAR *g, UCHAR *b);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
/*BMP_SUBTYPE
Toshihiro Shimizu 890ddd
     bmp_get_colorstyle(IMAGE *img);*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
int error_checking_bmp(BMP_HEADER *hd);
Shinya Kitaoka 120a6e
int read_bmp_line(FILE *fp, void *line, UINT w, UINT h, UCHAR **mp,
Shinya Kitaoka 120a6e
                  BMP_SUBTYPE type);
Shinya Kitaoka 120a6e
int write_bmp_line(FILE *fp, void *line_buffer, UINT w, UINT row, UCHAR *mp,
Shinya Kitaoka 120a6e
                   BMP_SUBTYPE type);
Toshihiro Shimizu 890ddd
int skip_bmp_lines(FILE *fp, UINT w, UINT rows, int whence, BMP_SUBTYPE type);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#define BMP_WIN_OS2_OLD 12
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef __cplusplus
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif