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>2016-07-01 08:27:37 +0300
committerJay Sorg <jay.sorg@gmail.com>2016-07-01 08:27:37 +0300
commit6fbd8adc6a4f819c342543ab967d25742f61ede9 (patch)
treee58d0e17d6cca384612ce5314f6f51dd81c47679
parent1765def8c73f711da10ec51a5f70f0c647facb88 (diff)
painter optimize
-rw-r--r--include/painter.h1
-rw-r--r--src/painter.c133
-rw-r--r--src/painter_utils.c66
-rw-r--r--src/painter_utils.h4
4 files changed, 164 insertions, 40 deletions
diff --git a/include/painter.h b/include/painter.h
index e5e5933..66d3a60 100644
--- a/include/painter.h
+++ b/include/painter.h
@@ -47,6 +47,7 @@ struct painter_bitmap
#define PT_ERROR_NONE 0
#define PT_ERROR_OUT_OF_MEM 1
#define PT_ERROR_PARAM 2
+#define PT_ERROR_NOT_IMP 3
#define PT_PATTERN_MODE_NORMAL 0
#define PT_PATTERN_MODE_OPAQUE 1
diff --git a/src/painter.c b/src/painter.c
index ba6468e..3bb770d 100644
--- a/src/painter.c
+++ b/src/painter.c
@@ -147,50 +147,47 @@ painter_fill_rect(void *handle, struct painter_bitmap *dst,
{
int index;
int jndex;
- int x1;
- int y1;
- int x2;
- int y2;
+ int bpp;
int *dst32;
+ short *dst16;
struct painter *pt;
pt = (struct painter *) handle;
if (pt->rop == PT_ROP_S)
{
- if (dst->format == PT_FORMAT_a8r8g8b8)
+ if (painter_warp_coords(pt, &x, &y, &cx, &cy, NULL, NULL))
{
- x1 = x;
- y1 = y;
- x2 = x + cx;
- y2 = y + cy;
- if (pt->clip_valid)
+ bpp = dst->format >> 24;
+ if (bpp == 32)
{
- if (x1 < pt->clip.x1)
+ for (jndex = 0; jndex < cy; jndex++)
{
- x1 = pt->clip.x1;
- }
- if (y1 < pt->clip.y1)
- {
- y1 = pt->clip.y1;
- }
- if (x2 > pt->clip.x2)
- {
- x2 = pt->clip.x2;
- }
- if (y2 > pt->clip.y2)
- {
- y2 = pt->clip.y2;
+ dst32 = (int *) bitmap_get_ptr(dst, x, y + jndex);
+ if (dst32 != NULL)
+ {
+ for (index = 0; index < cx; index++)
+ {
+ *(dst32++) = pt->fgcolor;
+ }
+ }
}
+ return PT_ERROR_NONE;
}
- for (jndex = y1; jndex < y2; jndex++)
+ else if (bpp == 16)
{
- dst32 = (int *) bitmap_get_ptr(dst, x1, jndex);
- for (index = x1; index < x2; index++)
+ for (jndex = 0; jndex < cy; jndex++)
{
- *(dst32++) = pt->fgcolor;
+ dst16 = (short *) bitmap_get_ptr(dst, x, y + jndex);
+ if (dst16 != NULL)
+ {
+ for (index = 0; index < cx; index++)
+ {
+ *(dst16++) = pt->fgcolor;
+ }
+ }
}
+ return PT_ERROR_NONE;
}
- return PT_ERROR_NONE;
}
}
for (jndex = 0; jndex < cy; jndex++)
@@ -218,24 +215,41 @@ painter_fill_pattern(void *handle, struct painter_bitmap *dst,
struct painter *pt;
pt = (struct painter *) handle;
- for (jndex = 0; jndex < cy; jndex++)
+ if (pt->pattern_mode == PT_PATTERN_MODE_OPAQUE)
{
- for (index = 0; index < cx; index++)
+ for (jndex = 0; jndex < cy; jndex++)
{
- lx = (patx + index + pt->origin_x) % pat->width;
- ly = (paty + jndex + pt->origin_y) % pat->height;
- pixel = bitmap_get_pixel(pat, lx, ly);
- if (pixel != 0)
+ for (index = 0; index < cx; index++)
{
- painter_set_pixel(pt, dst, x + index, y + jndex,
- pt->fgcolor, dst->format);
+ lx = (patx + index + pt->origin_x) % pat->width;
+ ly = (paty + jndex + pt->origin_y) % pat->height;
+ pixel = bitmap_get_pixel(pat, lx, ly);
+ if (pixel != 0)
+ {
+ painter_set_pixel(pt, dst, x + index, y + jndex,
+ pt->fgcolor, dst->format);
+ }
+ else
+ {
+ painter_set_pixel(pt, dst, x + index, y + jndex,
+ pt->bgcolor, dst->format);
+ }
}
- else
+ }
+ }
+ else
+ {
+ for (jndex = 0; jndex < cy; jndex++)
+ {
+ for (index = 0; index < cx; index++)
{
- if (pt->pattern_mode == PT_PATTERN_MODE_OPAQUE)
+ lx = (patx + index + pt->origin_x) % pat->width;
+ ly = (paty + jndex + pt->origin_y) % pat->height;
+ pixel = bitmap_get_pixel(pat, lx, ly);
+ if (pixel != 0)
{
painter_set_pixel(pt, dst, x + index, y + jndex,
- pt->bgcolor, dst->format);
+ pt->fgcolor, dst->format);
}
}
}
@@ -252,9 +266,48 @@ painter_copy(void *handle, struct painter_bitmap *dst,
int index;
int jndex;
int pixel;
+ int bpp;
struct painter *pt;
+ void *src_ptr;
+ void *dst_ptr;
pt = (struct painter *) handle;
+ if (pt->rop == PT_ROP_S)
+ {
+ if (src->format == dst->format)
+ {
+ bpp = src->format >> 24;
+ if (painter_warp_coords(pt, &x, &y, &cx, &cy, &srcx, &srcy))
+ {
+ if ((srcy < y) || ((srcy == y) && (srcx < x))) /* straight right or down */
+ {
+ for (jndex = cy - 1; jndex >= 0; jndex--)
+ {
+ dst_ptr = bitmap_get_ptr(dst, x, y + jndex);
+ src_ptr = bitmap_get_ptr(src, srcx, srcy + jndex);
+ if ((src_ptr != NULL) && (dst_ptr != NULL))
+ {
+ memmove(dst_ptr, src_ptr, cx * (bpp / 8));
+ }
+ }
+ }
+ else
+ {
+ for (jndex = 0; jndex < cy; jndex++)
+ {
+ dst_ptr = bitmap_get_ptr(dst, x, y + jndex);
+ src_ptr = bitmap_get_ptr(src, srcx, srcy + jndex);
+ if ((src_ptr != NULL) && (dst_ptr != NULL))
+ {
+ memcpy(dst_ptr, src_ptr, cx * (bpp / 8));
+ }
+ }
+ }
+ }
+ return PT_ERROR_NONE;
+ }
+ }
+
if ((srcy < y) || ((srcy == y) && (srcx < x))) /* straight right or down */
{
for (jndex = cy - 1; jndex >= 0; jndex--)
diff --git a/src/painter_utils.c b/src/painter_utils.c
index fee30e7..55abfcd 100644
--- a/src/painter_utils.c
+++ b/src/painter_utils.c
@@ -254,3 +254,69 @@ painter_set_pixel(struct painter *painter, struct painter_bitmap *bitmap,
return 0;
}
+/*****************************************************************************/
+/* return true is the is something to draw */
+int
+painter_warp_coords(struct painter *painter,
+ int *x, int *y, int *cx, int *cy,
+ int *srcx, int *srcy)
+{
+ int dx;
+ int dy;
+ int lx;
+ int ly;
+ int lcx;
+ int lcy;
+
+ lx = *x;
+ ly = *y;
+ lcx = *cx;
+ lcy = *cy;
+ dx = 0;
+ dy = 0;
+ if (painter->clip_valid)
+ {
+ if (painter->clip.x1 > lx)
+ {
+ dx = painter->clip.x1 - lx;
+ }
+ if (painter->clip.y1 > ly)
+ {
+ dy = painter->clip.y1 - ly;
+ }
+ if (lx + lcx > painter->clip.x2)
+ {
+ lcx = (lcx - ((lx + lcx) - painter->clip.x2));
+ }
+ if (*y + lcy > painter->clip.y2)
+ {
+ lcy = (lcy - ((ly + lcy) - painter->clip.y2));
+ }
+ }
+ lcx = lcx - dx;
+ lcy = lcy - dy;
+ if (lcx <= 0)
+ {
+ return 0;
+ }
+ if (lcy <= 0)
+ {
+ return 0;
+ }
+ lx = lx + dx;
+ ly = ly + dy;
+ if (srcx != 0)
+ {
+ *srcx = *srcx + dx;
+ }
+ if (srcy != 0)
+ {
+ *srcy = *srcy + dy;
+ }
+ *x = lx;
+ *y = ly;
+ *cx = lcx;
+ *cy = lcy;
+ return 1;
+}
+
diff --git a/src/painter_utils.h b/src/painter_utils.h
index 6ef0bfb..2feea5f 100644
--- a/src/painter_utils.h
+++ b/src/painter_utils.h
@@ -120,6 +120,10 @@ painter_get_pixel(struct painter *painter, struct painter_bitmap *bitmap,
int
painter_set_pixel(struct painter *painter, struct painter_bitmap *dst,
int x, int y, int pixel, int pixel_format);
+int
+painter_warp_coords(struct painter *painter,
+ int *x, int *y, int *cx, int *cy,
+ int *srcx, int *srcy);
char *
bitmap_get_ptr(struct painter_bitmap *bitmap, int x, int y);
int