@@ -71,6 +71,7 @@ struct rawfb_context {
71
71
struct rawfb_image font_tex ;
72
72
struct nk_font_atlas atlas ;
73
73
};
74
+ typedef unsigned int rawfb_color ;
74
75
75
76
#ifndef MIN
76
77
#define MIN (a ,b ) ((a) < (b) ? (a) : (b))
@@ -79,37 +80,36 @@ struct rawfb_context {
79
80
#define MAX (a ,b ) ((a) < (b) ? (b) : (a))
80
81
#endif
81
82
82
- static unsigned int
83
- nk_rawfb_color2int (const struct nk_color c , const struct rawfb_pl pl )
83
+ static rawfb_color
84
+ nk_rawfb_color2int (const struct nk_color c , const struct rawfb_pl * pl )
84
85
{
85
86
unsigned int res = 0 ;
86
87
87
- res |= (c .r >> pl . rloss ) << pl . rshift ;
88
- res |= (c .g >> pl . gloss ) << pl . gshift ;
89
- res |= (c .b >> pl . bloss ) << pl . bshift ;
90
- res |= (c .a >> pl . aloss ) << pl . ashift ;
88
+ res |= (c .r >> pl -> rloss ) << pl -> rshift ;
89
+ res |= (c .g >> pl -> gloss ) << pl -> gshift ;
90
+ res |= (c .b >> pl -> bloss ) << pl -> bshift ;
91
+ res |= (c .a >> pl -> aloss ) << pl -> ashift ;
91
92
92
93
return (res );
93
94
}
94
95
95
96
static struct nk_color
96
- nk_rawfb_int2color (const unsigned int i , const struct rawfb_pl pl )
97
+ nk_rawfb_int2color (const rawfb_color i , const struct rawfb_pl * pl )
97
98
{
98
99
struct nk_color col = {0 ,0 ,0 ,0 };
99
100
100
- col .r = (pl . rloss == 8 ) ? 0xff : ((i >> pl . rshift ) << pl . rloss ) & 0xff ;
101
- col .g = (pl . gloss == 8 ) ? 0xff : ((i >> pl . gshift ) << pl . gloss ) & 0xff ;
102
- col .b = (pl . bloss == 8 ) ? 0xff : ((i >> pl . bshift ) << pl . bloss ) & 0xff ;
103
- col .a = (pl . aloss == 8 ) ? 0xff : ((i >> pl . ashift ) << pl . aloss ) & 0xff ;
101
+ col .r = (pl -> rloss == 8 ) ? 0xff : ((i >> pl -> rshift ) << pl -> rloss ) & 0xff ;
102
+ col .g = (pl -> gloss == 8 ) ? 0xff : ((i >> pl -> gshift ) << pl -> gloss ) & 0xff ;
103
+ col .b = (pl -> bloss == 8 ) ? 0xff : ((i >> pl -> bshift ) << pl -> bloss ) & 0xff ;
104
+ col .a = (pl -> aloss == 8 ) ? 0xff : ((i >> pl -> ashift ) << pl -> aloss ) & 0xff ;
104
105
105
106
return col ;
106
107
}
107
108
108
109
static void
109
110
nk_rawfb_ctx_setpixel (const struct rawfb_context * rawfb ,
110
- const short x0 , const short y0 , const struct nk_color col )
111
+ const short x0 , const short y0 , const rawfb_color col )
111
112
{
112
- unsigned int c = nk_rawfb_color2int (col , rawfb -> fb .pl );
113
113
unsigned char * pixels = rawfb -> fb .pixels ;
114
114
115
115
pixels += y0 * rawfb -> fb .pitch ;
@@ -118,18 +118,18 @@ nk_rawfb_ctx_setpixel(const struct rawfb_context *rawfb,
118
118
x0 >= rawfb -> scissors .x && x0 < rawfb -> scissors .w ) {
119
119
120
120
if (rawfb -> fb .pl .bytesPerPixel == sizeof (unsigned int )) {
121
- * ((unsigned int * )pixels + x0 ) = c ;
121
+ * ((unsigned int * )pixels + x0 ) = col ;
122
122
} else if (rawfb -> fb .pl .bytesPerPixel == sizeof (unsigned short )) {
123
- * ((unsigned short * )pixels + x0 ) = c ;
123
+ * ((unsigned short * )pixels + x0 ) = col ;
124
124
} else {
125
- * ((unsigned char * )pixels + x0 ) = c ;
125
+ * ((unsigned char * )pixels + x0 ) = col ;
126
126
}
127
127
}
128
128
}
129
129
130
130
static void
131
131
nk_rawfb_line_horizontal (const struct rawfb_context * rawfb ,
132
- const short x0 , const short y , const short x1 , const struct nk_color col )
132
+ const short x0 , const short y , const short x1 , const rawfb_color col )
133
133
{
134
134
/* This function is called the most. Try to optimize it a bit...
135
135
* It does not check for scissors or image borders.
@@ -144,13 +144,13 @@ nk_rawfb_line_horizontal(const struct rawfb_context *rawfb,
144
144
n = (x1 - x0 ) * bpp ;
145
145
if (bpp == sizeof (unsigned int )) {
146
146
for (i = 0 ; i < sizeof (c ) / bpp ; i ++ )
147
- ((unsigned int * )c )[i ] = nk_rawfb_color2int ( col , rawfb -> fb . pl ) ;
147
+ ((unsigned int * )c )[i ] = col ;
148
148
} else if (bpp == sizeof (unsigned short )) {
149
149
for (i = 0 ; i < sizeof (c ) / bpp ; i ++ )
150
- ((unsigned short * )c )[i ] = nk_rawfb_color2int ( col , rawfb -> fb . pl ) ;
150
+ ((unsigned short * )c )[i ] = col ;
151
151
} else {
152
152
for (i = 0 ; i < sizeof (c ) / bpp ; i ++ )
153
- ((unsigned char * )c )[i ] = nk_rawfb_color2int ( col , rawfb -> fb . pl ) ;
153
+ ((unsigned char * )c )[i ] = col ;
154
154
}
155
155
156
156
while (n > sizeof (c )) {
@@ -164,7 +164,7 @@ static void
164
164
nk_rawfb_img_setpixel (const struct rawfb_image * img ,
165
165
const int x0 , const int y0 , const struct nk_color col )
166
166
{
167
- unsigned int c = nk_rawfb_color2int (col , img -> pl );
167
+ unsigned int c = nk_rawfb_color2int (col , & img -> pl );
168
168
unsigned char * ptr ;
169
169
NK_ASSERT (img );
170
170
if (y0 < img -> h && y0 >= 0 && x0 >= 0 && x0 < img -> w ) {
@@ -192,13 +192,13 @@ nk_rawfb_img_getpixel(const struct rawfb_image *img, const int x0, const int y0)
192
192
193
193
if (img -> pl .bytesPerPixel == sizeof (unsigned int )) {
194
194
pixel = ((unsigned int * )ptr )[x0 ];
195
- col = nk_rawfb_int2color (pixel , img -> pl );
195
+ col = nk_rawfb_int2color (pixel , & img -> pl );
196
196
} else if (img -> pl .bytesPerPixel == sizeof (unsigned short )) {
197
197
pixel = ((unsigned short * )ptr )[x0 ];
198
- col = nk_rawfb_int2color (pixel , img -> pl );
198
+ col = nk_rawfb_int2color (pixel , & img -> pl );
199
199
} else {
200
200
pixel = ((unsigned char * )ptr )[x0 ];
201
- col = nk_rawfb_int2color (pixel , img -> pl );
201
+ col = nk_rawfb_int2color (pixel , & img -> pl );
202
202
}
203
203
} return col ;
204
204
}
@@ -235,7 +235,7 @@ nk_rawfb_scissor(struct rawfb_context *rawfb,
235
235
static void
236
236
nk_rawfb_stroke_line (const struct rawfb_context * rawfb ,
237
237
short x0 , short y0 , short x1 , short y1 ,
238
- const unsigned int line_thickness , const struct nk_color col )
238
+ const unsigned int line_thickness , const rawfb_color col )
239
239
{
240
240
short tmp ;
241
241
int dy , dx , stepx , stepy ;
@@ -304,7 +304,7 @@ nk_rawfb_stroke_line(const struct rawfb_context *rawfb,
304
304
305
305
static void
306
306
nk_rawfb_fill_polygon (const struct rawfb_context * rawfb ,
307
- const struct nk_vec2i * pnts , int count , const struct nk_color col )
307
+ const struct nk_vec2i * pnts , int count , const rawfb_color col )
308
308
{
309
309
int i = 0 ;
310
310
#define MAX_POINTS 64
@@ -368,7 +368,7 @@ nk_rawfb_fill_polygon(const struct rawfb_context *rawfb,
368
368
static void
369
369
nk_rawfb_stroke_arc (const struct rawfb_context * rawfb ,
370
370
short x0 , short y0 , short w , short h , const short s ,
371
- const short line_thickness , const struct nk_color col )
371
+ const short line_thickness , const rawfb_color col )
372
372
{
373
373
/* Bresenham's ellipses - modified to draw one quarter */
374
374
const int a2 = (w * w ) / 4 ;
@@ -421,7 +421,7 @@ nk_rawfb_stroke_arc(const struct rawfb_context *rawfb,
421
421
422
422
static void
423
423
nk_rawfb_fill_arc (const struct rawfb_context * rawfb , short x0 , short y0 ,
424
- short w , short h , const short s , const struct nk_color col )
424
+ short w , short h , const short s , const rawfb_color col )
425
425
{
426
426
/* Bresenham's ellipses - modified to fill one quarter */
427
427
const int a2 = (w * w ) / 4 ;
@@ -486,7 +486,7 @@ nk_rawfb_fill_arc(const struct rawfb_context *rawfb, short x0, short y0,
486
486
static void
487
487
nk_rawfb_stroke_rect (const struct rawfb_context * rawfb ,
488
488
const short x , const short y , const short w , const short h ,
489
- const short r , const short line_thickness , const struct nk_color col )
489
+ const short r , const short line_thickness , const rawfb_color col )
490
490
{
491
491
if (r == 0 ) {
492
492
nk_rawfb_stroke_line (rawfb , x , y , x + w , y , line_thickness , col );
@@ -518,7 +518,7 @@ nk_rawfb_stroke_rect(const struct rawfb_context *rawfb,
518
518
static void
519
519
nk_rawfb_fill_rect (const struct rawfb_context * rawfb ,
520
520
const short x , const short y , const short w , const short h ,
521
- const short r , const struct nk_color col )
521
+ const short r , const rawfb_color col )
522
522
{
523
523
int i ;
524
524
if (r == 0 ) {
@@ -650,7 +650,7 @@ nk_rawfb_draw_rect_multi_color(const struct rawfb_context *rawfb,
650
650
static void
651
651
nk_rawfb_fill_triangle (const struct rawfb_context * rawfb ,
652
652
const short x0 , const short y0 , const short x1 , const short y1 ,
653
- const short x2 , const short y2 , const struct nk_color col )
653
+ const short x2 , const short y2 , const rawfb_color col )
654
654
{
655
655
struct nk_vec2i pnts [3 ];
656
656
pnts [0 ].x = x0 ;
@@ -666,7 +666,7 @@ static void
666
666
nk_rawfb_stroke_triangle (const struct rawfb_context * rawfb ,
667
667
const short x0 , const short y0 , const short x1 , const short y1 ,
668
668
const short x2 , const short y2 , const unsigned short line_thickness ,
669
- const struct nk_color col )
669
+ const rawfb_color col )
670
670
{
671
671
nk_rawfb_stroke_line (rawfb , x0 , y0 , x1 , y1 , line_thickness , col );
672
672
nk_rawfb_stroke_line (rawfb , x1 , y1 , x2 , y2 , line_thickness , col );
@@ -676,7 +676,7 @@ nk_rawfb_stroke_triangle(const struct rawfb_context *rawfb,
676
676
static void
677
677
nk_rawfb_stroke_polygon (const struct rawfb_context * rawfb ,
678
678
const struct nk_vec2i * pnts , const int count ,
679
- const unsigned short line_thickness , const struct nk_color col )
679
+ const unsigned short line_thickness , const rawfb_color col )
680
680
{
681
681
int i ;
682
682
for (i = 1 ; i < count ; ++ i )
@@ -689,7 +689,7 @@ nk_rawfb_stroke_polygon(const struct rawfb_context *rawfb,
689
689
static void
690
690
nk_rawfb_stroke_polyline (const struct rawfb_context * rawfb ,
691
691
const struct nk_vec2i * pnts , const int count ,
692
- const unsigned short line_thickness , const struct nk_color col )
692
+ const unsigned short line_thickness , const rawfb_color col )
693
693
{
694
694
int i ;
695
695
for (i = 0 ; i < count - 1 ; ++ i )
@@ -699,7 +699,7 @@ nk_rawfb_stroke_polyline(const struct rawfb_context *rawfb,
699
699
700
700
static void
701
701
nk_rawfb_fill_circle (const struct rawfb_context * rawfb ,
702
- short x0 , short y0 , short w , short h , const struct nk_color col )
702
+ short x0 , short y0 , short w , short h , const rawfb_color col )
703
703
{
704
704
/* Bresenham's ellipses */
705
705
const int a2 = (w * w ) / 4 ;
@@ -736,7 +736,7 @@ nk_rawfb_fill_circle(const struct rawfb_context *rawfb,
736
736
static void
737
737
nk_rawfb_stroke_circle (const struct rawfb_context * rawfb ,
738
738
short x0 , short y0 , short w , short h , const short line_thickness ,
739
- const struct nk_color col )
739
+ const rawfb_color col )
740
740
{
741
741
/* Bresenham's ellipses */
742
742
const int a2 = (w * w ) / 4 ;
@@ -781,7 +781,7 @@ nk_rawfb_stroke_curve(const struct rawfb_context *rawfb,
781
781
const struct nk_vec2i p1 , const struct nk_vec2i p2 ,
782
782
const struct nk_vec2i p3 , const struct nk_vec2i p4 ,
783
783
const unsigned int num_segments , const unsigned short line_thickness ,
784
- const struct nk_color col )
784
+ const rawfb_color col )
785
785
{
786
786
unsigned int i_step , segments ;
787
787
float t_step ;
@@ -805,7 +805,7 @@ nk_rawfb_stroke_curve(const struct rawfb_context *rawfb,
805
805
}
806
806
807
807
static void
808
- nk_rawfb_clear (const struct rawfb_context * rawfb , const struct nk_color col )
808
+ nk_rawfb_clear (const struct rawfb_context * rawfb , const rawfb_color col )
809
809
{
810
810
nk_rawfb_fill_rect (rawfb , 0 , 0 , rawfb -> fb .w , rawfb -> fb .h , 0 , col );
811
811
}
@@ -1032,10 +1032,11 @@ nk_rawfb_render(const struct rawfb_context *rawfb,
1032
1032
const struct nk_color clear ,
1033
1033
const unsigned char enable_clear )
1034
1034
{
1035
+ const struct rawfb_pl * pl = & rawfb -> fb .pl ;
1035
1036
const struct nk_command * cmd ;
1036
1037
1037
1038
if (enable_clear )
1038
- nk_rawfb_clear (rawfb , clear );
1039
+ nk_rawfb_clear (rawfb , nk_rawfb_color2int ( clear , pl ) );
1039
1040
1040
1041
nk_foreach (cmd , (struct nk_context * )& rawfb -> ctx ) {
1041
1042
switch (cmd -> type ) {
@@ -1047,47 +1048,51 @@ nk_rawfb_render(const struct rawfb_context *rawfb,
1047
1048
case NK_COMMAND_LINE : {
1048
1049
const struct nk_command_line * l = (const struct nk_command_line * )cmd ;
1049
1050
nk_rawfb_stroke_line (rawfb , l -> begin .x , l -> begin .y , l -> end .x ,
1050
- l -> end .y , l -> line_thickness , l -> color );
1051
+ l -> end .y , l -> line_thickness , nk_rawfb_color2int ( l -> color , pl ) );
1051
1052
} break ;
1052
1053
case NK_COMMAND_RECT : {
1053
1054
const struct nk_command_rect * r = (const struct nk_command_rect * )cmd ;
1054
1055
nk_rawfb_stroke_rect (rawfb , r -> x , r -> y , r -> w , r -> h ,
1055
- (unsigned short )r -> rounding , r -> line_thickness , r -> color );
1056
+ (unsigned short )r -> rounding , r -> line_thickness ,
1057
+ nk_rawfb_color2int (r -> color , pl ));
1056
1058
} break ;
1057
1059
case NK_COMMAND_RECT_FILLED : {
1058
1060
const struct nk_command_rect_filled * r = (const struct nk_command_rect_filled * )cmd ;
1059
1061
nk_rawfb_fill_rect (rawfb , r -> x , r -> y , r -> w , r -> h ,
1060
- (unsigned short )r -> rounding , r -> color );
1062
+ (unsigned short )r -> rounding , nk_rawfb_color2int ( r -> color , pl ) );
1061
1063
} break ;
1062
1064
case NK_COMMAND_CIRCLE : {
1063
1065
const struct nk_command_circle * c = (const struct nk_command_circle * )cmd ;
1064
- nk_rawfb_stroke_circle (rawfb , c -> x , c -> y , c -> w , c -> h , c -> line_thickness , c -> color );
1066
+ nk_rawfb_stroke_circle (rawfb , c -> x , c -> y , c -> w , c -> h , c -> line_thickness ,
1067
+ nk_rawfb_color2int (c -> color , pl ));
1065
1068
} break ;
1066
1069
case NK_COMMAND_CIRCLE_FILLED : {
1067
1070
const struct nk_command_circle_filled * c = (const struct nk_command_circle_filled * )cmd ;
1068
- nk_rawfb_fill_circle (rawfb , c -> x , c -> y , c -> w , c -> h , c -> color );
1071
+ nk_rawfb_fill_circle (rawfb , c -> x , c -> y , c -> w , c -> h ,
1072
+ nk_rawfb_color2int (c -> color , pl ));
1069
1073
} break ;
1070
1074
case NK_COMMAND_TRIANGLE : {
1071
1075
const struct nk_command_triangle * t = (const struct nk_command_triangle * )cmd ;
1072
1076
nk_rawfb_stroke_triangle (rawfb , t -> a .x , t -> a .y , t -> b .x , t -> b .y ,
1073
- t -> c .x , t -> c .y , t -> line_thickness , t -> color );
1077
+ t -> c .x , t -> c .y , t -> line_thickness , nk_rawfb_color2int ( t -> color , pl ) );
1074
1078
} break ;
1075
1079
case NK_COMMAND_TRIANGLE_FILLED : {
1076
1080
const struct nk_command_triangle_filled * t = (const struct nk_command_triangle_filled * )cmd ;
1077
1081
nk_rawfb_fill_triangle (rawfb , t -> a .x , t -> a .y , t -> b .x , t -> b .y ,
1078
- t -> c .x , t -> c .y , t -> color );
1082
+ t -> c .x , t -> c .y , nk_rawfb_color2int ( t -> color , pl ) );
1079
1083
} break ;
1080
1084
case NK_COMMAND_POLYGON : {
1081
1085
const struct nk_command_polygon * p = (const struct nk_command_polygon * )cmd ;
1082
- nk_rawfb_stroke_polygon (rawfb , p -> points , p -> point_count , p -> line_thickness ,p -> color );
1086
+ nk_rawfb_stroke_polygon (rawfb , p -> points , p -> point_count , p -> line_thickness ,
1087
+ nk_rawfb_color2int (p -> color , pl ));
1083
1088
} break ;
1084
1089
case NK_COMMAND_POLYGON_FILLED : {
1085
1090
const struct nk_command_polygon_filled * p = (const struct nk_command_polygon_filled * )cmd ;
1086
- nk_rawfb_fill_polygon (rawfb , p -> points , p -> point_count , p -> color );
1091
+ nk_rawfb_fill_polygon (rawfb , p -> points , p -> point_count , nk_rawfb_color2int ( p -> color , pl ) );
1087
1092
} break ;
1088
1093
case NK_COMMAND_POLYLINE : {
1089
1094
const struct nk_command_polyline * p = (const struct nk_command_polyline * )cmd ;
1090
- nk_rawfb_stroke_polyline (rawfb , p -> points , p -> point_count , p -> line_thickness , p -> color );
1095
+ nk_rawfb_stroke_polyline (rawfb , p -> points , p -> point_count , p -> line_thickness , nk_rawfb_color2int ( p -> color , pl ) );
1091
1096
} break ;
1092
1097
case NK_COMMAND_TEXT : {
1093
1098
const struct nk_command_text * t = (const struct nk_command_text * )cmd ;
@@ -1097,7 +1102,7 @@ nk_rawfb_render(const struct rawfb_context *rawfb,
1097
1102
case NK_COMMAND_CURVE : {
1098
1103
const struct nk_command_curve * q = (const struct nk_command_curve * )cmd ;
1099
1104
nk_rawfb_stroke_curve (rawfb , q -> begin , q -> ctrl [0 ], q -> ctrl [1 ],
1100
- q -> end , 22 , q -> line_thickness , q -> color );
1105
+ q -> end , 22 , q -> line_thickness , nk_rawfb_color2int ( q -> color , pl ) );
1101
1106
} break ;
1102
1107
case NK_COMMAND_RECT_MULTI_COLOR : {
1103
1108
const struct nk_command_rect_multi_color * q = (const struct nk_command_rect_multi_color * )cmd ;
0 commit comments