librui: Make color handling component-order independent 06/149606/5
authorKarol Lewandowski <k.lewandowsk@samsung.com>
Fri, 15 Sep 2017 10:50:13 +0000 (12:50 +0200)
committerŁukasz Stelmach <l.stelmach@samsung.com>
Thu, 21 Sep 2017 08:08:55 +0000 (10:08 +0200)
Change-Id: I68e4aff7d7bb358d2db176515d510a87fe93b007
Signed-off-by: Łukasz Stelmach <l.stelmach@samsung.com>
[ Applied Tizen Coding style ]
Signed-off-by: Karol Lewandowski <k.lewandowsk@samsung.com>
src/librui/graphics.c
src/librui/graphics.h
src/system-recovery/recovery-rui-skin.h

index 0ff930f..03f5605 100644 (file)
@@ -21,6 +21,7 @@
 #include <fcntl.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <stdint.h>
 #include <string.h>
 #include <unistd.h>
 #include <stdbool.h>
@@ -34,6 +35,8 @@
 #include "rui-image.h"
 #include "font-10x18.h"
 
+#include "config.h"
+
 typedef struct {
        gr_surface      texture;
        int             cwidth;
@@ -69,7 +72,8 @@ void gr_set_color(color c)
 void gr_draw_rectangle(int x, int y, int width, int height)
 {
        int i, j;
-       unsigned char *px, *dst_p, *first_line;
+       unsigned char *dst_p, *first_line;
+       color *px;
 
        if (outside(x, y) || outside(x + width - 1, y + height - 1))
                return;
@@ -77,12 +81,8 @@ void gr_draw_rectangle(int x, int y, int width, int height)
        dst_p = gr_draw->data + y * gr_draw->row_bytes +
                x * gr_draw->pixel_bytes;
 
-       for (i = 0, px = dst_p; i < width; i++) {
-               *px++ = gr_current_color.r;
-               *px++ = gr_current_color.g;
-               *px++ = gr_current_color.b;
-               px++; /* Alpha is not used on framebuffer */
-       }
+       for (i = 0, px = (color *)dst_p; i < width; i++)
+               *px++ = gr_current_color;
 
        first_line = dst_p;
        dst_p += gr_draw->row_bytes;
@@ -99,15 +99,12 @@ void gr_clear(void)
 void gr_fill_alpha(gr_surface gr)
 {
        int i, j;
-       unsigned char *px, *dst_p, *first_line;
+       unsigned char *dst_p, *first_line;
+       color *px;
 
        dst_p = gr->data;
-       for (i = 0, px = dst_p; i < gr->width; i++) {
-               *px++ = 0;
-               *px++ = 0;
-               *px++ = 0;
-               *px++ = 255;
-       }
+       for (i = 0, px = (color *)dst_p; i < gr->width; i++)
+               *px++ = BLACK;
 
        first_line = dst_p;
        dst_p += gr->row_bytes;
@@ -151,25 +148,20 @@ static void gr_blend_rgba(gr_surface source, int w, int h, unsigned char *src_p,
        int i, j;
 
        for (j = 0; j < h; j++) {
-               unsigned char *sx = src_p;
-               unsigned char *px = dst_p;
+               color *sx = (color *)src_p;
+               color *px = (color *)dst_p;
 
                for (i = 0; i < w; i++) {
-                       unsigned char r = *sx++, g = *sx++, b = *sx++,
-                                     a = *sx++;
+                       unsigned char r = sx->r, g = sx->g, b = sx->b,
+                               a = sx->a;
 
                        if (a == 255) {
-                               *px++ = r;
-                               *px++ = g;
-                               *px++ = b;
-                               px++; /* Alpha is not used on framebuffer */
+                               *px++ = *sx;
                        } else {
-                               *px = (*px * (255 - a) + r * a) / 255;
-                               ++px;
-                               *px = (*px * (255 - a) + g * a) / 255;
-                               ++px;
-                               *px = (*px * (255 - a) + b * a) / 255;
-                               px += 2;
+                               px->r = (px->r * (255 - a) + r * a) / 255;
+                               px->g = (px->g * (255 - a) + g * a) / 255;
+                               px->b = (px->b * (255 - a) + b * a) / 255;
+                               px->a = 255;
                        }
                }
 
@@ -185,27 +177,25 @@ static void gr_blend_rgb(gr_surface source, int w, int h, unsigned char *src_p,
        int i, j;
 
        for (j = 0; j < h; j++) {
-               unsigned char *sx = src_p;
-               unsigned char *px = dst_p;
+               color *sx = (color *)src_p;
+               color *px = (color *)dst_p;
 
                for (i = 0; i < w; i++) {
-                       unsigned char r = *sx++, g = *sx++, b = *sx++;
+                       unsigned char r = sx->r, g = sx->g, b = sx->b;
 
                        if (gr_current_color.a == 255) {
-                               *px++ = r;
-                               *px++ = g;
-                               *px++ = b;
-                               px++; /* Alpha is not used on framebuffer */
+                               *px = *sx;
+                               px->a = 255;
+                               px++;
                        } else {
-                               *px = (*px * (255 - gr_current_color.a) +
-                                               r * gr_current_color.a) / 255;
-                               ++px;
-                               *px = (*px * (255 - gr_current_color.a) +
-                                               g * gr_current_color.a) / 255;
-                               ++px;
-                               *px = (*px * (255 - gr_current_color.a) +
-                                               b * gr_current_color.a) / 255;
-                               px += 2;
+                               px->r = (px->r * (255 - gr_current_color.a) +
+                                        r * gr_current_color.a) / 255;
+                               px->g = (px->g * (255 - gr_current_color.a) +
+                                        g * gr_current_color.a) / 255;
+                               px->b = (px->b * (255 - gr_current_color.a) +
+                                        b * gr_current_color.a) / 255;
+                               px->a = 255;
+                               px++;
                        }
                }
 
@@ -222,23 +212,23 @@ static void gr_blend_ga(gr_surface source, int w, int h, unsigned char *src_p,
 
        for (j = 0; j < h; j++) {
                unsigned char *sx = src_p;
-               unsigned char *px = dst_p;
+               color *px = (color *)dst_p;
 
                for (i = 0; i < w; i++) {
                        unsigned char gr = *sx++, a = *sx++;
 
                        if (a == 255) {
-                               *px++ = gr;
-                               *px++ = gr;
-                               *px++ = gr;
-                               px++; /* Alpha is not used on framebuffer */
+                               px->r = gr;
+                               px->g = gr;
+                               px->b = gr;
+                               px->a = 255;
+                               px++;
                        } else {
-                               *px = (*px * (255 - a) + gr * a) / 255;
+                               px->r = (px->r * (255 - a) + gr * a) / 255;
+                               px->g = (px->g * (255 - a) + gr * a) / 255;
+                               px->b = (px->b * (255 - a) + gr * a) / 255;
+                               px->a = 255;
                                ++px;
-                               *px = (*px * (255 - a) + gr * a) / 255;
-                               ++px;
-                               *px = (*px * (255 - a) + gr * a) / 255;
-                               px += 2;
                        }
                }
 
@@ -256,7 +246,7 @@ static void gr_blend_g(gr_surface source, int w, int h, unsigned char *src_p,
 
        for (j = 0; j < h; j++) {
                unsigned char *sx = src_p;
-               unsigned char *px = dst_p;
+               color *px = (color *)dst_p;
 
                for (i = 0; i < w; i++) {
                        unsigned char a = *sx++;
@@ -265,20 +255,17 @@ static void gr_blend_g(gr_surface source, int w, int h, unsigned char *src_p,
                                a = ((int)a * gr_current_color.a) / 255;
 
                        if (a == 255) {
-                               *px++ = gr_current_color.r;
-                               *px++ = gr_current_color.g;
-                               *px++ = gr_current_color.b;
-                               px++; /* Alpha is not used on framebuffer */
+                               *px = gr_current_color;
+                               px++;
                        } else {
-                               *px = (*px * (255 - a) +
-                                               gr_current_color.r * a) / 255;
-                               ++px;
-                               *px = (*px * (255 - a) +
-                                               gr_current_color.g * a) / 255;
+                               px->r = (px->r * (255 - a) +
+                                        gr_current_color.r * a) / 255;
+                               px->g = (px->g * (255 - a) +
+                                        gr_current_color.g * a) / 255;
+                               px->b = (px->b * (255 - a) +
+                                        gr_current_color.b * a) / 255;
+                               px->a = 255;
                                ++px;
-                               *px = (*px * (255 - a) +
-                                               gr_current_color.b * a) / 255;
-                               px += 2;
                        }
                }
 
index e5ec042..a768462 100644 (file)
@@ -23,6 +23,8 @@
 
 #include <sys/types.h>
 
+#include "config.h"
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -52,20 +54,29 @@ typedef struct gr_backend {
        void *data; /* Private data for graphics backend */
 } gr_backend;
 
+#ifdef HAVE_TDM /* BGRA */
 typedef struct {
-       unsigned char r, g, b, a;
+       unsigned char b, g, r, a;
 } color;
 
-#define BLACK   (color) {   0,   0,   0, 255 }
-#define RED     (color) { 255,   0,   0, 255 }
-#define GREEN   (color) {   0, 255,   0, 255 }
-#define YELLOW  (color) { 255, 255,   0, 255 }
-#define BLUE    (color) {   0,   0, 255, 255 }
-#define MAGENTA (color) { 255,   0, 255, 255 }
-#define CYAN    (color) {   0, 255, 255, 255 }
-#define WHITE   (color) { 255, 255, 255, 255 }
+gr_backend *open_tdm(void);
+
+#else /* RGBA */
+typedef struct {
+       unsigned char r, g, b, a;
+} color;
 
 gr_backend *open_fbdev(void);
+#endif
+
+#define BLACK   (color) { .r =   0, .g =   0, .b =   0, .a = 255 }
+#define RED     (color) { .r = 255, .g =   0, .b =   0, .a = 255 }
+#define GREEN   (color) { .r =   0, .g = 255, .b =   0, .a = 255 }
+#define YELLOW  (color) { .r = 255, .g = 255, .b =   0, .a = 255 }
+#define BLUE    (color) { .r =   0, .g =   0, .b = 255, .a = 255 }
+#define MAGENTA (color) { .r = 255, .g =   0, .b = 255, .a = 255 }
+#define CYAN    (color) { .r =   0, .g = 255, .b = 255, .a = 255 }
+#define WHITE   (color) { .r = 255, .g = 255, .b = 255, .a = 255 }
 
 bool gr_init(void);
 void gr_exit(void);
index cb927c1..fe2df56 100644 (file)
@@ -21,7 +21,7 @@
 #include "graphics.h"
 
 #define RUI_COLOR_BACKGROUND                    BLACK
-#define RUI_COLOR_TITLE                         (color) {  27, 199, 204, 255 }
+#define RUI_COLOR_TITLE                         (color) { .r = 27, .g = 199, .b = 204, .a = 255 }
 #define RUI_COLOR_RULER                         RUI_COLOR_TITLE
 
 #define RUI_COLOR_MENU_BG_SELECTED              RUI_COLOR_TITLE