|
Shinya Kitaoka |
810553 |
#pragma once
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifndef TNZ4_H
|
|
Toshihiro Shimizu |
890ddd |
#define TNZ4_H
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include <assert.h></assert.h>
|
|
Toshihiro Shimizu |
890ddd |
#include <stdlib.h></stdlib.h>
|
|
Toshihiro Shimizu |
890ddd |
#include <sys types.h=""></sys>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#if defined(MACOSX)
|
|
Toshihiro Shimizu |
890ddd |
#include <sys malloc.h=""></sys>
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#define UCHAR unsigned char
|
|
Toshihiro Shimizu |
890ddd |
#define USHORT unsigned short
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "tmachine.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tnztypes.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "tfile_io.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#if !defined(TNZ_LITTLE_ENDIAN)
|
|
Toshihiro Shimizu |
890ddd |
TNZ_LITTLE_ENDIAN undefined !!
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#define NIL 0
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#define FALSE 0
|
|
Toshihiro Shimizu |
890ddd |
#define TRUE 1
|
|
Toshihiro Shimizu |
890ddd |
#define TBOOL int
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
typedef struct LPIXEL {
|
|
Shinya Kitaoka |
9f5a1b |
#ifdef _WIN32
|
|
Shinya Kitaoka |
120a6e |
unsigned char b, g, r, m;
|
|
Toshihiro Shimizu |
890ddd |
#elif defined(__sgi)
|
|
Shinya Kitaoka |
120a6e |
unsigned char m, b, g, r;
|
|
Jerome Duval |
b2d63b |
#elif defined(LINUX) || defined(FREEBSD) || defined(HAIKU)
|
|
Shinya Kitaoka |
120a6e |
unsigned char r, g, b, m;
|
|
Toshihiro Shimizu |
890ddd |
#elif defined(MACOSX)
|
|
Shinya Kitaoka |
120a6e |
unsigned char m, r, g, b;
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Toshihiro Shimizu |
890ddd |
#error Not yet implemented
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
} LPIXEL;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
typedef struct SPIXEL {
|
|
Shinya Kitaoka |
9f5a1b |
#ifdef _WIN32
|
|
Shinya Kitaoka |
120a6e |
unsigned short b, g, r, m;
|
|
Toshihiro Shimizu |
890ddd |
#elif defined(__sgi)
|
|
Shinya Kitaoka |
120a6e |
unsigned short m, b, g, r;
|
|
Jerome Duval |
b2d63b |
#elif defined(LINUX) || defined(FREEBSD) || defined(HAIKU)
|
|
Shinya Kitaoka |
120a6e |
unsigned short r, g, b, m;
|
|
Toshihiro Shimizu |
890ddd |
#elif defined(MACOSX)
|
|
Shinya Kitaoka |
120a6e |
unsigned char m, r, g, b;
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Toshihiro Shimizu |
890ddd |
#error Not yet implemented
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
} SPIXEL;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#define UINT TINT32
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
typedef LPIXEL GL_COLOR;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
typedef struct IMAGE {
|
|
Shinya Kitaoka |
120a6e |
int xsize, ysize;
|
|
Shinya Kitaoka |
120a6e |
int xSBsize, ySBsize;
|
|
Shinya Kitaoka |
120a6e |
int type;
|
|
Shinya Kitaoka |
120a6e |
UCHAR *buffer;
|
|
Shinya Kitaoka |
120a6e |
double x_dpi, y_dpi;
|
|
Toshihiro Shimizu |
890ddd |
} IMAGE;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#define TOONZRGB (1234)
|
|
Toshihiro Shimizu |
890ddd |
#define TOONZRGB64 (4567)
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
#define TMALLOC(ptr, elem) (ptr) = (void *)malloc((elem) * sizeof(*(ptr)));
|
|
Shinya Kitaoka |
120a6e |
#define TCALLOC(ptr, elem) (ptr) = (void *)calloc((elem), sizeof(*(ptr)));
|
|
Shinya Kitaoka |
120a6e |
#define TREALLOC(ptr, elem) \
|
|
Shinya Kitaoka |
120a6e |
{ \
|
|
Shinya Kitaoka |
120a6e |
if (ptr) \
|
|
Shinya Kitaoka |
120a6e |
(ptr) = (void *)realloc((ptr), (elem) * sizeof(*(ptr))); \
|
|
Shinya Kitaoka |
120a6e |
else \
|
|
Shinya Kitaoka |
120a6e |
(ptr) = (void *)malloc((elem) * sizeof(*(ptr))); \
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
#define TFREE(ptr) \
|
|
Shinya Kitaoka |
120a6e |
{ \
|
|
Shinya Kitaoka |
120a6e |
if (ptr) { \
|
|
Shinya Kitaoka |
120a6e |
free(ptr); \
|
|
Shinya Kitaoka |
120a6e |
ptr = NIL; \
|
|
Shinya Kitaoka |
120a6e |
} \
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
#define NOT_LESS_THAN(MIN, X) \
|
|
Shinya Kitaoka |
120a6e |
{ \
|
|
Shinya Kitaoka |
120a6e |
if ((X) < (MIN)) (X) = (MIN); \
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
#define NOT_MORE_THAN(MAX, X) \
|
|
Shinya Kitaoka |
120a6e |
{ \
|
|
Shinya Kitaoka |
120a6e |
if ((X) > (MAX)) (X) = (MAX); \
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#define CROP(X, MIN, MAX) (X < MIN ? MIN : (X > MAX ? MAX : X))
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
9f5a1b |
#ifdef _WIN32
|
|
Toshihiro Shimizu |
890ddd |
#define LPIXEL_TO_BGRM(X) (X)
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Toshihiro Shimizu |
890ddd |
#if TNZ_LITTLE_ENDIAN
|
|
Toshihiro Shimizu |
890ddd |
#define LPIXEL_TO_BGRM(X) (((TUINT32)(X) >> 8) | ((TUINT32)(X) << 24))
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
#define BGRM_TO_LPIXEL(X) (((TUINT32)(X)<<8) | ((TUINT32)(X)>>24))
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Toshihiro Shimizu |
890ddd |
#define LPIXEL_TO_BGRM(X) (((TUINT32)(X) << 8) | ((TUINT32)(X) >> 24))
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
#define BGRM_TO_LPIXEL(X) (((TUINT32)(X)>>8) | ((TUINT32)(X)<<24))
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#define BYTE_FROM_USHORT_MAGICFAC (256U * 255U + 1U)
|
|
Toshihiro Shimizu |
890ddd |
#define PIX_USHORT_FROM_BYTE(X) ((X) | ((X) << 8))
|
|
Shinya Kitaoka |
120a6e |
#define PIX_BYTE_FROM_USHORT(X) \
|
|
Shinya Kitaoka |
120a6e |
((((X)*BYTE_FROM_USHORT_MAGICFAC) + (1 << 23)) >> 24)
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
#define PIX_DITHER_BYTE_FROM_USHORT(X, R) \
|
|
Shinya Kitaoka |
120a6e |
(((((X)*BYTE_FROM_USHORT_MAGICFAC) - \
|
|
Shinya Kitaoka |
120a6e |
(((X)*BYTE_FROM_USHORT_MAGICFAC) >> 24)) + \
|
|
Shinya Kitaoka |
120a6e |
(R)) >> \
|
|
Shinya Kitaoka |
120a6e |
24)
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*---------------------------------------------------------------------------*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
short swap_short(short s);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TINT32 swap_TINT32(TINT32 s);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
USHORT swap_ushort(USHORT x);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*ULONG swap_uTLong (ULONG x);*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*---------------------------------------------------------------------------*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
/*! These functions are implemented in .cpp files, and allocate any buffer
|
|
Toshihiro Shimizu |
890ddd |
using new operator, so it's safe return img->buffer to .cpp units */
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
IMAGE *new_img();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void free_img(IMAGE *);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int allocate_pixmap(IMAGE *img, int w, int h);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#endif
|