OSDN Git Service

Created data structures for planar buffers
authorRobert Lowe <pngwen@acm.org>
Sat, 3 Jan 2015 23:00:56 +0000 (18:00 -0500)
committerRobert Lowe <pngwen@acm.org>
Sat, 3 Jan 2015 23:00:56 +0000 (18:00 -0500)
16/Q.BAT [deleted file]
16/lib/TYPES.H [deleted file]
makefile
pcxtest.exe
scroll.exe
src/lib/PLANAR.C [new file with mode: 0644]
src/lib/planar.h [new file with mode: 0644]
src/test2.c
test.exe
test2.exe

diff --git a/16/Q.BAT b/16/Q.BAT
deleted file mode 100644 (file)
index 5d1b584..0000000
--- a/16/Q.BAT
+++ /dev/null
@@ -1,5 +0,0 @@
-call hres\r
-vi dos_gfx.cpp\r
-call x\r
-pause\r
-dos_gfx.exe\r
diff --git a/16/lib/TYPES.H b/16/lib/TYPES.H
deleted file mode 100644 (file)
index 039653f..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-/*\r
- * Just some handy typedefs that make it easier to think about the low\r
- * level code\r
- */\r
-\r
-typedef unsigned char byte;\r
-typedef unsigned short word;\r
-typedef unsigned long  dword;\r
-typedef signed char sbyte;\r
-typedef signed short sword;\r
-typedef signed long sdword;\r
index 0a47caf..ebc15e3 100644 (file)
--- a/makefile
+++ b/makefile
@@ -10,8 +10,8 @@ scroll.obj: $(SRC)scroll.c
 test.exe: test.obj modex16.obj bitmap.obj\r
        wcl $(FLAGS) test.obj modex16.obj bitmap.obj\r
        \r
-test2.exe: test2.obj modex16.obj bitmap.obj\r
-       wcl $(FLAGS) test2.obj modex16.obj bitmap.obj\r
+test2.exe: test2.obj modex16.obj bitmap.obj planar.obj\r
+       wcl $(FLAGS) test2.obj modex16.obj bitmap.obj planar.obj\r
        \r
 pcxtest.exe: pcxtest.obj modex16.obj bitmap.obj\r
        wcl $(FLAGS) pcxtest.obj modex16.obj bitmap.obj\r
@@ -33,6 +33,9 @@ dos_kb.obj: $(SRCLIB)dos_kb.h $(SRCLIB)dos_kb.c
 \r
 bitmap.obj: $(SRCLIB)bitmap.h $(SRCLIB)bitmap.c\r
        wcl $(FLAGS) -c $(SRCLIB)bitmap.c\r
+\r
+planar.obj: $(SRCLIB)planar.h $(SRCLIB)planar.c\r
+       wcl $(FLAGS) -c $(SRCLIB)planar.c\r
        \r
 clean: \r
        del *.obj\r
index 1a99ead..e13ada6 100644 (file)
Binary files a/pcxtest.exe and b/pcxtest.exe differ
index ba9037f..05fc5f4 100644 (file)
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 (file)
index 0000000..8b9f004
--- /dev/null
@@ -0,0 +1,78 @@
+/*\r
+ * Implimentation of the planar buffer files.\r
+ */\r
+#include <stdlib.h>\r
+#include "planar.h"\r
+\r
+/* creates a planar buffer from the bitmap data.\r
+   The planar buffer is dynamically allocated, and should\r
+   be destroyed with the planar_buf_free function when no longer\r
+   needed.\r
+ */\r
+planar_buf_t *\r
+planar_buf_from_bitmap(bitmap_t *b) {\r
+    planar_buf_t *p;\r
+    int plane, bi, pi, x, y;\r
+\r
+    /* allocate the buffer */\r
+    p = planar_buf_alloc(b->width, b->height);\r
+\r
+    /* copy the bitmap data into the planar format */\r
+    bi=0;\r
+    pi=0;\r
+    for(y=0; y < b->height; y++) {\r
+       /* start on the first plane */\r
+       plane=0;\r
+       for(x=0; x < b->width; x++) {\r
+           /* copy to each plane */\r
+           p->plane[plane++][pi]=b->data[bi++];\r
+\r
+           /* handle the completion of 4 planes. */\r
+           if(plane==4) {\r
+               plane=0;\r
+               pi++;\r
+           }\r
+       }\r
+\r
+       /* correct for images not divisible by 4 */\r
+       if(plane) pi++;\r
+    }\r
+\r
+    return p;\r
+}\r
+\r
+\r
+/* allocates a planar buffer with specified dimensions */\r
+planar_buf_t *\r
+planar_buf_alloc(word width, word height) {\r
+    planar_buf_t *p;\r
+    int i;\r
+\r
+    /* allocate the structure and populate sizes */\r
+    p=malloc(sizeof(planar_buf_t));\r
+    p->width  = width;\r
+    p->height = height;\r
+    p->pwidth = width / 4 + (width%4 ? 1 : 0);\r
+\r
+    /* allocate the planes */\r
+    for(i=0; i<4; i++) {\r
+       p->plane[i] = malloc(p->height * p->pwidth);\r
+    }\r
+\r
+    return p;\r
+}\r
+\r
+\r
+/* deallocates a planar buffer */\r
+void\r
+planar_buf_free(planar_buf_t *p) {\r
+    int i;\r
+\r
+    /* free the planes */\r
+    for(i=0; i<4; i++) {\r
+       free(p->plane[i]);\r
+    }\r
+\r
+    /* free the structure */\r
+    free(p);\r
+}\r
diff --git a/src/lib/planar.h b/src/lib/planar.h
new file mode 100644 (file)
index 0000000..6aa8e26
--- /dev/null
@@ -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
index 5b3d32c..ac939e5 100644 (file)
@@ -1,19 +1,46 @@
+#include <stdio.h>\r
 #include "src\lib\modex16.h"\r
+#include "src\lib\planar.h"\r
+#include "src\lib\bitmap.h"\r
 \r
 word far* clock= (word far*) 0x046C; /* 18.2hz clock */\r
 \r
 void main() {\r
+    bitmap_t bmp;\r
+    planar_buf_t *p;\r
+    word size;\r
     int i;\r
-    word start;\r
-    page_t page;\r
+    int plane;\r
+    int x,y;\r
+    byte color;\r
 \r
-    page=modexDefaultPage();\r
+    /* get the size we want */\r
+    printf("Width: ");\r
+    scanf("%d", &bmp.width);\r
+    printf("Height: ");\r
+    scanf("%d", &bmp.height);\r
+    printf("Color: ");\r
+    scanf("%x", &color);\r
 \r
-    modexEnter();\r
-    start = *clock;\r
-    for(i=0; i<500; i++) {\r
-       modexShowPage(&page);\r
+    /* allocate the bmp and fill it with 42 */\r
+    size = bmp.width * bmp.height;\r
+    bmp.data = malloc(size);\r
+    for(i=0; i<size; i++) {\r
+       bmp.data[i] = color;\r
     }\r
-    modexLeave();\r
 \r
+    /* create the planar buffer */\r
+    p = planar_buf_from_bitmap(&bmp);\r
+\r
+    /* print out the contents of each plane */\r
+    for(plane=0; plane < 4; plane++) {\r
+        i=0;\r
+       printf("Plane %d\n", plane);\r
+       for(y=0; y < p->height; y++) {\r
+           for(x=0; x < p->pwidth; x++) {\r
+               printf("%02X ", (int) p->plane[plane][i++]);\r
+           }\r
+           printf("\n");\r
+       }\r
+    }\r
 }\r
index fcccbf0..4dae76d 100644 (file)
Binary files a/test.exe and b/test.exe differ
index ca41644..7878dbc 100644 (file)
Binary files a/test2.exe and b/test2.exe differ