[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[freetype2-demos] master e5cf9c9 2/2: src/ftgamma.c: Center and clip the
From: |
Alexei Podtelezhnikov |
Subject: |
[freetype2-demos] master e5cf9c9 2/2: src/ftgamma.c: Center and clip the bitmap to fix resizing. |
Date: |
Thu, 28 May 2020 23:56:19 -0400 (EDT) |
branch: master
commit e5cf9c9f8997418e834a52f67e24a4c0b926e502
Author: Alexei Podtelezhnikov <apodtele@gmail.com>
Commit: Alexei Podtelezhnikov <apodtele@gmail.com>
src/ftgamma.c: Center and clip the bitmap to fix resizing.
---
ChangeLog | 4 ++++
src/ftgamma.c | 71 +++++++++++++++++++++++++++++++++++++++--------------------
2 files changed, 51 insertions(+), 24 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index ed5675f..18574c7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
2020-05-28 Alexei Podtelezhnikov <apodtele@gmail.com>
+ src/ftgamma.c: Center and clip the bitmap to fix resizing.
+
+2020-05-28 Alexei Podtelezhnikov <apodtele@gmail.com>
+
[graph/x11] Stop double-dealing BackSpace, Tab, Return, and Esc.
* graph/x11/grx11.c (gr_x11_surface_listen_event): Do not reset the
diff --git a/src/ftgamma.c b/src/ftgamma.c
index 0cd398e..088a0fe 100644
--- a/src/ftgamma.c
+++ b/src/ftgamma.c
@@ -285,36 +285,50 @@
int lcd )
{
int pitch = abs( out->pitch );
+ int l = 0, r = in->width, t = 0, b = in->rows;
int i, ii, j;
unsigned char* src;
unsigned char* dst;
+ /* clip if necessary */
+ if ( x < 0 )
+ l = -x;
+ if ( y < 0 )
+ t = -y;
+ if ( x + r > out->width )
+ r = out->width - x;
+ if ( y + b > out->rows )
+ b = out->rows - y;
+
if ( color.chroma[0] == 255 )
- for ( src = in->buffer, i = 0; i < in->rows; i++ )
+ for ( i = t; i < b; i++ )
{
- ii = ( i + 24 * lcd ) % in->rows;
- dst = out->buffer + ( y + ii ) * pitch + 3 * x;
- for ( j = 0; j < in->width; j++, src++, dst += 3 )
+ ii = ( i + 0 * lcd ) % in->rows;
+ src = in->buffer + ii * in->pitch + l;
+ dst = out->buffer + ( y + i ) * pitch + 3 * ( x + l );
+ for ( j = l; j < r; j++, src++, dst += 3 )
*dst = *src;
}
if ( color.chroma[1] == 255 )
- for ( src = in->buffer, i = 0; i < in->rows; i++ )
+ for ( i = t; i < b; i++ )
{
ii = ( i + 12 * lcd ) % in->rows;
- dst = out->buffer + ( y + ii ) * pitch + 3 * x + 1;
- for ( j = 0; j < in->width; j++, src++, dst += 3 )
+ src = in->buffer + ii * in->pitch + l;
+ dst = out->buffer + ( y + i ) * pitch + 3 * ( x + l ) + 1;
+ for ( j = l; j < r; j++, src++, dst += 3 )
*dst = *src;
}
if ( color.chroma[2] == 255 )
- for ( src = in->buffer, i = 0; i < in->rows; i++ )
+ for ( i = t; i < b; i++ )
{
- ii = ( i + 0 * lcd ) % in->rows;
- dst = out->buffer + ( y + ii ) * pitch + 3 * x + 2;
- for ( j = 0; j < in->width; j++, src++, dst += 3 )
+ ii = ( i + 24 * lcd ) % in->rows;
+ src = in->buffer + ii * in->pitch + l;
+ dst = out->buffer + ( y + i ) * pitch + 3 * ( x + l ) + 2;
+ for ( j = l; j < r; j++, src++, dst += 3 )
*dst = *src;
}
}
@@ -329,6 +343,9 @@
grListenSurface( display->surface, 0, &event );
+ if ( event.type == gr_event_resize )
+ return ret;
+
switch ( event.key )
{
case grKeyEsc:
@@ -387,36 +404,42 @@
do
{
+ int x = display->bitmap->width / 2;
+ int y = display->bitmap->rows / 2;
+
+
FTDemo_Display_Clear( display );
switch ( status )
{
case 0:
- grWriteCellString( display->bitmap, 236, 75, "Solid-Checkered Pattern",
- display->fore_color );
- Render_Bitmap( display->bitmap, &bit1, 20, 90, display->fore_color, 0
);
+ grWriteCellString( display->bitmap, x - 84, y - 165,
+ "Solid-Checkered Pattern", display->fore_color );
+ Render_Bitmap( display->bitmap, &bit1, x - 300, y - 150,
+ display->fore_color, 0 );
break;
case 1:
- grWriteCellString( display->bitmap, 236, 75, "Grayscale Anti-Aliasing",
- display->fore_color );
- Render_Bitmap( display->bitmap, &bit2, 20, 96, display->fore_color, 0
);
+ grWriteCellString( display->bitmap, x - 84, y - 165,
+ "Grayscale Anti-Aliasing", display->fore_color );
+ Render_Bitmap( display->bitmap, &bit2, x - 300, y - 144,
+ display->fore_color, 0 );
break;
case 2:
- grWriteCellString( display->bitmap, 236, 75, "Subpixel Anti-Aliasing",
- display->fore_color );
- Render_Bitmap( display->bitmap, &bit2, 20, 96, display->fore_color, 1
);
+ grWriteCellString( display->bitmap, x - 84, y - 165,
+ "Subpixel Anti-Aliasing", display->fore_color );
+ Render_Bitmap( display->bitmap, &bit2, x - 300, y - 144,
+ display->fore_color, 1 );
break;
}
for ( i = 0; i <= 10; i++ )
{
sprintf( buf, "%.1f", 1. + .2 * i );
- grWriteCellString( display->bitmap, 9 + i * 60, 395, buf,
- display->fore_color );
+ grWriteCellString( display->bitmap, x - 311 + i * 60, y + 155,
+ buf, display->fore_color );
}
- grWriteCellString( display->bitmap,
- display->bitmap->width / 2 - 20, 410,
+ grWriteCellString( display->bitmap, x - 20, y + 170,
"Gamma", display->fore_color );
grRefreshSurface( display->surface );
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [freetype2-demos] master e5cf9c9 2/2: src/ftgamma.c: Center and clip the bitmap to fix resizing.,
Alexei Podtelezhnikov <=