2 * (c) 2011 Siegen, Germany by Nils Faerber <nils.faerber@kernelconcepts.de>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
24 #include "mw_utility.h"
25 #include "metawatch.h"
30 * The pixmap buffer has at least one byte per pixel, even for monochrome (bpp=1)
33 mw_buffer *mw_alloc_pbuffer(unsigned int res_x, unsigned int res_y, unsigned int bpp)
38 nmwbuf = (mw_buffer *) malloc(sizeof(mw_buffer));
42 nmwbuf->res_x = res_x;
43 nmwbuf->res_y = res_y;
46 pbuf_size = nmwbuf->res_x * nmwbuf->res_y * ((nmwbuf->bpp / 8) + 1);
47 nmwbuf->pbuf = malloc(pbuf_size);
52 memset(nmwbuf->pbuf, 0, pbuf_size);
57 void mw_free_pbuffer(mw_buffer *mwbuf)
67 * makes a buffer for sending to the watch from the drawing buffer, e.g.
68 * mw_send_bitmap(mw_fd, MW_SCREEN_MODE_IDLE, 96, 65, 31, bbuf, len);
70 unsigned char *mw_make_mw_buffer(mw_buffer *mwbuf, int *buflen)
72 static unsigned char wbuf[96*12];
76 memset(wbuf, 0, 96*12);
78 for (y = 0; y < mwbuf->res_y; y++) {
79 for (x = 0; x < mwbuf->res_x; x++) {
80 clr = *(unsigned char *)(mwbuf->pbuf+((y*mwbuf->res_x)+x));
82 *(unsigned char *)(wbuf+((y*12)+(x/8))) |= 1 << (x%8);
86 *buflen = mwbuf->res_y * 12;
91 void mw_dump_mw_buffer(mw_buffer *mwbuf)
96 for (y = 0; y < mwbuf->res_y; y++) {
97 for (x = 0; x < mwbuf->res_x; x++) {
98 clr = *(unsigned char *)(mwbuf->pbuf+((y*mwbuf->res_x)+x));
100 fprintf(stderr, ".");
102 fprintf(stderr, " ");
104 fprintf(stderr, "\n");
109 /* clear/fill entire buffer with color */
110 void mw_buf_clear(mw_buffer *mwbuf, mw_color clr)
116 if (clr == MW_TRANSPARENT)
119 pbuf_size = mwbuf->res_x * mwbuf->res_y * ((mwbuf->bpp / 8) + 1);
120 memset(mwbuf->pbuf, clr, pbuf_size);
123 /* draw a single pixel */
124 void mw_buf_draw_pixel(mw_buffer *mwbuf, unsigned int x, unsigned int y, mw_color clr)
128 if (clr == MW_TRANSPARENT)
131 *(unsigned char *)(mwbuf->pbuf+((y*mwbuf->res_x)+x)) = clr;
134 void mw_buf_print(mw_buffer *mwbuf, unsigned int x, unsigned int y, char *text, unsigned char fsize, mw_color fgclr, mw_color bgclr)
137 const unsigned char *data, *font_style;
138 unsigned char mask,xme,yme,offset;
140 if (text==NULL || strlen(text) == 0)
145 data = (const unsigned char *)FONT6x8;
146 font_style = (const unsigned char *)FONT6x8;
149 data = (const unsigned char *)FONT8x8F;
150 font_style = (const unsigned char *)FONT8x8F;
153 data = (const unsigned char *)FONT8x16;
154 font_style = (const unsigned char *)FONT8x16;
157 data = (const unsigned char *)FONT6x8;
158 font_style = (const unsigned char *)FONT6x8;
167 data = (font_style + offset) + (offset * (int)(*text - 32));
168 for (i=0; i < yme; i++) {
170 for (j=x; j < (x + xme); j++) {
172 if ((z < mwbuf->res_y) && (j < mwbuf->res_x)) {
174 mw_buf_draw_pixel(mwbuf, j, z, fgclr);
176 mw_buf_draw_pixel(mwbuf, j, z, bgclr);
185 } while (*text != '\0');
188 void mw_buf_draw_line_bresenham(mw_buffer *mwbuf, unsigned int xstart, unsigned int ystart, unsigned int xend, unsigned int yend, mw_color clr)
190 int x, y, t, dx, dy, incx, incy, pdx, pdy, ddx, ddy, es, el, err;
195 incx = (dx >= 0) ? 1 : -1;
196 incy = (dy >= 0) ? 1 : -1;
216 mw_buf_draw_pixel(mwbuf, x, y, clr);
218 for (t = 0; t < el; ++t) {
228 mw_buf_draw_pixel(mwbuf, x, y, clr);