Shinya Kitaoka 810553
#pragma once
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifndef _IMG_H_
Toshihiro Shimizu 890ddd
#define _IMG_H_
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tcm.h"
Toshihiro Shimizu 890ddd
#include "machine.h"
Toshihiro Shimizu 890ddd
#include "pixel.h"
Toshihiro Shimizu 890ddd
#include "tnzmovie.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#undef TNZAPI
Toshihiro Shimizu 890ddd
#ifdef TNZ_IS_IMAGELIB
Toshihiro Shimizu 890ddd
#define TNZAPI TNZ_EXPORT_API
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
#define TNZAPI TNZ_IMPORT_API
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#define IMG_ICON_WIDTH 100
Toshihiro Shimizu 890ddd
#define IMG_ICON_HEIGHT 90
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
typedef void *(*MALLOC_TYPE)(int size);
Toshihiro Shimizu 890ddd
typedef void *(*REALLOC_TYPE)(void *ptr, int size);
Toshihiro Shimizu 890ddd
typedef void (*FREE_TYPE)(void *ptr);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/* Tipi di  IMAGE */
Toshihiro Shimizu 890ddd
enum img_type {
Shinya Kitaoka 120a6e
  IMG_NONE,
Shinya Kitaoka 120a6e
  CMAPPED,   /* fa riferimento a una color-map */
Shinya Kitaoka 120a6e
  CMAPPED24, /* 3 x 8 bit (ink, paint, ramp) + 8 bit extra (nel MSB) */
Shinya Kitaoka 120a6e
  RGB,       /* ogni pixel e' una terna red-green-blue   - 8bit per canale */
Shinya Kitaoka 120a6e
  RGB64,     /* ogni pixel e' una terna red-green-blue - 16bit per canale */
Shinya Kitaoka 120a6e
  GR8,       /* a toni di grigio */
Shinya Kitaoka 120a6e
  CMAP       /* color map */
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/* pixel-map */
Toshihiro Shimizu 890ddd
struct s_pixmap {
Shinya Kitaoka 120a6e
  USHORT *buffer;
Shinya Kitaoka 120a6e
  UCHAR *extra;     /* patches etc. */
Shinya Kitaoka 120a6e
  UCHAR extra_mask; /* bits extra usati in buffer (CMAPPED24) o in extra */
Shinya Kitaoka 120a6e
  int xsize, ysize;
Shinya Kitaoka 120a6e
  int xSBsize, ySBsize, xD, yD; /* savebox */
Shinya Kitaoka 120a6e
  double x_dpi, y_dpi;
Shinya Kitaoka 120a6e
  double h_pos; /* in pixel */
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/* color-map */
Toshihiro Shimizu 890ddd
struct s_cmap {
Shinya Kitaoka 120a6e
  char *name;        /* riferimento a CMAP esterna */
Shinya Kitaoka 120a6e
  LPIXEL *buffer;    /* buffer della colormap (premoltiplicata) */
Shinya Kitaoka 120a6e
  LPIXEL *penbuffer; /* buffer della componente di pencil per > 16 bits */
Shinya Kitaoka 120a6e
  LPIXEL *colbuffer; /* buffer della componente di color  per > 16 bits */
Shinya Kitaoka 120a6e
  LPIXEL *pencil;    /* i colori non premoltiplicati */
Shinya Kitaoka 120a6e
  LPIXEL *color;     /* tanti quanto dicono info.n_pencils e n_colors */
Shinya Kitaoka 120a6e
  TCM_INFO info;     /* vedi tcm.h */
Shinya Kitaoka 120a6e
  void *names;       /* nomi dei colori, gestiti da colorsdb */
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  /* seguono i campi che andrebbero eliminati perche' doppioni */
Shinya Kitaoka 120a6e
  int offset;            /* == info.offset_mask */
Shinya Kitaoka 120a6e
  int pencil_n, color_n; /* == info.n_pencils e n_colors */
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/* Enum per l'identificazione dell' algoritmo di riduzione dei colori */
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
typedef enum { CM_NONEB = -1, CM_STANDARD, CM_CUSTOM } IMG_CM_ALGORITHM;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/* Struttura per le modalita' di scrittura dei formati di file supportati  */
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
typedef struct {
Shinya Kitaoka 120a6e
  char rgb_is_compressed;
Shinya Kitaoka 120a6e
  char rgb_write_matte;
Shinya Kitaoka 120a6e
  char rgb_64_bits;
Shinya Kitaoka 120a6e
  char rgb_colorstyle; /* full color or greyscale */
Shinya Kitaoka 120a6e
  char tga_bytes_per_pixel;
Shinya Kitaoka 120a6e
  char tga_is_colormap;
Shinya Kitaoka 120a6e
  char tga_is_compressed;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  /*
Shinya Kitaoka 120a6e
* Microsoft Windows Bitmap (BMP and DIB)
Shinya Kitaoka 120a6e
*
Shinya Kitaoka 120a6e
*                         | compression | colorstyle | numcolors |
Shinya Kitaoka 120a6e
* ---------------------------------------------------------------
Shinya Kitaoka 120a6e
*       BLack & White     |      0      |     0      |     2     |
Shinya Kitaoka 120a6e
* ----------------------------------------------------------------
Shinya Kitaoka 120a6e
*    16 Grey Tones        |      0      |    GR8     |     16    |
Shinya Kitaoka 120a6e
* ---------------------------------------------------------------
Shinya Kitaoka 120a6e
*    16 Grey Tones Comp.  |      1      |    GR8     |     16    |
Shinya Kitaoka 120a6e
* ---------------------------------------------------------------
Shinya Kitaoka 120a6e
*   256 Grey Tones        |      0      |    GR8     |     256   |
Shinya Kitaoka 120a6e
* ---------------------------------------------------------------
Shinya Kitaoka 120a6e
*   256 Grey Tones Comp.  |      1      |    GR8     |     256   |
Shinya Kitaoka 120a6e
* ---------------------------------------------------------------
Shinya Kitaoka 120a6e
*    16 Color Mapped      |      0      |  CMAPPED   |     16    |
Shinya Kitaoka 120a6e
* ---------------------------------------------------------------
Shinya Kitaoka 120a6e
*    16 Color Mapped Comp.|      1      |  CMAPPED   |     16    |
Shinya Kitaoka 120a6e
* ---------------------------------------------------------------
Shinya Kitaoka 120a6e
*   256 Color Mapped      |      0      |  CMAPPED   |     256   |
Shinya Kitaoka 120a6e
* ---------------------------------------------------------------
Shinya Kitaoka 120a6e
*   256 Color Mapped Comp.|      1      |  CMAPPED   |     256   |
Shinya Kitaoka 120a6e
* ---------------------------------------------------------------
Shinya Kitaoka 120a6e
*       Full Color        |      0      |    RGB     |     0     |
Shinya Kitaoka 120a6e
* ---------------------------------------------------------------
Shinya Kitaoka 120a6e
*
Shinya Kitaoka 120a6e
*/
Shinya Kitaoka 120a6e
  unsigned short bmp_compression;
Shinya Kitaoka 120a6e
  unsigned short bmp_colorstyle;
Shinya Kitaoka 120a6e
  unsigned short bmp_numcolors;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  /*---------------------------------------------------------------*/
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  unsigned int jpg_quality;
Shinya Kitaoka 120a6e
  unsigned int jpg_smoothing;
Shinya Kitaoka 120a6e
  unsigned int jpg_components;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  /*---------------------------------------------------------------*/
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  unsigned short tif_compression;
Shinya Kitaoka 120a6e
  unsigned short tif_orientation;
Shinya Kitaoka 120a6e
  unsigned short tif_photometric;
Shinya Kitaoka 120a6e
  unsigned short tif_bits_per_sample;
Shinya Kitaoka 120a6e
  unsigned short tif_samples_per_pixel;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  /*---------------------------------------------------------------*/
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  IMG_CM_ALGORITHM cm_algorithm;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  /*---------------------------------------------------------------*/
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TNZMOVIE_QUALITY pct_quality;
Shinya Kitaoka 120a6e
  TNZMOVIE_COMPRESSION pct_compression;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  /*---------------------------------------------------------------*/
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TNZMOVIE_QUALITY mov_quality;
Shinya Kitaoka 120a6e
  TNZMOVIE_COMPRESSION mov_compression;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  int avi_bpp;
Shinya Kitaoka 120a6e
  char *avi_compression;
Toshihiro Shimizu 890ddd
} IMG_IO_SETTINGS;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/* Struttura IMAGE */
Shinya Kitaoka 120a6e
typedef struct {
Shinya Kitaoka 120a6e
  enum img_type type;
Shinya Kitaoka 120a6e
  char *filename;
Shinya Kitaoka 120a6e
  char *history;
Shinya Kitaoka 120a6e
  struct s_pixmap icon;   /* Icon */
Shinya Kitaoka 120a6e
  struct s_cmap cmap;     /* Colormap */
Shinya Kitaoka 120a6e
  struct s_pixmap pixmap; /* Pixel Map */
Shinya Kitaoka 120a6e
  IMG_IO_SETTINGS io_settings;
Toshihiro Shimizu 890ddd
} IMAGE;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TNZAPI void img_set_mem_functions(MALLOC_TYPE new_malloc_func,
Shinya Kitaoka 120a6e
                                  REALLOC_TYPE new_realloc_func,
Shinya Kitaoka 120a6e
                                  FREE_TYPE new_free_func);
Toshihiro Shimizu 890ddd
TNZAPI void img_get_mem_functions(MALLOC_TYPE *new_malloc_func,
Shinya Kitaoka 120a6e
                                  REALLOC_TYPE *new_realloc_func,
Shinya Kitaoka 120a6e
                                  FREE_TYPE *new_free_func);
Toshihiro Shimizu 890ddd
TNZAPI IMAGE *new_img(void);
Toshihiro Shimizu 890ddd
TNZAPI IMAGE *new_img_f(char *filename);
Toshihiro Shimizu 890ddd
TNZAPI int allocate_pixmap(IMAGE *img, int xsize, int ysize);
Toshihiro Shimizu 890ddd
TNZAPI int free_img(IMAGE *img);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TNZAPI int control_image(IMAGE *ctrl_img);
Toshihiro Shimizu 890ddd
TNZAPI int make_icon(IMAGE *img, int rxsize, int rysize);
Toshihiro Shimizu 890ddd
TNZAPI int make_icon_and_update_sb(IMAGE *img, int rxsize, int rysize);
Toshihiro Shimizu 890ddd
TNZAPI int clear_cmap(IMAGE *img);
Toshihiro Shimizu 890ddd
TNZAPI int attach_cmap(IMAGE *img, char *filename);
Toshihiro Shimizu 890ddd
TNZAPI int force_to_rgb(IMAGE *img, char *path);
Toshihiro Shimizu 890ddd
TNZAPI int rgb_to_grey(IMAGE *img, int cmap_size, int cmap_offset);
Toshihiro Shimizu 890ddd
TNZAPI int apply_cmap(IMAGE *img);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TNZAPI void add_white(struct s_cmap *cmap);
Toshihiro Shimizu 890ddd
TNZAPI void remove_white(struct s_cmap *cmap);
Toshihiro Shimizu 890ddd
TNZAPI LPIXEL premult(LPIXEL color);
Toshihiro Shimizu 890ddd
TNZAPI LPIXEL unpremult(LPIXEL color);
Toshihiro Shimizu 890ddd
TNZAPI void check_premultiplied(struct s_cmap *cmap);
Shinya Kitaoka 120a6e
TNZAPI void fill_cmap_ramp(LPIXEL *buffer, TCM_INFO info, LPIXEL color,
Shinya Kitaoka 120a6e
                           LPIXEL pencil, int color_index, int pencil_index,
Shinya Kitaoka 120a6e
                           int already_premultiplied);
Shinya Kitaoka 120a6e
TNZAPI void fill_cmap_colramp(LPIXEL *colbuffer, TCM_INFO info, LPIXEL color,
Shinya Kitaoka 120a6e
                              int color_index, int already_premultiplied);
Shinya Kitaoka 120a6e
TNZAPI void fill_cmap_penramp(LPIXEL *penbuffer, TCM_INFO info, LPIXEL pencil,
Shinya Kitaoka 120a6e
                              int pencil_index, int already_premultiplied);
Shinya Kitaoka 120a6e
TNZAPI void fill_cmap_buffer(LPIXEL *buffer, TCM_INFO info, LPIXEL *color,
Shinya Kitaoka 120a6e
                             LPIXEL *pencil, int already_premultiplied);
Shinya Kitaoka 120a6e
TNZAPI void fill_cmap_colbuffer(LPIXEL *colbuffer, TCM_INFO info, LPIXEL *color,
Shinya Kitaoka 120a6e
                                int already_premultiplied);
Toshihiro Shimizu 890ddd
TNZAPI void fill_cmap_penbuffer(LPIXEL *penbuffer, TCM_INFO info,
Shinya Kitaoka 120a6e
                                LPIXEL *pencil, int already_premultiplied);
Toshihiro Shimizu 890ddd
TNZAPI void convert_cmap(struct s_cmap *cmap, TCM_INFO new_tcm);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/* funzioni per cmap di vecchio tipo */
Toshihiro Shimizu 890ddd
TNZAPI void to_new_cmap(struct s_cmap *cmap);
Toshihiro Shimizu 890ddd
TNZAPI void set_colors_and_pencils(struct s_cmap *cmap);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TNZAPI void apply_transparency_color(IMAGE *img, TBOOL according_setup_value);
Toshihiro Shimizu 890ddd
TNZAPI void do_apply_transparency_color(IMAGE *img);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif