File: image.h

package info (click to toggle)
xli 1.17.0+20061110-5
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 1,540 kB
  • sloc: ansic: 25,840; makefile: 11
file content (120 lines) | stat: -rw-r--r-- 4,445 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/* image.h:
 * portable image type declarations
 *
 * jim frost 10.02.89
 *
 * Copyright 1989 Jim Frost.  See included file "copyright.h" for complete
 * copyright information.
 */

#include "copyright.h"

typedef struct rgbmap {
	unsigned int size;	/* size of RGB map */
	unsigned int used;	/* number of colors used in RGB map */
	boolean compressed;	/* image uses colormap fully */
	Intensity *red;		/* color values in X style */
	Intensity *green;
	Intensity *blue;
} RGBMap;

/* image structure */

typedef struct {
	char *title;		/* name of image */
	unsigned int type;	/* type of image */
	RGBMap rgb;		/* RGB map of image if IRGB type */
	unsigned int width;	/* width of image in pixels */
	unsigned int height;	/* height of image in pixels */
	unsigned int depth;	/* depth of image in bits if IRGB type */
	unsigned int pixlen;	/* length of pixel if IRGB type */
	byte *data;		/* data rounded to full byte for each row */
	float gamma;		/* gamma of display the image is adjusted for */
	unsigned long flags;	/* sundry flags */
} Image;

#define IBITMAP 0		/* image is a bitmap */
#define IRGB    1		/* image is RGB */
#define ITRUE   2		/* image is true color */

#define BITMAPP(IMAGE) ((IMAGE)->type == IBITMAP)
#define RGBP(IMAGE)    ((IMAGE)->type == IRGB)
#define TRUEP(IMAGE)   ((IMAGE)->type == ITRUE)

#define TRUE_RED(PIXVAL)   (((unsigned long)((PIXVAL) & 0xff0000)) >> 16)
#define TRUE_GREEN(PIXVAL) (((unsigned long)((PIXVAL) & 0xff00)) >> 8)
#define TRUE_BLUE(PIXVAL)   ((unsigned long)((PIXVAL) & 0xff))
#define RGB_TO_TRUE(R,G,B) \
  ((((unsigned long)((R) & 0xff00)) << 8) | ((G) & 0xff00) | (((unsigned short)(B)) >> 8))

#define FLAG_ISCALE 1		/* image scaled by decoder */

#define UNSET_GAMMA 0.0

#define depthToColors(n) DepthToColorsTable[((n) < 32 ? (n) : 32)]

/* this returns the (approximate) intensity of an RGB triple */

#define colorIntensity(R,G,B) \
	(RedIntensity[((unsigned short)(R)) >> 8] \
	+ GreenIntensity[((unsigned short)(G)) >> 8] \
	+ BlueIntensity[((unsigned short)(B)) >> 8])

extern unsigned short RedIntensity[];
extern unsigned short GreenIntensity[];
extern unsigned short BlueIntensity[];

/* Architecture independent memory to value conversions.
 * Note the "Normal" internal format is big endian.
 */

#define memToVal(PTR,LEN) (\
	(LEN) == 1 ? (unsigned long)(*((byte *)(PTR))) : \
	(LEN) == 2 ? (unsigned long)(((unsigned long)(*((byte *)(PTR))))<< 8) \
		+ (*(((byte *)(PTR))+1)) : \
	(LEN) == 3 ? (unsigned long)(((unsigned long)(*((byte *)(PTR))))<<16) \
		+ (((unsigned long)(*(((byte *)(PTR))+1)))<< 8) \
		+ (*(((byte *)(PTR))+2)) : \
	(unsigned long)(((unsigned long)(*((byte *)(PTR))))<<24) \
		+ (((unsigned long)(*(((byte *)(PTR))+1)))<<16) \
		+ (((unsigned long)(*(((byte *)(PTR))+2)))<< 8) \
		+ (*(((byte *)(PTR))+3)))

#define valToMem(VAL,PTR,LEN)  ( \
(LEN) == 1 ? (*((byte *)(PTR)) = (VAL)) : \
(LEN) == 2 ? (*((byte *)(PTR)) = (((unsigned long)(VAL))>> 8), \
	*(((byte *)(PTR))+1) = (VAL)) : \
(LEN) == 3 ? (*((byte *)(PTR)) = (((unsigned long)(VAL))>>16), \
	*(((byte *)(PTR))+1) = (((unsigned long)(VAL))>> 8), \
	*(((byte *)(PTR))+2) = (VAL)) : \
	(*((byte *)(PTR)) = (((unsigned long)(VAL))>>24), \
	*(((byte *)(PTR))+1) = (((unsigned long)(VAL))>>16), \
	*(((byte *)(PTR))+2) = (((unsigned long)(VAL))>> 8), \
	*(((byte *)(PTR))+3) = (VAL)))

#define memToValLSB(PTR,LEN) ( \
	(LEN) == 1 ? (unsigned long)(*((byte *)(PTR))) : \
	(LEN) == 2 ? (unsigned long)(*((byte *)(PTR))) \
		+ (((unsigned long)(*(((byte *)(PTR))+1)))<< 8) : \
	(LEN) == 3 ? (unsigned long)(*((byte *)(PTR))) \
		+ (((unsigned long)(*(((byte *)(PTR))+1)))<< 8) \
		+ (((unsigned long)(*(((byte *)(PTR))+2)))<<16) : \
	(unsigned long)(*((byte *)(PTR))) \
		+ (((unsigned long)(*(((byte *)(PTR))+1)))<< 8) \
		+ (((unsigned long)(*(((byte *)(PTR))+2)))<<16) \
		+ (((unsigned long)(*(((byte *)(PTR))+3)))<<24))


/* this is provided for orthagonality */

#define valToMemLSB(VAL,PTR,LEN) ( \
(LEN) == 1 ? (*((byte *)(PTR)) = (VAL)) : \
(LEN) == 2 ? (*((byte *)(PTR)) = (VAL), \
	*(((byte *)(PTR))+1) = (((unsigned long)(VAL))>> 8)) : \
(LEN) == 3 ? (*((byte *)(PTR)) = (VAL), \
	*(((byte *)(PTR))+1) = (((unsigned long)(VAL))>> 8), \
	*(((byte *)(PTR))+2) = (((unsigned long)(VAL))>>16)) : \
	(*((byte *)(PTR)) = (VAL), \
	*(((byte *)(PTR))+1) = (((unsigned long)(VAL))>> 8), \
	*(((byte *)(PTR))+2) = (((unsigned long)(VAL))>>16), \
	*(((byte *)(PTR))+3) = (((unsigned long)(VAL))>>24)))