5 #include "xtypes.hpp"
\r
8 #include "xblitbuf.hpp"
\r
10 #define SEQU_ADDR 0x3C4
\r
11 #define GRACON_ADDR 0x3CE
\r
15 clear_blitbuf(blitbuf *buf)
\r
25 fill_blitbuf(BYTE color, blitbuf *buf)
\r
27 memset(buf->image, color, buf->xsize * buf->ysize);
\r
32 alloc_blitbuf(blitbuf *buf, DIST xsize, DIST ysize)
\r
36 buf->image = new BYTE[xsize * ysize];
\r
41 lin_2_pln_blitbuf(blitbuf *buf)
\r
49 oldbuf = buf->image;
\r
51 size = (buf->xsize * buf->ysize);
\r
52 newbuf = new BYTE[size];
\r
57 for (i=0; i < 4; i++) {
\r
58 src_ptr = oldbuf + i;
\r
62 *dest_ptr++ = *src_ptr;
\r
67 buf->image = newbuf;
\r
73 pln_2_lin_blitbuf(blitbuf *buf)
\r
81 oldbuf = buf->image;
\r
83 size = (buf->xsize * buf->ysize);
\r
84 newbuf = new BYTE[size];
\r
88 for (i=0; i < 4; i++) {
\r
89 dest_ptr = newbuf + i;
\r
93 *dest_ptr = *src_ptr++;
\r
98 buf->image = newbuf;
\r
104 vanilla_bitblitX(COORD x, COORD y, blitbuf *buf)
\r
106 short int ysize, plane, i, j, loop, skip, rewind, len;
\r
107 short int xsize[4];
\r
112 // Length of bitmap in each plane
\r
114 i = buf->xsize + plane - 1;
\r
115 xsize[0] = ((i--) >> 2);
\r
116 xsize[1] = ((i--) >> 2);
\r
117 xsize[2] = ((i--) >> 2);
\r
118 xsize[3] = (i >> 2) + 1;
\r
120 for (i=plane; i < 3; i++) {
\r
124 ysize = buf->ysize;
\r
125 base_vga = RowsX[y] + (x >> 2) + activeStart;
\r
128 for (loop = 0; loop < 4; loop++) {
\r
129 len = xsize[plane];
\r
130 rewind = buf->xsize - (len << 2);
\r
131 skip = widthBytes - len;
\r
132 buf_ptr = buf->image + loop;
\r
133 vga_ptr = base_vga;
\r
135 outpw(SEQU_ADDR, plane_mask[plane++]);
\r
145 *vga_ptr++ = *buf_ptr;
\r
157 vanilla_getblitX(COORD x, COORD y, blitbuf *buf)
\r
164 aligned_bitblitX(COORD x, COORD y, blitbuf *buf)
\r
166 short int i, j, plane, skip, xsize, ysize;
\r
171 xsize = (buf->xsize >> 2);
\r
172 ysize = buf->ysize;
\r
173 skip = widthBytes - xsize;
\r
174 base_vga = RowsX[y] + (x >> 2) + activeStart;
\r
176 for (plane=0; plane < 4; plane++) {
\r
177 buf_ptr = buf->image + plane;
\r
178 vga_ptr = base_vga;
\r
180 outpw(SEQU_ADDR, plane_mask[plane]);
\r
186 *vga_ptr++ = *buf_ptr;
\r
198 aligned_getblitX(COORD x, COORD y, blitbuf *buf)
\r
200 short int i, j, plane, skip, xsize, ysize;
\r
205 xsize = (buf->xsize >> 2);
\r
206 ysize = buf->ysize;
\r
207 skip = widthBytes - xsize;
\r
208 base_vga = RowsX[y] + (x >> 2) + activeStart;
\r
210 for (plane=0; plane < 4; plane++) {
\r
211 buf_ptr = buf->image + plane;
\r
212 vga_ptr = base_vga;
\r
214 outpw(GRACON_ADDR, read_mask[plane]);
\r
220 *buf_ptr = *vga_ptr++;
\r
232 transparent_bitblitX(COORD x, COORD y, blitbuf *buf)
\r
234 short int i, j, plane, skip, xsize, ysize;
\r
239 xsize = (buf->xsize >> 2);
\r
240 ysize = buf->ysize;
\r
241 skip = widthBytes - xsize;
\r
242 base_vga = RowsX[y] + (x >> 2) + activeStart;
\r
244 for (plane=0; plane < 4; plane++) {
\r
245 buf_ptr = buf->image + plane;
\r
246 vga_ptr = base_vga;
\r
248 outpw(SEQU_ADDR, plane_mask[plane]);
\r
255 *vga_ptr = *buf_ptr;
\r
269 planar_bitblitX(COORD x, COORD y, blitbuf *buf)
\r
271 short int i, plane, xsize, ysize;
\r
276 xsize = (buf->xsize >> 2);
\r
277 ysize = buf->ysize;
\r
278 base_vga = RowsX[y] + (x >> 2) + activeStart;
\r
279 buf_ptr = buf->image;
\r
281 for (plane=0; plane < 4; plane++) {
\r
282 vga_ptr = base_vga;
\r
284 outpw(SEQU_ADDR, plane_mask[plane]);
\r
288 memcpy(vga_ptr, buf_ptr, xsize);
\r
289 vga_ptr += widthBytes;
\r
299 planar_getblitX(COORD x, COORD y, blitbuf *buf)
\r
301 short int i, plane, xsize, ysize;
\r
306 xsize = (buf->xsize >> 2);
\r
307 ysize = buf->ysize;
\r
308 base_vga = RowsX[y] + (x >> 2) + activeStart;
\r
309 buf_ptr = buf->image;
\r
311 for (plane=0; plane < 4; plane++) {
\r
312 vga_ptr = base_vga;
\r
314 outpw(GRACON_ADDR, read_mask[plane]);
\r
318 memcpy(buf_ptr, vga_ptr, xsize);
\r
319 vga_ptr += widthBytes;
\r
329 wide_bitblitX(COORD y, blitbuf *buf)
\r
336 buf_ptr = buf->image;
\r
337 vga_ptr = RowsX[y] + activeStart;
\r
338 bufsize = (buf->ysize * widthBytes);
\r
340 outpw(SEQU_ADDR, PLANE_0);
\r
341 memcpy(vga_ptr, buf_ptr, bufsize);
\r
342 buf_ptr += bufsize;
\r
344 outpw(SEQU_ADDR, PLANE_1);
\r
345 memcpy(vga_ptr, buf_ptr, bufsize);
\r
346 buf_ptr += bufsize;
\r
348 outpw(SEQU_ADDR, PLANE_2);
\r
349 memcpy(vga_ptr, buf_ptr, bufsize);
\r
350 buf_ptr += bufsize;
\r
352 outpw(SEQU_ADDR, PLANE_3);
\r
353 memcpy(vga_ptr, buf_ptr, bufsize);
\r
358 wide_getblitX(COORD y, blitbuf *buf)
\r
365 buf_ptr = buf->image;
\r
366 vga_ptr = RowsX[y] + activeStart;
\r
367 bufsize = (buf->ysize * widthBytes);
\r
369 outpw(GRACON_ADDR, READ_PLANE_0);
\r
370 memcpy(buf_ptr, vga_ptr, bufsize);
\r
371 buf_ptr += bufsize;
\r
373 outpw(GRACON_ADDR, READ_PLANE_1);
\r
374 memcpy(buf_ptr, vga_ptr, bufsize);
\r
375 buf_ptr += bufsize;
\r
377 outpw(GRACON_ADDR, READ_PLANE_2);
\r
378 memcpy(buf_ptr, vga_ptr, bufsize);
\r
379 buf_ptr += bufsize;
\r
381 outpw(GRACON_ADDR, READ_PLANE_3);
\r
382 memcpy(buf_ptr, vga_ptr, bufsize);
\r
387 save_blitbufPCX(char *fname, blitbuf *buf)
\r
390 unsigned int i, size, temp_int;
\r
393 BYTE temp_char, match, count;
\r
395 fp = fopen(fname, "wb");
\r
398 // Write manufacturer's byte
\r
400 fwrite(&temp_char, 1, 1, fp);
\r
402 // Write version of PCX. 5 = 256 color (PCX Version 5.0)
\r
404 fwrite(&temp_char, 1, 1, fp);
\r
406 // Write encoding type, always 1 for RLE.
\r
408 fwrite(&temp_char, 1, 1, fp);
\r
410 // Write bits_per_pixel = 8.
\r
412 fwrite(&temp_char, 1, 1, fp);
\r
414 // Write starting X and Y coords
\r
416 fwrite(&temp_int, 2, 1, fp);
\r
417 fwrite(&temp_int, 2, 1, fp);
\r
420 temp_int = (buf->xsize - 1);
\r
421 fwrite(&temp_int, 2, 1, fp);
\r
424 temp_int = (buf->ysize - 1);
\r
425 fwrite(&temp_int, 2, 1, fp);
\r
427 // Do HRES and VRES **
\r
428 temp_int = buf->xsize;
\r
429 fwrite(&temp_int, 2, 1, fp);
\r
430 temp_int = buf->ysize;
\r
431 fwrite(&temp_int, 2, 1, fp);
\r
433 // Write 16 color palette, not used.
\r
437 fwrite(&temp_int, 2, 1, fp);
\r
440 // Write vmode byte.
\r
442 fwrite(&temp_char, 1, 1, fp);
\r
444 // Write bit_planes
\r
446 fwrite(&temp_char, 1, 1, fp);
\r
448 // Write bytes_per_line
\r
449 temp_int = buf->xsize;
\r
450 fwrite(&temp_int, 2, 1, fp);
\r
452 // Write palette type
\r
454 fwrite(&temp_int, 2, 1, fp);
\r
456 // Write junk filler
\r
460 fwrite(&temp_int, 2, 1, fp);
\r
463 // Write the actual image
\r
464 buf_ptr = buf->image;
\r
465 size = (buf->xsize * buf->ysize);
\r
472 temp_char = *buf_ptr++;
\r
474 if ((temp_char == match) && (count < 63)) {
\r
477 if ((count == 1) && (match < 192)) {
\r
478 // Write single byte
\r
479 fwrite(&match,1,1,fp);
\r
481 // Write run of pixels
\r
483 fwrite(&count, 1, 1, fp);
\r
484 fwrite(&match, 1, 1, fp);
\r
491 if ((count == 1) && (match < 192)) {
\r
492 // Write single byte
\r
493 fwrite(&match,1,1,fp);
\r
495 // Write run of pixels
\r
497 fwrite(&count, 1, 1, fp);
\r
498 fwrite(&match, 1, 1, fp);
\r
501 // Write palette verification byte
\r
503 fwrite(&temp_char, 1, 1, fp);
\r
505 get_paletteX(VGA_pal);
\r
507 // Write 256 color palette
\r
508 fwrite(VGA_pal, 1, 768, fp);
\r
516 load_blitbufPCX(char *fname, blitbuf *buf)
\r
521 BYTE PCX_byte, RLE_byte;
\r
525 fp = fopen(fname, "rb");
\r
533 fseek(fp, 8, SEEK_SET);
\r
534 fread(&buf->xsize, 2, 1, fp);
\r
535 fread(&buf->ysize, 2, 1, fp);
\r
540 size = (buf->xsize * buf->ysize);
\r
542 buf->image = new BYTE[size];
\r
543 buf_ptr = buf->image;
\r
544 end_of_buf = buf_ptr + size;
\r
546 // Load 256 color PCX palette
\r
547 fseek(fp, -768, SEEK_END);
\r
548 fread(VGA_pal, 1, 768, fp);
\r
550 set_paletteX(VGA_pal);
\r
552 fseek(fp, 128, SEEK_SET);
\r
554 while (buf_ptr < end_of_buf) {
\r
555 // Read next packet
\r
556 fread(&PCX_byte, 1, 1, fp);
\r
558 if (PCX_byte < 192) {
\r
560 *buf_ptr++ = PCX_byte;
\r
563 PCX_byte = PCX_byte & 0x3F;
\r
564 fread(&RLE_byte, 1, 1, fp);
\r
565 memset(buf_ptr, RLE_byte, PCX_byte);
\r
566 buf_ptr += PCX_byte;
\r
577 scale_blitbuf(DIST dest_x, DIST dest_y, blitbuf *buf1, blitbuf *buf2)
\r
579 unsigned long ErrorAccX, ErrorAccY, ErrorAdjX, ErrorAdjY;
\r
580 DIST oldx, oldy, newx, newy;
\r
581 short int i, j, count;
\r
587 oldx = buf1->xsize;
\r
588 oldy = buf1->ysize;
\r
592 newbuf = new BYTE[newx * newy];
\r
594 src_base = buf1->image;
\r
597 // My bitmap scaling routine. As you probably noticed, it's
\r
598 // pretty Bresenhammy!
\r
600 ErrorAccY = 0x8000;
\r
604 ErrorAdjX = ((((unsigned long)newx) << 16) /
\r
605 (((unsigned long)oldx)));
\r
607 ErrorAdjY = ((((unsigned long)newy) << 16) /
\r
608 (((unsigned long)oldy)));
\r
612 ErrorAccX = 0x8000;
\r
613 src_ptr = src_base;
\r
617 ErrorAccX += ErrorAdjX;
\r
618 if (count = (ErrorAccX >> 16)) {
\r
619 ErrorAccX &= 0xFFFFL;
\r
621 *dest_ptr++ = *src_ptr;
\r
627 ErrorAccY += ErrorAdjY;
\r
628 count = (ErrorAccY >> 16) - 1;
\r
630 memcpy(dest_ptr, dest_ptr - newx, newx);
\r
633 ErrorAccY &= 0xFFFFL;
\r
638 ErrorAdjX = ((((unsigned long)oldx) << 16) /
\r
639 (((unsigned long)newx)));
\r
641 ErrorAdjY = ((((unsigned long)oldy) << 16) /
\r
642 (((unsigned long)newy)));
\r
646 ErrorAccX = 0x8000;
\r
647 src_ptr = src_base;
\r
651 *dest_ptr++ = *src_ptr;
\r
652 ErrorAccX += ErrorAdjX;
\r
653 src_ptr += (ErrorAccX >> 16);
\r
654 ErrorAccX &= 0xFFFFL;
\r
657 ErrorAccY += ErrorAdjY;
\r
658 src_base += (oldx * (ErrorAccY >> 16));
\r
659 ErrorAccY &= 0xFFFFL;
\r
663 if (buf2 == NULL) {
\r
664 delete buf1->image;
\r
665 buf1->xsize = newx;
\r
666 buf1->ysize = newy;
\r
667 buf1->image = newbuf;
\r
669 if (buf2->image != NULL) {
\r
670 delete buf2->image;
\r
672 buf2->xsize = newx;
\r
673 buf2->ysize = newy;
\r
674 buf2->image = newbuf;
\r
680 vertical_scale_blitbuf(DIST dest_y, blitbuf *buf1, blitbuf *buf2)
\r
682 unsigned long ErrorAccY, ErrorAdjY;
\r
683 DIST xsize, oldy, newy;
\r
684 short int i, count;
\r
689 xsize = buf1->xsize;
\r
690 oldy = buf1->ysize;
\r
693 newbuf = new BYTE[xsize * newy];
\r
695 src_ptr = buf1->image;
\r
698 // My bitmap scaling routine. As you probably noticed, it's
\r
699 // pretty Bresenhammy!
\r
701 ErrorAccY = 0x8000;
\r
702 ErrorAdjY = ((((unsigned long)newy) << 16) /
\r
703 (((unsigned long)oldy)));
\r
705 if (newy >= oldy) {
\r
709 ErrorAccY += ErrorAdjY;
\r
710 if (count = (ErrorAccY >> 16)) {
\r
711 ErrorAccY &= 0xFFFFL;
\r
714 memcpy(dest_ptr, src_ptr, xsize);
\r
725 ErrorAccY += ErrorAdjY;
\r
726 if (ErrorAccY & ~0xFFFFL) {
\r
727 ErrorAccY &= 0xFFFFL;
\r
728 memcpy(dest_ptr, src_ptr, xsize);
\r
736 if (buf2 == NULL) {
\r
737 delete buf1->image;
\r
738 buf1->ysize = newy;
\r
739 buf1->image = newbuf;
\r
741 if (buf2->image != NULL) {
\r
742 delete buf2->image;
\r
744 buf2->xsize = xsize;
\r
745 buf2->ysize = newy;
\r
746 buf2->image = newbuf;
\r
752 greyscale_blitbuf(blitbuf *buf)
\r
754 BYTE temp_pal[768];
\r
760 buf_ptr = buf->image;
\r
762 get_paletteX(temp_pal, 0);
\r
764 for (i = (buf->xsize * buf->ysize); i; i--) {
\r
765 temp = temp_pal + ((*buf_ptr) * 3);
\r
769 *buf_ptr++ = ((r * 19) + (g * 37) + (*temp << 3)) >> 6;
\r
775 RGB_blitbuf(blitbuf *buf)
\r
777 BYTE temp_pal[768];
\r
783 buf_ptr = buf->image;
\r
785 get_paletteX(temp_pal, 0);
\r
787 for (i = (buf->xsize * buf->ysize); i; i--) {
\r
788 temp = temp_pal + ((*buf_ptr) * 3);
\r
795 *buf_ptr++ = ((r >> 3) << 5) + ((g >> 3) << 2) + (b >> 4);
\r
801 flip_vertical_blitbuf(blitbuf *buf)
\r
811 temp = new BYTE[x];
\r
814 bottom = buf->image + (x * (y-1));
\r
818 memcpy(temp, top, x);
\r
819 memcpy(top, bottom, x);
\r
820 memcpy(bottom, temp, x);
\r
830 flip_horizontal_blitbuf(blitbuf *buf)
\r
839 temp = new BYTE[x];
\r
841 buf_ptr = buf->image;
\r
845 memcpy(temp, buf_ptr, x);
\r
846 temp_ptr = temp + (x - 1);
\r
849 *buf_ptr++ = *temp_ptr--;
\r
858 brighten_blitbuf(SBYTE factor, blitbuf *buf)
\r
864 buf_ptr = buf->image;
\r
866 for (i = (buf->xsize * buf->ysize); i; i--) {
\r
867 scratch = (*buf_ptr + factor);
\r
868 if (scratch <= 0) {
\r
870 } else if (scratch >= 63) {
\r
873 *buf_ptr++ = scratch;
\r
880 stretch_blitbuf(BYTE factor, blitbuf *buf)
\r
886 buf_ptr = buf->image;
\r
888 for (i = (buf->xsize * buf->ysize); i; i--) {
\r
889 scratch = ((((*buf_ptr - 32) * factor) + 8) >> 4) + 32;
\r
890 if (scratch <= 0) {
\r
892 } else if (scratch >= 63) {
\r
895 *buf_ptr++ = scratch;
\r
902 pixelize(DIST pixfactor, blitbuf *buf)
\r
909 GREYconvolve_blitbuf(BYTE *kernel, blitbuf *buf)
\r
916 RGBconvolve_blitbuf(BYTE *kernel, blitbuf *buf)
\r
923 scale_scanline(BYTE *source, BYTE *dest, DIST smap_size, DIST dmap_size,
\r
926 unsigned long ErrorAcc, ErrorAdj;
\r
927 short int i, temp, invert;
\r
931 // Prepare for backwards scanlines
\r
932 if (dline_size >= 0) {
\r
936 dline_size = -dline_size;
\r
939 if (dline_size > smap_size) {
\r
941 if (smap_size == 0) {
\r
944 ErrorAdj = ((((unsigned long)dline_size) << 16) /
\r
945 (((unsigned long)smap_size)));
\r
949 ErrorAcc += ErrorAdj;
\r
950 temp = (ErrorAcc >> 16);
\r
951 ErrorAcc &= 0xFFFFL;
\r
959 if (dline_size == 0) {
\r
960 memset(dest, 0, dmap_size);
\r
962 temp = dmap_size - dline_size;
\r
969 ErrorAdj = ((((unsigned long)smap_size) << 16) /
\r
970 (((unsigned long)dline_size)));
\r
976 ErrorAcc += ErrorAdj;
\r
977 source += (ErrorAcc >> 16);
\r
978 ErrorAcc &= 0xFFFFL;
\r
990 load_blitbufRAW(char *rawname, char *palname, blitbuf *buf)
\r
995 fp = fopen(rawname, "rb");
\r
1000 buf->image = NULL;
\r
1005 buf->image = new BYTE[64000L];
\r
1008 fread(buf->image, 64000L, 1, fp);
\r
1010 if (palname == NULL) {
\r
1011 fread(VGA_pal, 1, 768, fp);
\r
1012 set_paletteX(VGA_pal);
\r
1016 fp = fopen(palname, "rb");
\r
1018 fread(VGA_pal, 1, 768, fp);
\r
1019 set_paletteX(VGA_pal);
\r