[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[freetype2-demos] master 89a1071: Relocate gamma grid display from [ftvi
From: |
Alexei Podtelezhnikov |
Subject: |
[freetype2-demos] master 89a1071: Relocate gamma grid display from [ftview] to [ftgamma]. |
Date: |
Mon, 21 Dec 2015 04:11:35 +0000 |
branch: master
commit 89a1071166c60ebdd9acf5d33e7438fe9ed05497
Author: Alexei Podtelezhnikov <address@hidden>
Commit: Alexei Podtelezhnikov <address@hidden>
Relocate gamma grid display from [ftview] to [ftgamma].
* src/ftview.c (Procenn_Event): Remove event `G'.
(event_help): Update.
(event_gamma_grid): Move to...
* src/ftgamma.c (event_gamma_grid): ... here.
(Process_Event): New function.
(event_help): New function.
(main): Update to handle events.
---
ChangeLog | 12 ++
src/ftgamma.c | 317 ++++++++++++++++++++++++++++++++++++++++----------------
src/ftview.c | 79 +--------------
3 files changed, 240 insertions(+), 168 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index fdfd979..83c5806 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2015-12-20 Alexei Podtelezhnikov <address@hidden>
+
+ Relocate gamma grid display from [ftview] to [ftgamma].
+
+ * src/ftview.c (Procenn_Event): Remove event `G'.
+ (event_help): Update.
+ (event_gamma_grid): Move to...
+ * src/ftgamma.c (event_gamma_grid): ... here.
+ (Process_Event): New function.
+ (event_help): New function.
+ (main): Update to handle events.
+
2015-12-18 Alexei Podtelezhnikov <address@hidden>
[ftstring, ftview] Auxiliary gamma rounding fixes.
diff --git a/src/ftgamma.c b/src/ftgamma.c
index 8662eb8..08b34d8 100644
--- a/src/ftgamma.c
+++ b/src/ftgamma.c
@@ -15,125 +15,260 @@
#include <math.h>
-static void
-do_fill( grBitmap* bitmap,
- int x,
- int y,
- int w,
- int h,
- int back,
- int fore )
-{
- int pitch = bitmap->pitch;
- int i;
- double b, f;
-
- unsigned char* line = bitmap->buffer + y*pitch + 3*x;
- unsigned char* dst;
-
-
- 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;
- }
- 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 ) );
- }
+ static FTDemo_Display* display;
+
+
+ static void
+ do_fill( grBitmap* bitmap,
+ int x,
+ int y,
+ int w,
+ int h,
+ int back,
+ int fore )
+ {
+ int pitch = bitmap->pitch;
+ int i;
+ double b, f;
+
+ unsigned char* line = bitmap->buffer + y*pitch + 3*x;
+ unsigned char* dst;
- if ( fore == 0 || fore == 255 )
- for ( i = 0; i < w; i++ )
+
+ 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;
+ }
+ 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 ) );
+ }
+
+ 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;
+ }
+ 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 ) );
+ }
+
+ for ( i = 2; i < h; i += 2 )
{
- dst = line + 3 * i + ( ~i & 1 ) * pitch;
- dst[0] = dst[1] = dst[2] = fore;
+ memcpy( line + i * pitch, line, 3 * w );
+ memcpy( line + i * pitch + pitch, line + pitch, 3 * w );
}
- else
- for ( f = fore / 255., i = 0; i < w; i++ )
+ }
+
+
+ static FT_Error
+ Render_GammaGrid( grBitmap* bitmap )
+ {
+ int x = 20;
+ int y = 90;
+ int h = ( bitmap->rows - 2 * y ) / 15;
+ int w = bitmap->width - 2 * x;
+
+ int i;
+ char buf[4];
+ grColor color = grFindColor( bitmap, 0x00, 0x00, 0x00, 0xff );
+
+
+ do_fill( bitmap, x, y, w, h, 85, 255 );
+ do_fill( bitmap, x, y+=h, w, h, 170, 170 );
+ do_fill( bitmap, x, y+=h, w, h, 85, 255 );
+ do_fill( bitmap, x, y+=h, w, h, 170, 170 );
+ do_fill( bitmap, x, y+=h, w, h, 85, 255 );
+
+ do_fill( bitmap, x, y+=h, w, h, 0, 255 );
+ do_fill( bitmap, x, y+=h, w, h, 127, 127 );
+ do_fill( bitmap, x, y+=h, w, h, 0, 255 );
+ do_fill( bitmap, x, y+=h, w, h, 127, 127 );
+ do_fill( bitmap, x, y+=h, w, h, 0, 255 );
+
+ do_fill( bitmap, x, y+=h, w, h, 0, 170 );
+ do_fill( bitmap, x, y+=h, w, h, 85, 85 );
+ do_fill( bitmap, x, y+=h, w, h, 0, 170 );
+ do_fill( bitmap, x, y+=h, w, h, 85, 85 );
+ do_fill( bitmap, x, y+=h, w, h, 0, 170 );
+
+ for ( i = 0; i <= 10; i++ )
{
- dst = line + 3 * i + ( ~i & 1 ) * pitch;
- dst[0] = dst[1] = dst[2] = 0.5 +
- 255. * pow ( f, 1. / (1. + 2. * i / w ) );
+ sprintf( buf, "%.1f", 1. + .2 * i );
+ grWriteCellString( bitmap, 9 + i * w / 10, 395, buf, color );
}
- for ( i = 2; i < h; i += 2 )
- {
- memcpy( line + i * pitch, line, 3 * w );
- memcpy( line + i * pitch + pitch, line + pitch, 3 * w );
+ return 0;
}
-}
-static FT_Error
-Render_GammaGrid( grBitmap* bitmap )
-{
- int x = 20;
- int y = 90;
- int h = ( bitmap->rows - 2 * y ) / 15;
- int w = bitmap->width - 2 * x;
+ static void
+ event_help( void )
+ {
+ grEvent dummy_event;
- int i;
- char buf[4];
- grColor color = grFindColor( bitmap, 0x00, 0x00, 0x00, 0xff );
+ FTDemo_Display_Clear( display );
+ grSetLineHeight( 10 );
+ grGotoxy( 0, 0 );
+ grSetMargin( 2, 1 );
+ grGotobitmap( display->bitmap );
- do_fill( bitmap, x, y, w, h, 85, 255 );
- do_fill( bitmap, x, y+=h, w, h, 170, 170 );
- do_fill( bitmap, x, y+=h, w, h, 85, 255 );
- do_fill( bitmap, x, y+=h, w, h, 170, 170 );
- do_fill( bitmap, x, y+=h, w, h, 85, 255 );
- do_fill( bitmap, x, y+=h, w, h, 0, 255 );
- do_fill( bitmap, x, y+=h, w, h, 127, 127 );
- do_fill( bitmap, x, y+=h, w, h, 0, 255 );
- do_fill( bitmap, x, y+=h, w, h, 127, 127 );
- do_fill( bitmap, x, y+=h, w, h, 0, 255 );
+ grWriteln( "FreeType Gamma Matcher" );
+ grLn();
+ grWriteln( "Use the following keys:" );
+ grLn();
+ grWriteln( "F1, ? display this help screen" );
+ grLn();
+ grWriteln( "G show gamma ramp" );
+ grLn();
+ grLn();
+ grWriteln( "press any key to exit this help screen" );
- do_fill( bitmap, x, y+=h, w, h, 0, 170 );
- do_fill( bitmap, x, y+=h, w, h, 85, 85 );
- do_fill( bitmap, x, y+=h, w, h, 0, 170 );
- do_fill( bitmap, x, y+=h, w, h, 85, 85 );
- do_fill( bitmap, x, y+=h, w, h, 0, 170 );
+ grRefreshSurface( display->surface );
+ grListenSurface( display->surface, gr_event_key, &dummy_event );
+ }
- for ( i = 0; i <= 10; i++ )
+
+ static void
+ event_gamma_grid( void )
{
- sprintf( buf, "%.1f", 1. + .2 * i );
- grWriteCellString( bitmap, 9 + i * w / 10, 395, buf, color );
- }
+ grEvent dummy_event;
+ int g;
+ int yside = 11;
+ int xside = 10;
+ int levels = 17;
+ int gammas = 30;
+ int x_0 = ( display->bitmap->width - levels * xside ) / 2;
+ int y_0 = ( display->bitmap->rows - gammas * ( yside + 1 ) ) / 2;
+ int pitch = display->bitmap->pitch;
+
+
+ FTDemo_Display_Clear( display );
+ grGotobitmap( display->bitmap );
- return 0;
-}
+ if ( pitch < 0 )
+ pitch = -pitch;
+ memset( display->bitmap->buffer,
+ 100,
+ (unsigned int)( pitch * display->bitmap->rows ) );
+ grWriteCellString( display->bitmap, 0, 0, "Gamma grid",
+ display->fore_color );
+
+
+ for ( g = 1; g <= gammas; g++ )
+ {
+ double ggamma = 0.1 * g;
+ char temp[6];
+ int y = y_0 + ( yside + 1 ) * ( g - 1 );
+ int nx, ny;
-int
-main( void )
-{
- FTDemo_Display* display;
- grEvent dummy;
+ unsigned char* line = display->bitmap->buffer +
+ y * display->bitmap->pitch;
- display = FTDemo_Display_New( gr_pixel_mode_rgb24, DIM_X, DIM_Y );
- if ( !display )
+
+ if ( display->bitmap->pitch < 0 )
+ line -= display->bitmap->pitch * ( display->bitmap->rows - 1 );
+
+ line += x_0 * 3;
+
+ grSetPixelMargin( x_0 - 32, y + ( yside - 8 ) / 2 );
+ grGotoxy( 0, 0 );
+
+ sprintf( temp, "%.1f", ggamma );
+ grWrite( temp );
+
+ for ( ny = 0; ny < yside; ny++, line += display->bitmap->pitch )
+ {
+ unsigned char* dst = line;
+
+
+ for ( nx = 0; nx < levels; nx++, dst += 3 * xside )
+ {
+ double p = nx / (double)( levels - 1 );
+ int gm = (int)( 255.0 * pow( p, ggamma ) + 0.5 );
+
+
+ memset( dst, gm, (unsigned int)( xside * 3 ) );
+ }
+ }
+ }
+
+ grRefreshSurface( display->surface );
+ grListenSurface( display->surface, gr_event_key, &dummy_event );
+ }
+
+
+ static int
+ Process_Event( grEvent* event )
{
- PanicZ( "could not allocate display surface" );
+ int ret = 0;
+
+ switch ( event->key )
+ {
+ case grKeyEsc:
+ case grKEY( 'q' ):
+ ret = 1;
+ break;
+
+ case grKeyF1:
+ case grKEY( '?' ):
+ event_help();
+ break;
+
+ case grKEY( 'G' ):
+ event_gamma_grid();
+ break;
+
+ default:
+ break;
+ }
+
+ return ret;
}
- grSetTitle( display->surface, "FreeType Gamma Matcher" );
- FTDemo_Display_Clear( display );
+ int
+ main( void )
+ {
+ grEvent event;
- Render_GammaGrid( display->bitmap );
+ display = FTDemo_Display_New( gr_pixel_mode_rgb24, DIM_X, DIM_Y );
+ if ( !display )
+ {
+ PanicZ( "could not allocate display surface" );
+ }
+
+ grSetTitle( display->surface, "FreeType Gamma Matcher - press ? for help"
);
+
+ do
+ {
+ FTDemo_Display_Clear( display );
- grRefreshSurface( display->surface );
- grListenSurface( display->surface, 0, &dummy );
+ Render_GammaGrid( display->bitmap );
- exit( 0 ); /* for safety reasons */
- /* return 0; */ /* never reached */
-}
+ grRefreshSurface( display->surface );
+ grListenSurface( display->surface, 0, &event );
+ } while ( Process_Event( &event ) == 0 );
+
+ FTDemo_Display_Done( display );
+
+ exit( 0 ); /* for safety reasons */
+ /* return 0; */ /* never reached */
+ }
/* End */
diff --git a/src/ftview.c b/src/ftview.c
index f845899..4bb5c07 100644
--- a/src/ftview.c
+++ b/src/ftview.c
@@ -805,8 +805,8 @@
grWriteln( "h toggle hinting -, +(=) adjust
selected custom " );
grWriteln( "H cycle through hinting LCD
filter weight " );
grWriteln( " engines (if available)
" );
- grWriteln( "f toggle forced auto- G show gamma
ramp " );
- grWriteln( " hinting (if hinting) g, v adjust
gamma value " );
+ grWriteln( "f toggle forced auto- g, v adjust
gamma value " );
+ grWriteln( " hinting (if hinting)
" );
grWriteln( "w toggle warping (in light
" );
grWriteln( " AA mode, if available) q, ESC quit
ftview " );
grWriteln( "
" );
@@ -821,76 +821,6 @@
}
- static void
- event_gamma_grid( void )
- {
- grEvent dummy_event;
- int g;
- int yside = 11;
- int xside = 10;
- int levels = 17;
- int gammas = 30;
- int x_0 = ( display->bitmap->width - levels * xside ) / 2;
- int y_0 = ( display->bitmap->rows - gammas * ( yside + 1 ) ) / 2;
- int pitch = display->bitmap->pitch;
-
-
- FTDemo_Display_Clear( display );
- grGotobitmap( display->bitmap );
-
- if ( pitch < 0 )
- pitch = -pitch;
-
- memset( display->bitmap->buffer,
- 100,
- (unsigned int)( pitch * display->bitmap->rows ) );
-
- grWriteCellString( display->bitmap, 0, 0, "Gamma grid",
- display->fore_color );
-
- for ( g = 1; g <= gammas; g++ )
- {
- double ggamma = 0.1 * g;
- char temp[6];
- int y = y_0 + ( yside + 1 ) * ( g - 1 );
- int nx, ny;
-
- unsigned char* line = display->bitmap->buffer +
- y * display->bitmap->pitch;
-
-
- if ( display->bitmap->pitch < 0 )
- line -= display->bitmap->pitch * ( display->bitmap->rows - 1 );
-
- line += x_0 * 3;
-
- grSetPixelMargin( x_0 - 32, y + ( yside - 8 ) / 2 );
- grGotoxy( 0, 0 );
-
- sprintf( temp, "%.1f", ggamma );
- grWrite( temp );
-
- for ( ny = 0; ny < yside; ny++, line += display->bitmap->pitch )
- {
- unsigned char* dst = line;
-
-
- for ( nx = 0; nx < levels; nx++, dst += 3 * xside )
- {
- double p = nx / (double)( levels - 1 );
- int gm = (int)( 255.0 * pow( p, ggamma ) + 0.5 );
-
-
- memset( dst, gm, (unsigned int)( xside * 3 ) );
- }
- }
- }
-
- grRefreshSurface( display->surface );
- grListenSurface( display->surface, gr_event_key, &dummy_event );
- }
-
-
static int
event_cff_hinting_engine_change( unsigned int delta )
{
@@ -1260,11 +1190,6 @@
status.update = 1;
break;
- case grKEY( 'G' ):
- event_gamma_grid();
- status.update = 1;
- break;
-
case grKEY( 's' ):
if ( status.render_mode == RENDER_MODE_SLANTED )
status.update = event_slant_change( 0.02 );
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [freetype2-demos] master 89a1071: Relocate gamma grid display from [ftview] to [ftgamma].,
Alexei Podtelezhnikov <=