2 * $ANH-Date: 1432512809 2015/05/25 00:13:29 $ $ANH-Branch: master $:$ANH-Revision: 1.5 $
20 /* VDI <-> Device palette order conversion matrixes: */
21 /* Four-plane vdi-device */
22 int vdi2dev4
[] = { 0, 15, 1, 2, 4, 6, 3, 5, 7, 8, 9, 10, 12, 14, 11, 13 };
23 /* Two-plane vdi-device */
24 int vdi2dev2
[] = { 0, 3, 1, 2 };
27 get_colors(int handle
, short *palette
, int col
)
31 /* get current color palette */
32 for (i
= 0; i
< col
; i
++) {
33 /* device->vdi->device palette order */
48 idx
= i
== 255 ? 1 : i
;
50 vq_color(handle
, i
, 0, (int *) palette
+ idx
* 3);
55 img_set_colors(int handle
, short *palette
, int col
)
59 /* set color palette */
60 end
= min(1 << col
, 1 << planes
);
61 for (i
= 0; i
< end
; i
++) {
62 switch (planes
) { /* MAR -- war col 10.01.2001 */
76 idx
= i
== 255 ? 1 : i
;
78 vs_color(handle
, i
, (int *) palette
+ idx
* 3);
83 convert(MFDB
*image
, long size
)
86 char *line_addr
, *buf_addr
, *new_addr
, *new1_addr
, *image_addr
,
91 /* convert size from words to bytes */
94 /* memory for the device raster */
95 new_size
= size
* (long) planes
;
96 if ((new_addr
= (char *) calloc(1, new_size
)) == NULL
)
99 /* initialize MFDBs */
101 tmp
.fd_nplanes
= planes
;
102 tmp
.fd_addr
= new_addr
;
103 tmp
.fd_stand
= 1; /* standard format */
105 screen_addr
= new_addr
;
106 dev_form
.fd_stand
= 0; /* device format */
107 image_addr
= (char *) image
->fd_addr
;
109 /* initialize some variables and zero temp. line buffer */
110 mplanes
= min(image
->fd_nplanes
, planes
);
112 line_addr
= image_addr
;
113 buf_addr
= screen_addr
;
115 /* cut/pad color planes into temp buf */
116 for (plane
= 0; plane
< mplanes
; plane
++) {
117 memcpy(buf_addr
, line_addr
, size
);
122 /* fill temp line bitplanes with a b&w line */
123 for (plane
= 0; plane
< planes
; plane
++) {
124 memcpy(buf_addr
, line_addr
, size
);
128 free(image
->fd_addr
);
129 /* convert image line in temp into current device raster format */
130 if ((new1_addr
= (char *) calloc(1, new_size
)) == NULL
)
132 dev_form
.fd_addr
= new1_addr
;
133 vr_trnfm(x_handle
, &tmp
, &dev_form
);
136 /* change image description */
137 image
->fd_stand
= 0; /* device format */
138 image
->fd_addr
= new1_addr
;
139 image
->fd_nplanes
= planes
;
144 transform_img(MFDB
*image
)
145 { /* return FALSE if transform_img fails */
152 size
= (long) ((long) image
->fd_wdwidth
* (long) image
->fd_h
);
154 image
, size
); /* Use vr_trfm(), which needs quite a lot memory. */
157 /* else show_error(ERR_ALLOC); */
161 /* Loads & depacks IMG (0 if succeded, else error). */
162 /* Bitplanes are one after another in address IMG_HEADER.addr. */
164 depack_img(char *name
, IMG_header
*pic
)
166 int b
, line
, plane
, width
, word_aligned
, opcode
, patt_len
, pal_size
,
167 byte_repeat
, patt_repeat
, scan_repeat
, error
= FALSE
;
168 char *pattern
, *to
, *endline
, *puffer
, sol_pat
;
172 if ((fp
= fopen(name
, "rb")) == NULL
)
175 setvbuf(fp
, NULL
, _IOLBF
, BUFSIZ
);
177 /* read header info (bw & ximg) into image structure */
178 fread((char *) &(pic
->version
), 2, 8 + 3, fp
);
180 /* only 2-256 color imgs */
181 if (pic
->planes
< 1 || pic
->planes
> 8) {
186 /* if XIMG, read info */
187 if (pic
->magic
== XIMG
&& pic
->paltype
== 0) {
188 pal_size
= (1 << pic
->planes
) * 3 * 2;
189 if ((pic
->palette
= (short *) calloc(1, pal_size
))) {
190 fread((char *) pic
->palette
, 1, pal_size
, fp
);
196 /* width in bytes word aliged */
197 word_aligned
= (pic
->img_w
+ 15) >> 4;
200 /* width byte aligned */
201 width
= (pic
->img_w
+ 7) >> 3;
203 /* allocate memory for the picture */
205 size
= (long) ((long) word_aligned
* (long) pic
->img_h
206 * (long) pic
->planes
); /*MAR*/
208 /* check for header validity & malloc long... */
209 if (pic
->length
> 7 && pic
->planes
< 33 && pic
->img_w
> 0
211 if (!(pic
->addr
= (char *) calloc(1, size
))) {
220 patt_len
= pic
->pat_len
;
222 /* jump over the header and possible (XIMG) info */
223 fseek(fp
, (long) pic
->length
* 2L, SEEK_SET
);
225 for (line
= 0, to
= pic
->addr
; line
< pic
->img_h
;
226 line
+= scan_repeat
) { /* depack whole img */
227 for (plane
= 0, scan_repeat
= 1; plane
< pic
->planes
;
228 plane
++) { /* depack one scan line */
231 + (long) (line
+ plane
* pic
->img_h
) * (long) word_aligned
;
232 endline
= puffer
+ width
;
233 do { /* depack one line in one bitplane */
234 switch ((opcode
= fgetc(fp
))) {
235 case 0: /* pattern or scan repeat */
236 if ((patt_repeat
= fgetc(fp
))) { /* repeat a pattern */
237 fread(to
, patt_len
, 1, fp
);
240 while (--patt_repeat
) { /* copy pattern */
241 memcpy(to
, pattern
, patt_len
);
244 } else { /* repeat a line */
245 if (fgetc(fp
) == 0xFF)
246 scan_repeat
= fgetc(fp
);
253 case 0x80: /* Literal */
254 byte_repeat
= fgetc(fp
);
255 fread(to
, byte_repeat
, 1, fp
);
258 default: /* Solid run */
259 byte_repeat
= opcode
& 0x7F;
260 sol_pat
= opcode
& 0x80 ? 0xFF : 0x00;
261 while (byte_repeat
--)
264 } while (to
< endline
);
267 /* ensure that lines aren't repeated past the end of the img
269 if (line
+ scan_repeat
> pic
->img_h
)
270 scan_repeat
= pic
->img_h
- line
;
271 /* copy line to image buffer */
272 if (scan_repeat
> 1) {
273 /* calculate address of a current line in a current
275 /* to=pic->addr+(long)(line+1+plane*pic->img_h)*(long)word_aligned;*/
276 for (b
= scan_repeat
- 1; b
; --b
) {
277 memcpy(to
, puffer
, width
);
294 half_img(MFDB
*s
, MFDB
*d
)
299 mfdb(&tmp
, NULL
, s
->fd_w
/ 2, s
->fd_h
, s
->fd_stand
, s
->fd_nplanes
);
300 tmp
.fd_w
= s
->fd_w
/ 2;
301 tmp
.fd_addr
= calloc(1, mfdb_size(&tmp
));
306 pxy
[3] = pxy
[7] = s
->fd_h
- 1;
307 for (i
= 0; i
< s
->fd_w
/ 2; i
++) {
308 pxy
[0] = pxy
[2] = 2 * i
;
310 vro_cpyfm(x_handle
, S_ONLY
, pxy
, s
, &tmp
);
313 pxy
[2] = pxy
[6] = s
->fd_w
/ 2 - 1;
314 for (j
= 0; j
< s
->fd_h
/ 2; j
++) {
315 pxy
[1] = pxy
[3] = 2 * j
;
317 vro_cpyfm(x_handle
, S_ONLY
, pxy
, &tmp
, d
);