Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/neutrinolabs/libpainter.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJay Sorg <jay.sorg@gmail.com>2015-06-12 11:25:46 +0300
committerJay Sorg <jay.sorg@gmail.com>2015-06-12 11:25:46 +0300
commitde4deb34003317cb697ef43c8faceffce8be91c6 (patch)
tree9239d2c3dfda070a01d957cbefe5c196e92f179c
parente840ccb85cb3036cd26ea27b8323386294ac9684 (diff)
early work
-rw-r--r--include/painter.h2
-rw-r--r--src/painter.c25
-rw-r--r--src/painter_utils.c129
-rw-r--r--src/painter_utils.h65
4 files changed, 198 insertions, 23 deletions
diff --git a/include/painter.h b/include/painter.h
index 301b87c..8cdf32a 100644
--- a/include/painter.h
+++ b/include/painter.h
@@ -16,7 +16,7 @@
* limitations under the License.
*/
-#ifndef __PAINTER_H
+#if !defined(__PAINTER_H)
#define __PAINTER_H
#define PT_FORMAT_a8b8g8r8 \
diff --git a/src/painter.c b/src/painter.c
index 88a698d..1a82144 100644
--- a/src/painter.c
+++ b/src/painter.c
@@ -1,5 +1,5 @@
/**
- * painter main header
+ * painter main
*
* Copyright 2015 Jay Sorg <jay.sorg@gmail.com>
*
@@ -21,26 +21,7 @@
#include <string.h>
#include "painter.h"
-
-struct painter_rect
-{
- short x1;
- short y1;
- short x2;
- short y2;
-};
-
-struct painter
-{
- int rop;
- int fgcolor;
- int bgcolor;
- int fill_mode;
- int clip_valid;
- struct painter_rect clip;
- int origin_x;
- int origin_y;
-};
+#include "painter_utils.h"
/*****************************************************************************/
int
@@ -60,7 +41,7 @@ painter_create(void **handle)
memset(*handle, 0, sizeof(struct painter));
pt = (struct painter *) *handle;
- pt->rop = PT_ROP_COPY;
+ pt->rop = PT_ROP_S;
return PT_ERROR_NONE;
}
diff --git a/src/painter_utils.c b/src/painter_utils.c
new file mode 100644
index 0000000..2893cda
--- /dev/null
+++ b/src/painter_utils.c
@@ -0,0 +1,129 @@
+/**
+ * painter utils
+ *
+ * Copyright 2015 Jay Sorg <jay.sorg@gmail.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "painter.h"
+#include "painter_utils.h"
+
+/*****************************************************************************/
+/* do a raster op */
+int
+do_rop(int rop, int src, int dst)
+{
+ switch (rop)
+ {
+ case PT_ROP_0: return 0;
+ case PT_ROP_DSon: return ~(src | dst);
+ case PT_ROP_DSna: return (~src) & dst;
+ case PT_ROP_Sn: return ~src;
+ case PT_ROP_SDna: return src & (~dst);
+ case PT_ROP_Dn: return ~(dst);
+ case PT_ROP_DSx: return src ^ dst;
+ case PT_ROP_DSan: return ~(src & dst);
+ case PT_ROP_DSa: return src & dst;
+ case PT_ROP_DSxn: return ~(src) ^ dst;
+ case PT_ROP_D: return dst;
+ case PT_ROP_DSno: return (~src) | dst;
+ case PT_ROP_S: return src;
+ case PT_ROP_SDno: return src | (~dst);
+ case PT_ROP_DSo: return src | dst;
+ case PT_ROP_1: return ~0;
+ }
+ return dst;
+}
+
+/*****************************************************************************/
+char *
+bitmap_get_ptr(struct painter_bitmap *bitmap, int x, int y)
+{
+ char *p;
+ int Bpp;
+
+ if ((x >= 0) && (x < bitmap->width) &&
+ (y >= 0) && (y < bitmap->height))
+ {
+ Bpp = ((bitmap->format >> 24) + 7) / 8;
+ p = bitmap->data + (y * bitmap->stride_bytes) + (x * Bpp);
+ return p;
+ }
+ else
+ {
+ return NULL;
+ }
+}
+
+/*****************************************************************************/
+int
+pixel_convert(int pixel, int src_format, int dst_format, int *palette)
+{
+ int a;
+ int r;
+ int g;
+ int b;
+ int rv;
+
+ if (src_format == dst_format)
+ {
+ return pixel;
+ }
+ switch (src_format)
+ {
+ case PT_FORMAT_a1r5g5b5:
+ SPLIT_a1r5g5b5(pixel, a, r, g, b);
+ break;
+ case PT_FORMAT_r5g6b5:
+ SPLIT_r5g6b5(pixel, a, r, g, b);
+ break;
+ }
+ rv = 0;
+ switch (dst_format)
+ {
+ case PT_FORMAT_a8r8g8b8:
+ rv = (a << 24) | (r << 16) | (g << 8) | b;
+ break;
+ }
+ return rv;
+}
+
+/*****************************************************************************/
+int
+painter_set_pixel(struct painter *painter, struct painter_bitmap *dst,
+ int x, int y, int pixel, int pixel_format)
+{
+ if (painter->clip_valid == 0 ||
+ (x >= painter->clip.x1 && x < painter->clip.x2 &&
+ y >= painter->clip.y1 && y < painter->clip.y2))
+ {
+ if ((x >= 0) && (x < dst->width) &&
+ (y >= 0) && (y < dst->height))
+ {
+ pixel = pixel_convert(pixel, pixel_format, dst->format,
+ painter->palete);
+ if (rop != PT_ROP_S)
+ {
+ pixel = do_rop(painter->rop, pixel,
+ bitmap_get_pixel(dst, x, y));
+ }
+ bitmap_set_pixel(dst, x, y, pixel);
+ }
+ }
+}
+
diff --git a/src/painter_utils.h b/src/painter_utils.h
new file mode 100644
index 0000000..27961cf
--- /dev/null
+++ b/src/painter_utils.h
@@ -0,0 +1,65 @@
+/**
+ * painter utils header
+ *
+ * Copyright 2015 Jay Sorg <jay.sorg@gmail.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#if !defined(__PAINTER_UTILS_H)
+#define __PAINTER_UTILS_H
+
+#define SPLIT_a1r5g5b5(c, a, r, g, b) \
+do { \
+ a = (c & 0x8000) ? 0xff : 0; \
+ r = ((c >> 7) & 0xf8) | ((c >> 12) & 0x7); \
+ g = ((c >> 2) & 0xf8) | ((c >> 8) & 0x7); \
+ b = ((c << 3) & 0xf8) | ((c >> 2) & 0x7); \
+} while (0)
+
+#define SPLIT_r5g6b5(c, a, r, g, b) \
+do { \
+ a = 0xff; \
+ r = ((c >> 8) & 0xf8) | ((c >> 13) & 0x7); \
+ g = ((c >> 3) & 0xfc) | ((c >> 9) & 0x3); \
+ b = ((c << 3) & 0xf8) | ((c >> 2) & 0x7); \
+} while (0)
+
+struct painter_rect
+{
+ short x1;
+ short y1;
+ short x2;
+ short y2;
+};
+
+struct painter
+{
+ int rop;
+ int fgcolor;
+ int bgcolor;
+ int fill_mode;
+ int clip_valid;
+ struct painter_rect clip;
+ int origin_x;
+ int origin_y;
+ int palette[256];
+};
+
+int
+painter_rop(int rop, int src, int dst);
+int
+painter_set_pixel(struct painter *painter, struct painter_bitmap *dst,
+ int x, int y, int pixel);
+
+#endif