Toshihiro Shimizu 890ddd
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 {
Toshihiro Shimizu 890ddd
	IMG_NONE,
Toshihiro Shimizu 890ddd
	CMAPPED,   /* fa riferimento a una color-map */
Toshihiro Shimizu 890ddd
	CMAPPED24, /* 3 x 8 bit (ink, paint, ramp) + 8 bit extra (nel MSB) */
Toshihiro Shimizu 890ddd
	RGB,	   /* ogni pixel e' una terna red-green-blue   - 8bit per canale */
Toshihiro Shimizu 890ddd
	RGB64,	 /* ogni pixel e' una terna red-green-blue - 16bit per canale */
Toshihiro Shimizu 890ddd
	GR8,	   /* a toni di grigio */
Toshihiro Shimizu 890ddd
	CMAP	   /* color map */
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/* pixel-map */
Toshihiro Shimizu 890ddd
struct s_pixmap {
Toshihiro Shimizu 890ddd
	USHORT *buffer;
Toshihiro Shimizu 890ddd
	UCHAR *extra;	 /* patches etc. */
Toshihiro Shimizu 890ddd
	UCHAR extra_mask; /* bits extra usati in buffer (CMAPPED24) o in extra */
Toshihiro Shimizu 890ddd
	int xsize, ysize;
Toshihiro Shimizu 890ddd
	int xSBsize, ySBsize, xD, yD; /* savebox */
Toshihiro Shimizu 890ddd
	double x_dpi, y_dpi;
Toshihiro Shimizu 890ddd
	double h_pos; /* in pixel */
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/* color-map */
Toshihiro Shimizu 890ddd
struct s_cmap {
Toshihiro Shimizu 890ddd
	char *name;		   /* riferimento a CMAP esterna */
Toshihiro Shimizu 890ddd
	LPIXEL *buffer;	/* buffer della colormap (premoltiplicata) */
Toshihiro Shimizu 890ddd
	LPIXEL *penbuffer; /* buffer della componente di pencil per > 16 bits */
Toshihiro Shimizu 890ddd
	LPIXEL *colbuffer; /* buffer della componente di color  per > 16 bits */
Toshihiro Shimizu 890ddd
	LPIXEL *pencil;	/* i colori non premoltiplicati */
Toshihiro Shimizu 890ddd
	LPIXEL *color;	 /* tanti quanto dicono info.n_pencils e n_colors */
Toshihiro Shimizu 890ddd
	TCM_INFO info;	 /* vedi tcm.h */
Toshihiro Shimizu 890ddd
	void *names;	   /* nomi dei colori, gestiti da colorsdb */
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/* seguono i campi che andrebbero eliminati perche' doppioni */
Toshihiro Shimizu 890ddd
	int offset;			   /* == info.offset_mask */
Toshihiro Shimizu 890ddd
	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
Toshihiro Shimizu 890ddd
typedef enum {
Toshihiro Shimizu 890ddd
	CM_NONEB = -1,
Toshihiro Shimizu 890ddd
	CM_STANDARD,
Toshihiro Shimizu 890ddd
	CM_CUSTOM
Toshihiro Shimizu 890ddd
} IMG_CM_ALGORITHM;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/* Struttura per le modalita' di scrittura dei formati di file supportati  */
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
typedef struct
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	char rgb_is_compressed;
Toshihiro Shimizu 890ddd
	char rgb_write_matte;
Toshihiro Shimizu 890ddd
	char rgb_64_bits;
Toshihiro Shimizu 890ddd
	char rgb_colorstyle; /* full color or greyscale */
Toshihiro Shimizu 890ddd
	char tga_bytes_per_pixel;
Toshihiro Shimizu 890ddd
	char tga_is_colormap;
Toshihiro Shimizu 890ddd
	char tga_is_compressed;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/*
Toshihiro Shimizu 890ddd
    * Microsoft Windows Bitmap (BMP and DIB)
Toshihiro Shimizu 890ddd
    * 
Toshihiro Shimizu 890ddd
    *                         | compression | colorstyle | numcolors |
Toshihiro Shimizu 890ddd
    * ---------------------------------------------------------------
Toshihiro Shimizu 890ddd
    *       BLack & White     |      0      |     0      |     2     |
Toshihiro Shimizu 890ddd
    * ----------------------------------------------------------------
Toshihiro Shimizu 890ddd
    *    16 Grey Tones        |      0      |    GR8     |     16    |
Toshihiro Shimizu 890ddd
    * ---------------------------------------------------------------
Toshihiro Shimizu 890ddd
    *    16 Grey Tones Comp.  |      1      |    GR8     |     16    |
Toshihiro Shimizu 890ddd
    * ---------------------------------------------------------------
Toshihiro Shimizu 890ddd
    *   256 Grey Tones        |      0      |    GR8     |     256   |
Toshihiro Shimizu 890ddd
    * ---------------------------------------------------------------
Toshihiro Shimizu 890ddd
    *   256 Grey Tones Comp.  |      1      |    GR8     |     256   |
Toshihiro Shimizu 890ddd
    * ---------------------------------------------------------------
Toshihiro Shimizu 890ddd
    *    16 Color Mapped      |      0      |  CMAPPED   |     16    |
Toshihiro Shimizu 890ddd
    * ---------------------------------------------------------------
Toshihiro Shimizu 890ddd
    *    16 Color Mapped Comp.|      1      |  CMAPPED   |     16    |
Toshihiro Shimizu 890ddd
    * ---------------------------------------------------------------
Toshihiro Shimizu 890ddd
    *   256 Color Mapped      |      0      |  CMAPPED   |     256   |
Toshihiro Shimizu 890ddd
    * ---------------------------------------------------------------
Toshihiro Shimizu 890ddd
    *   256 Color Mapped Comp.|      1      |  CMAPPED   |     256   |
Toshihiro Shimizu 890ddd
    * ---------------------------------------------------------------
Toshihiro Shimizu 890ddd
    *       Full Color        |      0      |    RGB     |     0     |
Toshihiro Shimizu 890ddd
    * ---------------------------------------------------------------
Toshihiro Shimizu 890ddd
    * 
Toshihiro Shimizu 890ddd
    */
Toshihiro Shimizu 890ddd
	unsigned short bmp_compression;
Toshihiro Shimizu 890ddd
	unsigned short bmp_colorstyle;
Toshihiro Shimizu 890ddd
	unsigned short bmp_numcolors;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/*---------------------------------------------------------------*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	unsigned int jpg_quality;
Toshihiro Shimizu 890ddd
	unsigned int jpg_smoothing;
Toshihiro Shimizu 890ddd
	unsigned int jpg_components;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/*---------------------------------------------------------------*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	unsigned short tif_compression;
Toshihiro Shimizu 890ddd
	unsigned short tif_orientation;
Toshihiro Shimizu 890ddd
	unsigned short tif_photometric;
Toshihiro Shimizu 890ddd
	unsigned short tif_bits_per_sample;
Toshihiro Shimizu 890ddd
	unsigned short tif_samples_per_pixel;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/*---------------------------------------------------------------*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	IMG_CM_ALGORITHM cm_algorithm;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/*---------------------------------------------------------------*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TNZMOVIE_QUALITY pct_quality;
Toshihiro Shimizu 890ddd
	TNZMOVIE_COMPRESSION pct_compression;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/*---------------------------------------------------------------*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TNZMOVIE_QUALITY mov_quality;
Toshihiro Shimizu 890ddd
	TNZMOVIE_COMPRESSION mov_compression;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int avi_bpp;
Toshihiro Shimizu 890ddd
	char *avi_compression;
Toshihiro Shimizu 890ddd
} IMG_IO_SETTINGS;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/* Struttura IMAGE */
Toshihiro Shimizu 890ddd
typedef struct
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
	enum img_type type;
Toshihiro Shimizu 890ddd
	char *filename;
Toshihiro Shimizu 890ddd
	char *history;
Toshihiro Shimizu 890ddd
	struct s_pixmap icon;   /* Icon */
Toshihiro Shimizu 890ddd
	struct s_cmap cmap;		/* Colormap */
Toshihiro Shimizu 890ddd
	struct s_pixmap pixmap; /* Pixel Map */
Toshihiro Shimizu 890ddd
	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,
Toshihiro Shimizu 890ddd
								  REALLOC_TYPE new_realloc_func,
Toshihiro Shimizu 890ddd
								  FREE_TYPE new_free_func);
Toshihiro Shimizu 890ddd
TNZAPI void img_get_mem_functions(MALLOC_TYPE *new_malloc_func,
Toshihiro Shimizu 890ddd
								  REALLOC_TYPE *new_realloc_func,
Toshihiro Shimizu 890ddd
								  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);
Toshihiro Shimizu 890ddd
TNZAPI void fill_cmap_ramp(LPIXEL *buffer, TCM_INFO info,
Toshihiro Shimizu 890ddd
						   LPIXEL color, LPIXEL pencil,
Toshihiro Shimizu 890ddd
						   int color_index, int pencil_index,
Toshihiro Shimizu 890ddd
						   int already_premultiplied);
Toshihiro Shimizu 890ddd
TNZAPI void fill_cmap_colramp(LPIXEL *colbuffer, TCM_INFO info,
Toshihiro Shimizu 890ddd
							  LPIXEL color, int color_index,
Toshihiro Shimizu 890ddd
							  int already_premultiplied);
Toshihiro Shimizu 890ddd
TNZAPI void fill_cmap_penramp(LPIXEL *penbuffer, TCM_INFO info,
Toshihiro Shimizu 890ddd
							  LPIXEL pencil, int pencil_index,
Toshihiro Shimizu 890ddd
							  int already_premultiplied);
Toshihiro Shimizu 890ddd
TNZAPI void fill_cmap_buffer(LPIXEL *buffer, TCM_INFO info,
Toshihiro Shimizu 890ddd
							 LPIXEL *color, LPIXEL *pencil,
Toshihiro Shimizu 890ddd
							 int already_premultiplied);
Toshihiro Shimizu 890ddd
TNZAPI void fill_cmap_colbuffer(LPIXEL *colbuffer, TCM_INFO info,
Toshihiro Shimizu 890ddd
								LPIXEL *color, int already_premultiplied);
Toshihiro Shimizu 890ddd
TNZAPI void fill_cmap_penbuffer(LPIXEL *penbuffer, TCM_INFO info,
Toshihiro Shimizu 890ddd
								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