From 3e0f741630175b268f469d9c2e53cfe0e43c408a Mon Sep 17 00:00:00 2001 From: metan Date: Wed, 23 Feb 2011 23:21:19 +0100 Subject: [PATCH] cleanup: - bits_per_pixel -> bpp - GP_VLine() is now in algo/VLine.algo.h --- algo/HLine.algo.h | 4 +-- algo/{HLine.algo.h => VLine.algo.h} | 41 +++++++++------------------ core/GP_Context.c | 2 +- core/GP_Context.h | 4 +-- core/GP_FnPerBpp.h | 2 +- core/GP_VLine.c | 55 +++++++------------------------------ doc/Makefile | 5 +++- drivers/GP_Framebuffer.c | 2 +- loaders/tests/autotest.sh | 2 +- targets/sdl/GP_SDL_Context.c | 2 +- 10 files changed, 36 insertions(+), 83 deletions(-) copy algo/{HLine.algo.h => VLine.algo.h} (72%) diff --git a/algo/HLine.algo.h b/algo/HLine.algo.h index 7566d8ce..2d0d6657 100644 --- a/algo/HLine.algo.h +++ b/algo/HLine.algo.h @@ -63,7 +63,7 @@ void FN_NAME(GP_Context *context, int x0, int x1, int y, GP_Pixel pixel) \ } /* - * Not byte aligned pixels. The bits_per_pixel must be power of two. + * Not byte aligned pixels. The number of bits per pixel must be power of two. */ #define DEF_HLINE_BU_FN(FN_NAME, CONTEXT_T, PIXEL_T, PIXEL_ADDRESS, WRITE_PIXELS) \ void FN_NAME(GP_Context *context, int x0, int x1, int y, GP_Pixel pixel) \ @@ -73,5 +73,5 @@ void FN_NAME(GP_Context *context, int x0, int x1, int y, GP_Pixel pixel) \ size_t length = 1 + x1 - x0; \ void *start = GP_PIXEL_ADDRESS(context, y, x0); \ \ - WRITE_PIXELS(start, x0 % (8 / context->bits_per_pixel), length, pixel); \ + WRITE_PIXELS(start, x0 % (8 / context->bpp), length, pixel); \ } diff --git a/algo/HLine.algo.h b/algo/VLine.algo.h similarity index 72% copy from algo/HLine.algo.h copy to algo/VLine.algo.h index 7566d8ce..daa6f9d1 100644 --- a/algo/HLine.algo.h +++ b/algo/VLine.algo.h @@ -23,21 +23,21 @@ * * *****************************************************************************/ -/* A horizontal line drawing algorithm. */ +/* A vertical line drawing algorithm. */ /* Ensures that coordinates are in correct order, and clips them. * Exits immediately if the line is completely clipped out. */ #define ORDER_AND_CLIP_COORDS do { \ - if (x0 > x1) GP_SWAP(x0, x1); \ - if (y < (int) context->clip_h_min \ - || y > (int) context->clip_h_max \ - || x0 > (int) context->clip_w_max \ - || x1 < (int) context->clip_w_min) { \ + if (y0 > y1) GP_SWAP(y0, y1); \ + if (x < (int) context->clip_w_min \ + || x > (int) context->clip_w_max \ + || y1 < (int) context->clip_h_min \ + || y0 > (int) context->clip_h_max) { \ return; \ } \ - x0 = GP_MAX(x0, (int) context->clip_w_min); \ - x1 = GP_MIN(x1, (int) context->clip_w_max); \ + y0 = GP_MAX(y0, (int) context->clip_h_min); \ + y1 = GP_MIN(y1, (int) context->clip_h_max); \ } while (0) /* @@ -51,27 +51,12 @@ * in form f(start, length, pixel) * FN_NAME - name of the function to be defined */ -#define DEF_HLINE_FN(FN_NAME, CONTEXT_T, PIXEL_T, PIXEL_ADDRESS, WRITE_PIXELS) \ -void FN_NAME(GP_Context *context, int x0, int x1, int y, GP_Pixel pixel) \ +#define DEF_VLINE_FN(FN_NAME, CONTEXT_T, PIXEL_T, PUT_PIXEL) \ +void FN_NAME(CONTEXT_T context, int x, int y0, int y1, PIXEL_T pixel) \ { \ ORDER_AND_CLIP_COORDS; \ + int y; \ \ - size_t length = 1 + x1 - x0; \ - void *start = GP_PIXEL_ADDRESS(context, y, x0); \ -\ - WRITE_PIXELS(start, length, pixel); \ -} - -/* - * Not byte aligned pixels. The bits_per_pixel must be power of two. - */ -#define DEF_HLINE_BU_FN(FN_NAME, CONTEXT_T, PIXEL_T, PIXEL_ADDRESS, WRITE_PIXELS) \ -void FN_NAME(GP_Context *context, int x0, int x1, int y, GP_Pixel pixel) \ -{ \ - ORDER_AND_CLIP_COORDS; \ -\ - size_t length = 1 + x1 - x0; \ - void *start = GP_PIXEL_ADDRESS(context, y, x0); \ -\ - WRITE_PIXELS(start, x0 % (8 / context->bits_per_pixel), length, pixel); \ + for (y = y0; y <= y1; y++) \ + PUT_PIXEL(context, x, y, pixel); \ } diff --git a/core/GP_Context.c b/core/GP_Context.c index b1b07114..f10edd99 100644 --- a/core/GP_Context.c +++ b/core/GP_Context.c @@ -46,7 +46,7 @@ GP_Context *GP_ContextAlloc(uint32_t w, uint32_t h, GP_PixelType type) } context->pixels = pixels; - context->bits_per_pixel = bpp; + context->bpp = bpp; context->bytes_per_row = bpr; context->w = w; diff --git a/core/GP_Context.h b/core/GP_Context.h index 006c219d..709a8b04 100644 --- a/core/GP_Context.h +++ b/core/GP_Context.h @@ -35,7 +35,7 @@ /* This structure holds all information needed for drawing into an image. */ typedef struct GP_Context { uint8_t *pixels; /* pointer to image pixels */ - uint8_t bits_per_pixel; /* values: 1, 2, 4, 8, 16, 24, 32 */ + uint8_t bpp; /* values: 1, 2, 4, 8, 16, 24, 32 */ uint32_t bytes_per_row; uint32_t w; /* width */ uint32_t h; /* heigth */ @@ -65,7 +65,7 @@ inline GP_PixelType GP_GetContextPixelType(const GP_Context *context); */ #define GP_PIXEL_ADDRESS(context, y, x) ((uint8_t *) (context->pixels \ + y * context->bytes_per_row \ - + (x * context->bits_per_pixel) / 8)) + + (x * context->bpp) / 8)) /* Evaluates to true if the context is valid (sane), false otherwise. */ #define GP_IS_CONTEXT_VALID(context) ( \ diff --git a/core/GP_FnPerBpp.h b/core/GP_FnPerBpp.h index 4261b0bc..6c7b344e 100644 --- a/core/GP_FnPerBpp.h +++ b/core/GP_FnPerBpp.h @@ -33,7 +33,7 @@ */ #define GP_FN_PER_BPP(FN_NAME, ...) \ \ - switch (context->bits_per_pixel) { \ + switch (context->bpp) { \ case 1: \ FN_NAME##1bpp(context, __VA_ARGS__); \ break; \ diff --git a/core/GP_VLine.c b/core/GP_VLine.c index cd144a7c..519b0033 100644 --- a/core/GP_VLine.c +++ b/core/GP_VLine.c @@ -24,6 +24,15 @@ *****************************************************************************/ #include "GP.h" +#include "algo/VLine.algo.h" +#include "GP_FnPerBpp.h" + +DEF_VLINE_FN(GP_VLine1bpp, GP_Context *, GP_Pixel, GP_PutPixel1bpp) +DEF_VLINE_FN(GP_VLine2bpp, GP_Context *, GP_Pixel, GP_PutPixel2bpp) +DEF_VLINE_FN(GP_VLine8bpp, GP_Context *, GP_Pixel, GP_PutPixel8bpp) +DEF_VLINE_FN(GP_VLine16bpp, GP_Context *, GP_Pixel, GP_PutPixel16bpp) +DEF_VLINE_FN(GP_VLine24bpp, GP_Context *, GP_Pixel, GP_PutPixel24bpp) +DEF_VLINE_FN(GP_VLine32bpp, GP_Context *, GP_Pixel, GP_PutPixel32bpp) GP_RetCode GP_VLineXYY(GP_Context *context, int x, int y0, int y1, GP_Pixel pixel) { @@ -32,51 +41,7 @@ GP_RetCode GP_VLineXYY(GP_Context *context, int x, int y0, int y1, GP_Pixel pixe if (!GP_IS_CONTEXT_VALID(context)) return GP_EBADCONTEXT; - /* handle swapped coordinates gracefully */ - if (y0 > y1) - GP_SWAP(y0, y1); - - /* check if we are not completely outside the clipping rectangle */ - if (x < (int) context->clip_w_min - || x > (int) context->clip_w_max - || y0 > (int) context->clip_h_max - || y1 < (int) context->clip_h_min) { - return GP_ESUCCESS; - } - - /* clip the row value */ - y0 = GP_MAX(y0, (int) context->clip_h_min); - y1 = GP_MIN(y1, (int) context->clip_h_max); - - /* Calculate the start address and height of the filled block */ - size_t height = 1 + y1 - y0; - uint8_t *p = (uint8_t *) GP_PIXEL_ADDRESS(context, y0, x); - - size_t i; - switch(context->bits_per_pixel) { - case 32: - for (i = 0; i < height; i++, p += context->bytes_per_row) - GP_WritePixel32bpp(p, pixel); - break; - - case 24: - for (i = 0; i < height; i++, p += context->bytes_per_row) - GP_WritePixel24bpp(p, pixel); - break; - - case 16: - for (i = 0; i < height; i++, p += context->bytes_per_row) - GP_WritePixel16bpp(p, pixel); - break; - - case 8: - for (i = 0; i < height; i++, p += context->bytes_per_row) - GP_WritePixel8bpp(p, pixel); - break; - - default: - return GP_ENOIMPL; - } + GP_FN_PER_BPP(GP_VLine, x, y0, y1, pixel); return GP_ESUCCESS; } diff --git a/doc/Makefile b/doc/Makefile index 4062098c..0ca96912 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -1,8 +1,11 @@ -all: api.html +all: api.html context.html api.html: api.txt asciidoc -a toc api.txt +context.html: context.txt + asciidoc -a context.txt + api.pdf: api.txt asciidoc -b docbook api.txt xsltproc /usr/share/sgml/docbook/xsl-ns-stylesheets/fo/docbook.xsl api.xml > api.fo diff --git a/drivers/GP_Framebuffer.c b/drivers/GP_Framebuffer.c index 0ce0ba74..a60746a8 100644 --- a/drivers/GP_Framebuffer.c +++ b/drivers/GP_Framebuffer.c @@ -94,7 +94,7 @@ GP_Framebuffer *GP_FramebufferInit(const char *path) fb->context.clip_w_max = fb->context.w - 1; fb->context.clip_h_max = fb->context.h - 1; - fb->context.bits_per_pixel = vscri.bits_per_pixel; + fb->context.bpp = vscri.bits_per_pixel; fb->context.bytes_per_row = fscri.line_length; fb->context.pixel_type = GP_PIXEL_XRGB8888; diff --git a/loaders/tests/autotest.sh b/loaders/tests/autotest.sh index e62e80fe..5ce74d1c 100755 --- a/loaders/tests/autotest.sh +++ b/loaders/tests/autotest.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash echo "Generating pbm file" ./runtest.sh PBM_test &> /dev/null diff --git a/targets/sdl/GP_SDL_Context.c b/targets/sdl/GP_SDL_Context.c index 42a16004..3689e446 100644 --- a/targets/sdl/GP_SDL_Context.c +++ b/targets/sdl/GP_SDL_Context.c @@ -115,7 +115,7 @@ inline GP_RetCode GP_SDL_ContextFromSurface( /* basic structure and size */ context->pixels = surf->pixels; - context->bits_per_pixel = 8 * surf->format->BytesPerPixel; + context->bpp = 8 * surf->format->BytesPerPixel; context->pixel_type = pixeltype; context->bytes_per_row = surf->pitch; context->w = surf->w; -- 2.11.4.GIT