File: PixMap.h

package info (click to toggle)
libpano12 2.8.3-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 3,168 kB
  • ctags: 2,419
  • sloc: ansic: 28,076; sh: 8,724; makefile: 223
file content (245 lines) | stat: -rw-r--r-- 8,065 bytes parent folder | download | duplicates (2)
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
/* File PixMap.h Copyright (C) 1997 by John R. Montbriand.  All Rights Reserved. */

#ifndef __PIXMAP__
#define __PIXMAP__

/* File PixMap.h
	PixMap manipulation routines, definitions.
	Copyright (c) 1996, 1997 by John Montbriand.  All Rights Reserved.
	Permission hereby granted for public use.
    	Distribute freely in areas where the laws of copyright apply.
	USE AT YOUR OWN RISK.
	DO NOT DISTRIBUTE MODIFIED COPIES.
	Comments/questions/postcards* to the author at the address:
	  John Montbriand
	  P.O. Box. 1133
	  Saskatoon Saskatchewan Canada
	  S7K 3N2
	or by email at:
	  tinyjohn@sk.sympatico.ca
	*if you mail a postcard, then I will provide you with technical support
	regarding questions you may have about this file.

*/

//#include <Types.h> // commented by Kekus Digital
//#include <QuickDraw.h> // commented by Kekus Digital
#include <Carbon/Carbon.h> // added by Kekus Digital

#ifdef __cplusplus
extern "C" { 
#endif


/* version number for this interface (version 1) */

#define kPixMapVersion 1


/* MakePixMap creates a new pixmap handle with the requested
	dimensions.  If there is not enough memory to allocate the pixmap,
	MakePixMap will return NULL.  if clut is NULL, then the default
	256 colour table (clut = 8) is used.  if clut is not NULL, then a
	copy of it is used in the pixmap.  The number of colours in the clut
	determines the pixel depth of the created pixmap as follows:
		2 colours -> 1 pit per pixel,
		3 to 4 colours -> 2 bits per pixel,
		5 to 16 colours -> 4 bits per pixel,
		17 to 256 colours -> 8 bits per pixel. */

PixMapHandle MakePixMap(short width, short height, CTabHandle clut);


/* Make16BitPixMap creates a new pixmap handle with the requested
	dimensions.  If there is not enough memory to allocate the pixmap,
	Make16BitPixMap will return NULL.  The created pixmap utilizes 16 bit
	colour and allocates 16 bits per each pixel.  Make32BitPixMap is
	identical however it allocates 32 bits per pixel.  */

PixMapHandle Make16BitPixMap(short width, short height);
PixMapHandle Make32BitPixMap(short width, short height);


/* MakeScreenLikePixMap creates a pixmap mirroring the attributes of the
	pixmap used to draw largest area of *globalRect on the screen */ 
PixMapHandle MakeScreenLikePixMap(Rect *globalRect);


/* KillPixMap disposes of a pixmap allocated by one of the
	routines herein. */
void KillPixMap(PixMapHandle pix);


/* PixMapSize returns the number of bytes occupied by the pixmap. */
long PixMapSize(PixMapHandle pix);


/* SetPixMapPixel and GetPixMapPixel are for getting or setting
	individual pixel values.  */

void SetPixMapPixel(PixMapHandle pix, short h, short v, long value);
long GetPixMapPixel(PixMapHandle pix, short h, short v);


/* RotatePixRight creates a new pixmap containing the image
	stored in the parameter pixmap rotated 90 degrees to the right.
	The resulting pixmap is appropriately sized:  i.e. if the source
	pixmap is 100 pixels wide and 200 pixels tall,  then the result
	pixmap pointer will be 200 pixels wide and 100 pixels tall.  */
	
PixMapHandle RotatePixRight(PixMapHandle pix);


/* RotatePixLeft creates a new pixmap containing the image stored in
	the parameter bitmap pointer rotated 90 degrees to the left.  The
	resulting pixmap is appropriately sized:  i.e. if the source pixmap
	is 100 pixels wide and 200 pixels tall,  then the result pixmap
	pointer will be 200 pixels wide and 100 pixels tall.   */
	
PixMapHandle RotatePixLeft(PixMapHandle pix);


/* FlipPixVertical creates a new pixmap containing the image stored
	in the parameter pixmap flipped upside down.  The resulting
	pixmap will be the same size as the original image.  */
	
PixMapHandle FlipPixVertical(PixMapHandle pix);


/* FlipPixHorizontal creates a new pixmap containing the image stored
	in the parameter pixmap flipped horizontally. The resulting pixmap
	will be the same size as the original image.  */
	
PixMapHandle FlipPixHorizontal(PixMapHandle pix);


/* RotatePixMap creates a new pixmap containing the image from
	the parameter pixmap rotated angle degrees about the center (cx, cy).
	The resultant pixmap will have the same dimensions as the parameter
	pixmap regardless of the angle specified. */
	
PixMapHandle RotatePixMap(PixMapHandle pix, short cx, short cy, float angle);


/* DuplicatePixMap creates a copy of the pixmap parameter. */

PixMapHandle DuplicatePixMap(PixMapHandle pix);


/* PICTToBitMap creates a new pixmap the using the size information
	provided in the QuickDraw picture pointer parameter and draws
	the picture in the pixmap before returning the pixmap. */
	
PixMapHandle PICTToPixMap(PicHandle pic, CTabHandle clut);
PixMapHandle PICTTo16BitPixMap(PicHandle pic);
PixMapHandle PICTTo32BitPixMap(PicHandle pic);


/* PixMapToPICT returns a QuickDraw picture that will draw the
	image stored in the pixmap.  PixMapToPICT is the inverse
	of PICTToPixMap. */
	
PicHandle PixMapToPICT(PixMapHandle pix);


/* PixMapToCompressedPICT returns a QuickDraw picture that will draw the
	image stored in the pixmap.  PixMapToCompressedPICT is the inverse
	of PICTToPixMap. */
	
PicHandle PixMapToCompressedPICT(PixMapHandle pix);



/* ROUTINES FOR DRAWING TO... */

/* PixMapPort data structure managed by the routines NewBMP and
	DisposeBMP.  You should never have to access the fields of this
	record directly as it's all taken care of by NewBMP and DisposeBMP. */

typedef struct {
	//CGrafPort pport;		/* the grafport record for drawing into the pixmap */ // commented by Kekus Digital
	CGrafPtr pport;		/* the grafport record for drawing into the pixmap */ // added by Kekus Digital
	GDHandle pdevice;		/* gdevice for drawing into the pixmap */
	GDHandle saved_device;	/* saved gdevice */
	GrafPtr saved_port;		/* saved grafport for later restoration */
	PixMapHandle pix;		/* the pixmap */
} PixMapPort;


/* NewBMP is called by the WithBitMap macro and you should never have to
	call it directly yourself.  What it does is it locks the pixmap, saves the
	original grafport, and creates a new grafport suitable for drawing into
	the pixmap.  NewBMP should be followed by a call to DisposeBMP which
	will restore the original grafport, unlock the pixmap, and dispose of the
	new grafport. */
	
PixMapPort* NewPxMP(PixMapHandle pix);



/* DisposePxMP unlocks the pixmap pointer passed to NewPxMP, deallocates
	the grafport allocated for it, and restores the original grafport.
	the macro WithBitMap calls this routine automatically and you will
	not normally have to call it directly. */
	
void DisposePxMP(PixMapPort* px);



/* WithPixMap is a macro facility that sets up the drawing environment
	such that any drawing commands in the statement following the
	macro instantiation will draw into the pixmap handle provided as
	the first parameter.  The parameters are declared as follows:
		PixMapHandle pix;
		PixMapPort* pxmp; */
	
#define WithPixMap(pix, pxmp) \
	for (pxmp = NewPxMP(pix); \
		pxmp != NULL; \
		DisposePxMP(pxmp), pxmp = NULL)




/* ROUTINES FOR DRAWING FROM... */

/* PlotPixMap provides a simple interface for drawing a pixmap in
	the current grafport.  The pixmap is drawn with the top left corner
	aligned with the point (h,v) using the indicated transfer mode. */

void PlotPixMap(PixMapHandle pix, short h, short v, short mode);


/* PixMapCopy copies bits from the pixmap to the current port
	from the src rectangle to the destination using the indicated
	copy mode. */

void PixMapCopy(PixMapHandle pix, Rect *src, Rect *dst, short mode);


/* PixMap2PixPat converts a pixmap to a pixel pattern resource.  The
	pixmap's dimensions should be some power of two
	(i.e. 8, 16, 32, 64, or 128). */

PixPatHandle PixMap2PixPat(PixMapHandle pix, Pattern *the_pattern);


/* CalcPixMapColours calculates a colour table for the colours
	used in the pixmap.  For indexed images, CalcPixMapColours returns
	a copy of the pixmap's colour table, otherwise, for direct
	images, it calls GetPixMapInfo. */

CTabHandle CalcPixMapColours(PixMapHandle pix);


#ifdef __cplusplus
};
#endif

#endif

/* end of File PixMap.h */