From: Robert Lowe Date: Sat, 3 Jan 2015 23:00:56 +0000 (-0500) Subject: Created data structures for planar buffers X-Git-Url: http://4ch.mooo.com/gitweb/?a=commitdiff_plain;h=2fe35c053f6f106895e87ee646ec00eea32b605a;p=16.git Created data structures for planar buffers --- diff --git a/16/Q.BAT b/16/Q.BAT deleted file mode 100644 index 5d1b5845..00000000 --- a/16/Q.BAT +++ /dev/null @@ -1,5 +0,0 @@ -call hres -vi dos_gfx.cpp -call x -pause -dos_gfx.exe diff --git a/16/lib/TYPES.H b/16/lib/TYPES.H deleted file mode 100644 index 039653f2..00000000 --- a/16/lib/TYPES.H +++ /dev/null @@ -1,11 +0,0 @@ -/* - * Just some handy typedefs that make it easier to think about the low - * level code - */ - -typedef unsigned char byte; -typedef unsigned short word; -typedef unsigned long dword; -typedef signed char sbyte; -typedef signed short sword; -typedef signed long sdword; diff --git a/makefile b/makefile index 0a47caf6..ebc15e33 100644 --- a/makefile +++ b/makefile @@ -10,8 +10,8 @@ scroll.obj: $(SRC)scroll.c test.exe: test.obj modex16.obj bitmap.obj wcl $(FLAGS) test.obj modex16.obj bitmap.obj -test2.exe: test2.obj modex16.obj bitmap.obj - wcl $(FLAGS) test2.obj modex16.obj bitmap.obj +test2.exe: test2.obj modex16.obj bitmap.obj planar.obj + wcl $(FLAGS) test2.obj modex16.obj bitmap.obj planar.obj pcxtest.exe: pcxtest.obj modex16.obj bitmap.obj wcl $(FLAGS) pcxtest.obj modex16.obj bitmap.obj @@ -33,6 +33,9 @@ dos_kb.obj: $(SRCLIB)dos_kb.h $(SRCLIB)dos_kb.c bitmap.obj: $(SRCLIB)bitmap.h $(SRCLIB)bitmap.c wcl $(FLAGS) -c $(SRCLIB)bitmap.c + +planar.obj: $(SRCLIB)planar.h $(SRCLIB)planar.c + wcl $(FLAGS) -c $(SRCLIB)planar.c clean: del *.obj diff --git a/pcxtest.exe b/pcxtest.exe index 1a99ead2..e13ada66 100644 Binary files a/pcxtest.exe and b/pcxtest.exe differ diff --git a/scroll.exe b/scroll.exe index ba9037f2..05fc5f4e 100644 Binary files a/scroll.exe and b/scroll.exe differ diff --git a/src/lib/PLANAR.C b/src/lib/PLANAR.C new file mode 100644 index 00000000..8b9f0042 --- /dev/null +++ b/src/lib/PLANAR.C @@ -0,0 +1,78 @@ +/* + * Implimentation of the planar buffer files. + */ +#include +#include "planar.h" + +/* creates a planar buffer from the bitmap data. + The planar buffer is dynamically allocated, and should + be destroyed with the planar_buf_free function when no longer + needed. + */ +planar_buf_t * +planar_buf_from_bitmap(bitmap_t *b) { + planar_buf_t *p; + int plane, bi, pi, x, y; + + /* allocate the buffer */ + p = planar_buf_alloc(b->width, b->height); + + /* copy the bitmap data into the planar format */ + bi=0; + pi=0; + for(y=0; y < b->height; y++) { + /* start on the first plane */ + plane=0; + for(x=0; x < b->width; x++) { + /* copy to each plane */ + p->plane[plane++][pi]=b->data[bi++]; + + /* handle the completion of 4 planes. */ + if(plane==4) { + plane=0; + pi++; + } + } + + /* correct for images not divisible by 4 */ + if(plane) pi++; + } + + return p; +} + + +/* allocates a planar buffer with specified dimensions */ +planar_buf_t * +planar_buf_alloc(word width, word height) { + planar_buf_t *p; + int i; + + /* allocate the structure and populate sizes */ + p=malloc(sizeof(planar_buf_t)); + p->width = width; + p->height = height; + p->pwidth = width / 4 + (width%4 ? 1 : 0); + + /* allocate the planes */ + for(i=0; i<4; i++) { + p->plane[i] = malloc(p->height * p->pwidth); + } + + return p; +} + + +/* deallocates a planar buffer */ +void +planar_buf_free(planar_buf_t *p) { + int i; + + /* free the planes */ + for(i=0; i<4; i++) { + free(p->plane[i]); + } + + /* free the structure */ + free(p); +} diff --git a/src/lib/planar.h b/src/lib/planar.h new file mode 100644 index 00000000..6aa8e260 --- /dev/null +++ b/src/lib/planar.h @@ -0,0 +1,31 @@ +/* + * Functions and types for a planar image buffer. + * This is meant to be able to load into video memory faster. + */ +#include "bitmap.h" + +#ifndef PLANAR_H +#define PLANAR_H +typedef struct { + byte *plane[4]; /* 4 planes of image data */ + word width; /* width of the image (spread across 4 planes) */ + word height; /* height of the image (spread across 4 planes) */ + word pwidth; /* the number of bytes in each plane */ +} planar_buf_t; + + +/* creates a planar buffer from the bitmap data. + The planar buffer is dynamically allocated, and should + be destroyed with the planar_buf_free function when no longer + needed. + */ +planar_buf_t *planar_buf_from_bitmap(bitmap_t *b); + + +/* allocates a planar buffer with specified dimensions */ +planar_buf_t *planar_buf_alloc(word width, word height); + + +/* deallocates a planar buffer */ +void planar_buf_free(planar_buf_t *p); +#endif diff --git a/src/test2.c b/src/test2.c index 5b3d32c0..ac939e57 100644 --- a/src/test2.c +++ b/src/test2.c @@ -1,19 +1,46 @@ +#include #include "src\lib\modex16.h" +#include "src\lib\planar.h" +#include "src\lib\bitmap.h" word far* clock= (word far*) 0x046C; /* 18.2hz clock */ void main() { + bitmap_t bmp; + planar_buf_t *p; + word size; int i; - word start; - page_t page; + int plane; + int x,y; + byte color; - page=modexDefaultPage(); + /* get the size we want */ + printf("Width: "); + scanf("%d", &bmp.width); + printf("Height: "); + scanf("%d", &bmp.height); + printf("Color: "); + scanf("%x", &color); - modexEnter(); - start = *clock; - for(i=0; i<500; i++) { - modexShowPage(&page); + /* allocate the bmp and fill it with 42 */ + size = bmp.width * bmp.height; + bmp.data = malloc(size); + for(i=0; iheight; y++) { + for(x=0; x < p->pwidth; x++) { + printf("%02X ", (int) p->plane[plane][i++]); + } + printf("\n"); + } + } } diff --git a/test.exe b/test.exe index fcccbf07..4dae76db 100644 Binary files a/test.exe and b/test.exe differ diff --git a/test2.exe b/test2.exe index ca41644c..7878dbc4 100644 Binary files a/test2.exe and b/test2.exe differ