Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifndef __FILEQUANTELP_H__
Toshihiro Shimizu 890ddd
#define __FILEQUANTELP_H__
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "filequantel.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#define QNT_PAL_FILE_SIZE 829440
Toshihiro Shimizu 890ddd
#define QNT_PAL_W_FILE_SIZE 855360
Toshihiro Shimizu 890ddd
#define QTL_NTSC_FILE_SIZE 699840
Toshihiro Shimizu 890ddd
#define QTL_NTSC_W_FILE_SIZE 728640
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#define QUANTEL_XSIZE 720
Toshihiro Shimizu 890ddd
#define QNT_PAL_XSIZE QUANTEL_XSIZE
Toshihiro Shimizu 890ddd
#define QNT_PAL_YSIZE 576
Toshihiro Shimizu 890ddd
#define QTL_NTSC_XSIZE QUANTEL_XSIZE
Toshihiro Shimizu 890ddd
#define QTL_NTSC_YSIZE 486
Toshihiro Shimizu 890ddd
#define BYTESPERROW (QUANTEL_XSIZE * sizeof(short))
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#define CHECK_END_OF_FILE(car)                       \
Toshihiro Shimizu 890ddd
	{                                                \
Toshihiro Shimizu 890ddd
		if ((car) == EOF) {                          \
Toshihiro Shimizu 890ddd
			printf("read error: EOF encountered\n"); \
Toshihiro Shimizu 890ddd
			exit = 1;                                \
Toshihiro Shimizu 890ddd
			break;                                   \
Toshihiro Shimizu 890ddd
		}                                            \
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#define QUANTEL_GET_YUV_LINE(file_ptr, buf, xsize)    \
Toshihiro Shimizu 890ddd
	{                                                 \
Toshihiro Shimizu 890ddd
		int pixel;                                    \
Toshihiro Shimizu 890ddd
		TINT32 r, g, b, y1, y2, u, v;                 \
Toshihiro Shimizu 890ddd
                                                      \
Toshihiro Shimizu 890ddd
		for (pixel = ((xsize) >> 1); pixel--;) {      \
Toshihiro Shimizu 890ddd
			u = fgetc(file_ptr);                      \
Toshihiro Shimizu 890ddd
			CHECK_END_OF_FILE(u)                      \
Toshihiro Shimizu 890ddd
			u -= 128;                                 \
Toshihiro Shimizu 890ddd
			y1 = fgetc(file_ptr);                     \
Toshihiro Shimizu 890ddd
			CHECK_END_OF_FILE(y1)                     \
Toshihiro Shimizu 890ddd
			y1 -= 16;                                 \
Toshihiro Shimizu 890ddd
                                                      \
Toshihiro Shimizu 890ddd
			if (y1 < 0)                               \
Toshihiro Shimizu 890ddd
				y1 = 0;                               \
Toshihiro Shimizu 890ddd
                                                      \
Toshihiro Shimizu 890ddd
			v = fgetc(file_ptr);                      \
Toshihiro Shimizu 890ddd
			CHECK_END_OF_FILE(v)                      \
Toshihiro Shimizu 890ddd
			v -= 128;                                 \
Toshihiro Shimizu 890ddd
			y2 = fgetc(file_ptr);                     \
Toshihiro Shimizu 890ddd
			CHECK_END_OF_FILE(y2)                     \
Toshihiro Shimizu 890ddd
			y2 -= 16;                                 \
Toshihiro Shimizu 890ddd
                                                      \
Toshihiro Shimizu 890ddd
			if (y2 < 0)                               \
Toshihiro Shimizu 890ddd
				y2 = 0;                               \
Toshihiro Shimizu 890ddd
                                                      \
Toshihiro Shimizu 890ddd
			r = 76310 * y1 + 104635 * v;              \
Toshihiro Shimizu 890ddd
			if (r > 0xFFFFFF)                         \
Toshihiro Shimizu 890ddd
				r = 0xFFFFFF;                         \
Toshihiro Shimizu 890ddd
			if (r <= 0xFFFF)                          \
Toshihiro Shimizu 890ddd
				r = 0;                                \
Toshihiro Shimizu 890ddd
                                                      \
Toshihiro Shimizu 890ddd
			g = 76310 * y1 + -25690 * u + -53294 * v; \
Toshihiro Shimizu 890ddd
			if (g > 0xFFFFFF)                         \
Toshihiro Shimizu 890ddd
				g = 0xFFFFFF;                         \
Toshihiro Shimizu 890ddd
			if (g <= 0xFFFF)                          \
Toshihiro Shimizu 890ddd
				g = 0;                                \
Toshihiro Shimizu 890ddd
                                                      \
Toshihiro Shimizu 890ddd
			b = 76310 * y1 + 132278 * u;              \
Toshihiro Shimizu 890ddd
			if (b > 0xFFFFFF)                         \
Toshihiro Shimizu 890ddd
				b = 0xFFFFFF;                         \
Toshihiro Shimizu 890ddd
			if (b <= 0xFFFF)                          \
Toshihiro Shimizu 890ddd
				b = 0;                                \
Toshihiro Shimizu 890ddd
                                                      \
Toshihiro Shimizu 890ddd
			buf->r = (UCHAR)(r >> 16);                \
Toshihiro Shimizu 890ddd
			buf->g = (UCHAR)(g >> 16);                \
Toshihiro Shimizu 890ddd
			buf->b = (UCHAR)(b >> 16);                \
Toshihiro Shimizu 890ddd
			buf->m = (UCHAR)255;                      \
Toshihiro Shimizu 890ddd
			buf++;                                    \
Toshihiro Shimizu 890ddd
                                                      \
Toshihiro Shimizu 890ddd
			r = 76310 * y2 + 104635 * v;              \
Toshihiro Shimizu 890ddd
			if (r > 0xFFFFFF)                         \
Toshihiro Shimizu 890ddd
				r = 0xFFFFFF;                         \
Toshihiro Shimizu 890ddd
			if (r <= 0xFFFF)                          \
Toshihiro Shimizu 890ddd
				r = 0;                                \
Toshihiro Shimizu 890ddd
                                                      \
Toshihiro Shimizu 890ddd
			g = 76310 * y2 + -25690 * u + -53294 * v; \
Toshihiro Shimizu 890ddd
			if (g > 0xFFFFFF)                         \
Toshihiro Shimizu 890ddd
				g = 0xFFFFFF;                         \
Toshihiro Shimizu 890ddd
			if (g <= 0xFFFF)                          \
Toshihiro Shimizu 890ddd
				g = 0;                                \
Toshihiro Shimizu 890ddd
                                                      \
Toshihiro Shimizu 890ddd
			b = 76310 * y2 + 132278 * u;              \
Toshihiro Shimizu 890ddd
			if (b > 0xFFFFFF)                         \
Toshihiro Shimizu 890ddd
				b = 0xFFFFFF;                         \
Toshihiro Shimizu 890ddd
			if (b <= 0xFFFF)                          \
Toshihiro Shimizu 890ddd
				b = 0;                                \
Toshihiro Shimizu 890ddd
                                                      \
Toshihiro Shimizu 890ddd
			buf->r = (UCHAR)(r >> 16);                \
Toshihiro Shimizu 890ddd
			buf->g = (UCHAR)(g >> 16);                \
Toshihiro Shimizu 890ddd
			buf->b = (UCHAR)(b >> 16);                \
Toshihiro Shimizu 890ddd
			buf->m = (UCHAR)255;                      \
Toshihiro Shimizu 890ddd
			buf++;                                    \
Toshihiro Shimizu 890ddd
		}                                             \
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#define QUANTEL_FILL_LINE_OF_BLACK(rbuf, gbuf, bbuf, size) \
Toshihiro Shimizu 890ddd
	{                                                      \
Toshihiro Shimizu 890ddd
		memset(rbuf, 0, (size_t)(size * sizeof(USHORT)));  \
Toshihiro Shimizu 890ddd
		memset(gbuf, 0, (size_t)(size * sizeof(USHORT)));  \
Toshihiro Shimizu 890ddd
		memset(bbuf, 0, (size_t)(size * sizeof(USHORT)));  \
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#define QUANTEL_FILL_LINE_OF_RGB(xmarg, xsize, rbuf, gbuf, bbuf, RGBbuf) \
Shinya Kitaoka 4c5bd5
	{                                                                      \
Shinya Kitaoka 4c5bd5
	  int i;                                                               \
Shinya Kitaoka 4c5bd5
		QUANTEL_FILL_LINE_OF_BLACK(rbuf, gbuf, bbuf, xmarg)                  \
Shinya Kitaoka 4c5bd5
		for (i = xmarg; i < xsize + xmarg; i++) {                            \
Shinya Kitaoka 4c5bd5
			rbuf[i] = (USHORT)RGBbuf->r;                                       \
Shinya Kitaoka 4c5bd5
			gbuf[i] = (USHORT)RGBbuf->g;                                       \
Shinya Kitaoka 4c5bd5
			bbuf[i] = (USHORT)RGBbuf->b;                                       \
Shinya Kitaoka 4c5bd5
			RGBbuf++;                                                          \
Shinya Kitaoka 4c5bd5
		}                                                                    \
Shinya Kitaoka 4c5bd5
		QUANTEL_FILL_LINE_OF_BLACK(rbuf + i, gbuf + i, bbuf + i, xmarg)      \
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 4c5bd5
#define QUANTEL_FILL_LINE_OF_RGB2(xmarg, rbuf, gbuf, bbuf, RGBbuf)  \
Shinya Kitaoka 4c5bd5
	{                                                                 \
Shinya Kitaoka 4c5bd5
	  int i;                                                          \
Toshihiro Shimizu 890ddd
		QUANTEL_FILL_LINE_OF_BLACK(rbuf, gbuf, bbuf, xmarg)             \
Toshihiro Shimizu 890ddd
		for (i = xmarg; i < (QUANTEL_XSIZE - xmarg); i++) {             \
Shinya Kitaoka 4c5bd5
			rbuf[i] = (USHORT)RGBbuf->r;                                  \
Shinya Kitaoka 4c5bd5
			gbuf[i] = (USHORT)RGBbuf->g;                                  \
Shinya Kitaoka 4c5bd5
			bbuf[i] = (USHORT)RGBbuf->b;                                  \
Shinya Kitaoka 4c5bd5
			RGBbuf++;                                                     \
Toshihiro Shimizu 890ddd
		}                                                               \
Toshihiro Shimizu 890ddd
		QUANTEL_FILL_LINE_OF_BLACK(rbuf + i, gbuf + i, bbuf + i, xmarg) \
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#define QUANTEL_LIMIT(r, x)  \
Toshihiro Shimizu 890ddd
	{                        \
Toshihiro Shimizu 890ddd
		r = x;               \
Toshihiro Shimizu 890ddd
		if (r > 0x00ffffff)  \
Toshihiro Shimizu 890ddd
			r = 0x00ffffff;  \
Toshihiro Shimizu 890ddd
		if (r <= 0x00000000) \
Toshihiro Shimizu 890ddd
			r = 0;           \
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif /* __FILEQUANTELP_H__ */