[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[freetype2-demos] master 25450a3: [ftgamma] Enable color.
From: |
Alexei Podtelezhnikov |
Subject: |
[freetype2-demos] master 25450a3: [ftgamma] Enable color. |
Date: |
Tue, 05 Jan 2016 04:49:03 +0000 |
branch: master
commit 25450a3cbb6f8315692b6b1c50d44d4f049e575e
Author: Alexei Podtelezhnikov <address@hidden>
Commit: Alexei Podtelezhnikov <address@hidden>
[ftgamma] Enable color.
* src/ftcamma.c (Render_GammaGrid): Split into...
(Render_Bitmap): ... this renderer with color controls.
(GammaGrid): ... and this grayscale bitmap builder.
(event_color_change): New function.
(Process_Event, event_help, main): Updated.
* src/ftgamma.1: Updated.
---
ChangeLog | 11 ++++++
src/ftgamma.1 | 4 +-
src/ftgamma.c | 112 +++++++++++++++++++++++++++++++++++++++++++-------------
3 files changed, 99 insertions(+), 28 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 8435683..bd8ee18 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2016-01-04 Alexei Podtelezhnikov <address@hidden>
+
+ [ftgamma] Enable color.
+
+ * src/ftcamma.c (Render_GammaGrid): Split into...
+ (Render_Bitmap): ... this renderer with color controls.
+ (GammaGrid): ... and this grayscale bitmap builder.
+ (event_color_change): New function.
+ (Process_Event, event_help, main): Updated.
+ * src/ftgamma.1: Updated.
+
2015-12-22 Alexei Podtelezhnikov <address@hidden>
[ftgamma] Minor refactoring.
diff --git a/src/ftgamma.1 b/src/ftgamma.1
index 35a483e..b149959 100644
--- a/src/ftgamma.1
+++ b/src/ftgamma.1
@@ -21,11 +21,11 @@ roughly corresponds to the horizontal position where the
solid and checkered
stripes are equally bright when seen from some distance. Three brightness
targets are explored: 33%, 50%, and 67%. If the input-output curve of your
monitor does not follow ideal power law relationship, you might observe
-slightly different gamma values at different brightness levels.
+slightly different gamma values at different brightness levels. It is also
+possible to examine gamma values for basic colors.
.
.PP
This program does not have any options.
-Pressing any key closes the window again.
.
.PP
This program is part of the FreeType demos package.
diff --git a/src/ftgamma.c b/src/ftgamma.c
index 16a47c2..03ce599 100644
--- a/src/ftgamma.c
+++ b/src/ftgamma.c
@@ -31,51 +31,38 @@
int i;
double b, f;
- unsigned char* line = bitmap->buffer + y*pitch + 3*x;
- unsigned char* dst;
+ unsigned char* line = bitmap->buffer + y*pitch + x;
if ( back == 0 || back == 255 )
for ( i = 0; i < w; i++ )
- {
- dst = line + 3 * i + ( i & 1 ) * pitch;
- dst[0] = dst[1] = dst[2] = back;
- }
+ line[i + ( i & 1 ) * pitch] = back;
else
for ( b = back / 255., i = 0; i < w; i++ )
- {
- dst = line + 3 * i + ( i & 1 ) * pitch;
- dst[0] = dst[1] = dst[2] = 0.5 +
- 255. * pow ( b, 1. / (1. + 2. * i / w ) );
- }
+ line[i + ( i & 1 ) * pitch] =
+ 0.5 + 255. * pow ( b, 1. / (1. + 2. * i / w ) );
if ( fore == 0 || fore == 255 )
for ( i = 0; i < w; i++ )
- {
- dst = line + 3 * i + ( ~i & 1 ) * pitch;
- dst[0] = dst[1] = dst[2] = fore;
- }
+ line[i + ( ~i & 1 ) * pitch] = fore;
else
for ( f = fore / 255., i = 0; i < w; i++ )
- {
- dst = line + 3 * i + ( ~i & 1 ) * pitch;
- dst[0] = dst[1] = dst[2] = 0.5 +
- 255. * pow ( f, 1. / (1. + 2. * i / w ) );
- }
+ line[i + ( ~i & 1 ) * pitch] =
+ 0.5 + 255. * pow ( f, 1. / (1. + 2. * i / w ) );
for ( i = 2; i < h; i += 2 )
{
- memcpy( line + i * pitch, line, 3 * w );
- memcpy( line + i * pitch + pitch, line + pitch, 3 * w );
+ memcpy( line + i * pitch, line, w );
+ memcpy( line + i * pitch + pitch, line + pitch, w );
}
}
static FT_Error
- Render_GammaGrid( grBitmap* bitmap )
+ GammaGrid( grBitmap* bitmap )
{
- int x = 20;
- int y = 90;
+ int x = 0;
+ int y = 0;
int h = ( bitmap->rows - 2 * y ) / 15;
int w = bitmap->width - 2 * x;
@@ -121,6 +108,7 @@
grLn();
grWriteln( "F1, ? display this help screen" );
grLn();
+ grWriteln( "space cycle through color");
grWriteln( "G show gamma ramp" );
grLn();
grLn();
@@ -132,6 +120,24 @@
static void
+ event_color_change( void )
+ {
+ static int i = 7;
+ unsigned char r = i & 4 ? 0xff : 0;
+ unsigned char g = i & 2 ? 0xff : 0;
+ unsigned char b = i & 1 ? 0xff : 0;
+
+
+ display->back_color = grFindColor( display->bitmap, 0, 0, 0, 0xff );
+ display->fore_color = grFindColor( display->bitmap, r, g, b, 0xff );
+
+ i++;
+ if ( ( i & 0x7 ) == 0 )
+ i = 1;
+ }
+
+
+ static void
event_gamma_grid( void )
{
grEvent dummy_event;
@@ -202,6 +208,44 @@
}
+ static void
+ Render_Bitmap( grBitmap* bitmap,
+ grBitmap* bit,
+ int x,
+ int y,
+ grColor color )
+ {
+ int pitch = bitmap->pitch;
+ int i, j;
+
+ unsigned char* src;
+ unsigned char* dst;
+
+ if ( color.chroma[0] == 255 )
+ for ( src = bit->buffer, i = 0; i < bit->rows; i++ )
+ {
+ dst = bitmap->buffer + ( y + i ) * pitch + 3 * x;
+ for ( j = 0; j < bit->width; j++, src++, dst += 3 )
+ *dst = *src;
+ }
+
+ if ( color.chroma[1] == 255 )
+ for ( src = bit->buffer, i = 0; i < bit->rows; i++ )
+ {
+ dst = bitmap->buffer + ( y + i ) * pitch + 3 * x + 1;
+ for ( j = 0; j < bit->width; j++, src++, dst += 3 )
+ *dst = *src;
+ }
+
+ if ( color.chroma[2] == 255 )
+ for ( src = bit->buffer, i = 0; i < bit->rows; i++ )
+ {
+ dst = bitmap->buffer + ( y + i ) * pitch + 3 * x + 2;
+ for ( j = 0; j < bit->width; j++, src++, dst += 3 )
+ *dst = *src;
+ }
+ }
+
static int
Process_Event( grEvent* event )
{
@@ -219,6 +263,10 @@
event_help();
break;
+ case grKeySpace:
+ event_color_change();
+ break;
+
case grKEY( 'G' ):
event_gamma_grid();
break;
@@ -234,6 +282,7 @@
int
main( void )
{
+ grBitmap bit;
grEvent event;
char buf[4];
int i;
@@ -246,11 +295,22 @@
grSetTitle( display->surface, "FreeType Gamma Matcher - press ? for help"
);
+ bit.rows = 300;
+ bit.width = 600;
+ bit.pitch = 600;
+ bit.grays = 256;
+ bit.mode = gr_pixel_mode_gray;
+
+ grNewBitmap( bit.mode, bit.grays, bit.width, bit.rows, &bit );
+ GammaGrid( &bit );
+
+ event_color_change();
+
do
{
FTDemo_Display_Clear( display );
- Render_GammaGrid( display->bitmap );
+ Render_Bitmap( display->bitmap, &bit, 20, 90, display->fore_color );
for ( i = 0; i <= 10; i++ )
{
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [freetype2-demos] master 25450a3: [ftgamma] Enable color.,
Alexei Podtelezhnikov <=