[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[freetype2-demos] master d54a7ed: [graph] Rearrange 32-bit color.
From: |
Alexei Podtelezhnikov |
Subject: |
[freetype2-demos] master d54a7ed: [graph] Rearrange 32-bit color. |
Date: |
Thu, 22 Oct 2020 23:40:17 -0400 (EDT) |
branch: master
commit d54a7edd7b02c895b36511536a11b87f8028bf64
Author: Alexei Podtelezhnikov <apodtele@gmail.com>
Commit: Alexei Podtelezhnikov <apodtele@gmail.com>
[graph] Rearrange 32-bit color.
Both Windows and X11 interpret 32-bit color using masks rather than
byte order. We ned to align with that.
* graph.h (grColor): Update value type.
* graph/grobjs.c (grFindColor),
graph/grfill.c (gr_fill_hline_32),
graph/gblblit.c (grSetTargetPenBrush),
graph/grblit.c (blit_mono_to_rgb32): Updated.
---
ChangeLog | 13 +++++++++++++
graph/gblblit.c | 4 +---
graph/graph.h | 2 +-
graph/grblit.c | 16 +++-------------
graph/grfill.c | 12 +++---------
graph/grobjs.c | 8 ++++----
6 files changed, 25 insertions(+), 30 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 536e3e0..ba15d71 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,18 @@
2020-10-22 Alexei Podtelezhnikov <apodtele@gmail.com>
+ [graph] Rearrange 32-bit color.
+
+ Both Windows and X11 interpret 32-bit color using masks rather than
+ byte order. We ned to align with that.
+
+ * graph.h (grColor): Update value type.
+ * graph/grobjs.c (grFindColor),
+ graph/grfill.c (gr_fill_hline_32),
+ graph/gblblit.c (grSetTargetPenBrush),
+ graph/grblit.c (blit_mono_to_rgb32): Updated.
+
+2020-10-22 Alexei Podtelezhnikov <apodtele@gmail.com>
+
[graph] s/uint32/uint32_t/ and popularize it.
* graph/grconfig.h: Define uint32_t here...
diff --git a/graph/gblblit.c b/graph/gblblit.c
index 098d0a8..3f4c0e1 100644
--- a/graph/gblblit.c
+++ b/graph/gblblit.c
@@ -395,9 +395,7 @@ grSetTargetPenBrush( grBitmap* target,
case gr_pixel_mode_rgb32:
surface->origin += x * 4;
surface->gray_spans = _gblender_spans_rgb32;
- surface->gcolor = GRGB_PACK( color.chroma[0],
- color.chroma[1],
- color.chroma[2] );
+ surface->gcolor = color.value;
break;
default:
(void)_gblender_spans_bgr565; /* unused */
diff --git a/graph/graph.h b/graph/graph.h
index a24427e..9f71a04 100644
--- a/graph/graph.h
+++ b/graph/graph.h
@@ -110,7 +110,7 @@
typedef union grColor_
{
- long value;
+ uint32_t value;
unsigned char chroma[4];
} grColor;
diff --git a/graph/grblit.c b/graph/grblit.c
index 3f8e02e..24688b6 100644
--- a/graph/grblit.c
+++ b/graph/grblit.c
@@ -456,7 +456,7 @@
do
{
unsigned char* _read = read;
- unsigned char* _write = write;
+ uint32_t* _write = (uint32_t*)write;
unsigned long val = ((unsigned long)*_read++ | 0x100L ) << shift;
x = blit->width;
@@ -466,20 +466,10 @@
val = *_read++ | 0x100L;
if ( val & 0x80 )
- {
- /* this could be greatly optimized as */
- /* */
- /* *(long*)_write = color.value */
- /* */
- /* but it wouldn't work on 64-bits systems... stupid C types! */
- _write[0] = color.chroma[0];
- _write[1] = color.chroma[1];
- _write[2] = color.chroma[2];
- _write[3] = color.chroma[3];
- }
+ *_write = color.value;
val <<= 1;
- _write += 4;
+ _write++;
x--;
} while ( x > 0 );
diff --git a/graph/grfill.c b/graph/grfill.c
index 2ca6e57..517ee4a 100644
--- a/graph/grfill.c
+++ b/graph/grfill.c
@@ -112,21 +112,15 @@ gr_fill_hline_24( unsigned char* line,
}
static void
-gr_fill_hline_32( unsigned char* line,
+gr_fill_hline_32( unsigned char* _line,
int x,
int width,
grColor color )
{
- line += 4*x;
+ uint32_t* line = (uint32_t*)_line + x;
- /* clearly slow */
for (; width > 0; width--, line += 4)
- {
- line[0] = color.chroma[0];
- line[1] = color.chroma[1];
- line[2] = color.chroma[2];
- line[3] = color.chroma[3];
- }
+ *line++ = color.value;
}
diff --git a/graph/grobjs.c b/graph/grobjs.c
index 09a9522..59d7987 100644
--- a/graph/grobjs.c
+++ b/graph/grobjs.c
@@ -48,10 +48,10 @@
break;
case gr_pixel_mode_rgb32:
- color.chroma[0] = (unsigned char)red;
- color.chroma[1] = (unsigned char)green;
- color.chroma[2] = (unsigned char)blue;
- color.chroma[3] = (unsigned char)alpha;
+ color.value = ((alpha & 0xFF) << 24) |
+ ((red & 0xFF) << 16) |
+ ((green & 0xFF) << 8) |
+ ((blue & 0xFF) );
break;
default:
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [freetype2-demos] master d54a7ed: [graph] Rearrange 32-bit color.,
Alexei Podtelezhnikov <=