90 lines
1.7 KiB
C
90 lines
1.7 KiB
C
/*
|
|
* (c) 2011 Siegen, Germany by Nils Faerber <nils.faerber@kernelconcepts.de>
|
|
*
|
|
* license LGPL
|
|
*/
|
|
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <stdio.h>
|
|
|
|
#include "mw_utility.h"
|
|
#include "metawatch.h"
|
|
|
|
/*
|
|
* The pixmap buffer has at least one byte per pixel, even for monochrome (bpp=1)
|
|
* bitmaps
|
|
*/
|
|
mw_buffer *mw_alloc_pbuffer(unsigned int res_x, unsigned int res_y, unsigned int bpp)
|
|
{
|
|
mw_buffer *nmwbuf;
|
|
int pbuf_size;
|
|
|
|
nmwbuf = (mw_buffer *) malloc(sizeof(mw_buffer));
|
|
if (!nmwbuf)
|
|
return NULL;
|
|
|
|
nmwbuf->res_x = res_x;
|
|
nmwbuf->res_y = res_y;
|
|
nmwbuf->bpp = bpp;
|
|
|
|
pbuf_size = nmwbuf->res_x * nmwbuf->res_y * ((nmwbuf->bpp / 8) + 1);
|
|
nmwbuf->pbuf = malloc(pbuf_size);
|
|
if (!nmwbuf->pbuf) {
|
|
free(nmwbuf);
|
|
return NULL;
|
|
} else {
|
|
memset(nmwbuf->pbuf, 0, pbuf_size);
|
|
return nmwbuf;
|
|
}
|
|
}
|
|
|
|
void mw_free_pbuffer(mw_buffer *mwbuf)
|
|
{
|
|
if (!mwbuf)
|
|
return;
|
|
|
|
free(mwbuf->pbuf);
|
|
free(mwbuf);
|
|
}
|
|
|
|
void mw_dump_mw_buffer(mw_buffer *mwbuf)
|
|
{
|
|
int x, y;
|
|
unsigned char clr;
|
|
|
|
for (y = 0; y < mwbuf->res_y; y++) {
|
|
for (x = 0; x < mwbuf->res_x; x++) {
|
|
clr = *(unsigned char *)(mwbuf->pbuf+((y*mwbuf->res_x)+x));
|
|
if (clr)
|
|
fprintf(stderr, ".");
|
|
else
|
|
fprintf(stderr, " ");
|
|
};
|
|
fprintf(stderr, "\n");
|
|
};
|
|
}
|
|
|
|
|
|
/* clear/fill entire buffer with color */
|
|
void mw_buf_clear(mw_buffer *mwbuf, mw_color clr)
|
|
{
|
|
int pbuf_size;
|
|
|
|
if (!mwbuf)
|
|
return;
|
|
|
|
pbuf_size = mwbuf->res_x * mwbuf->res_y * ((mwbuf->bpp / 8) + 1);
|
|
memset(mwbuf->pbuf, clr, pbuf_size);
|
|
}
|
|
|
|
/* draw a single pixel */
|
|
void mw_buf_draw_pixel(mw_buffer *mwbuf, unsigned int x, unsigned int y, mw_color clr)
|
|
{
|
|
if (!mwbuf)
|
|
return;
|
|
|
|
*(unsigned char *)(mwbuf->pbuf+((y*mwbuf->res_x)+x)) = clr;
|
|
}
|
|
|
|
|