2004-12-14 17:01:29 +01:00
|
|
|
/***************************************************************************/
|
|
|
|
/* */
|
|
|
|
/* ftbitmap.c */
|
|
|
|
/* */
|
|
|
|
/* FreeType utility functions for converting 1bpp, 2bpp, 4bpp, and 8bpp */
|
|
|
|
/* bitmaps into 8bpp format (body). */
|
|
|
|
/* */
|
2007-01-13 08:34:23 +01:00
|
|
|
/* Copyright 2004, 2005, 2006, 2007 by */
|
2004-12-14 17:01:29 +01:00
|
|
|
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
|
|
|
|
/* */
|
|
|
|
/* This file is part of the FreeType project, and may only be used, */
|
|
|
|
/* modified, and distributed under the terms of the FreeType project */
|
|
|
|
/* license, LICENSE.TXT. By continuing to use, modify, or distribute */
|
|
|
|
/* this file you indicate that you have read the license and */
|
|
|
|
/* understand and accept it fully. */
|
|
|
|
/* */
|
|
|
|
/***************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
#include <ft2build.h>
|
2005-05-20 23:52:19 +02:00
|
|
|
#include FT_BITMAP_H
|
2004-12-14 17:01:29 +01:00
|
|
|
#include FT_INTERNAL_OBJECTS_H
|
|
|
|
|
|
|
|
|
|
|
|
static
|
|
|
|
const FT_Bitmap null_bitmap = { 0, 0, 0, 0, 0, 0, 0, 0 };
|
|
|
|
|
|
|
|
|
|
|
|
/* documentation is in ftbitmap.h */
|
|
|
|
|
|
|
|
FT_EXPORT_DEF( void )
|
|
|
|
FT_Bitmap_New( FT_Bitmap *abitmap )
|
|
|
|
{
|
|
|
|
*abitmap = null_bitmap;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-05-20 23:52:19 +02:00
|
|
|
/* documentation is in ftbitmap.h */
|
|
|
|
|
|
|
|
FT_EXPORT_DEF( FT_Error )
|
|
|
|
FT_Bitmap_Copy( FT_Library library,
|
|
|
|
const FT_Bitmap *source,
|
|
|
|
FT_Bitmap *target)
|
|
|
|
{
|
|
|
|
FT_Memory memory = library->memory;
|
|
|
|
FT_Error error = FT_Err_Ok;
|
|
|
|
FT_Int pitch = source->pitch;
|
|
|
|
FT_ULong size;
|
|
|
|
|
|
|
|
|
|
|
|
if ( source == target )
|
|
|
|
return FT_Err_Ok;
|
|
|
|
|
|
|
|
if ( source->buffer == NULL )
|
|
|
|
{
|
|
|
|
*target = *source;
|
|
|
|
|
|
|
|
return FT_Err_Ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( pitch < 0 )
|
|
|
|
pitch = -pitch;
|
|
|
|
size = (FT_ULong)( pitch * source->rows );
|
|
|
|
|
|
|
|
if ( target->buffer )
|
|
|
|
{
|
|
|
|
FT_Int target_pitch = target->pitch;
|
|
|
|
FT_ULong target_size;
|
|
|
|
|
|
|
|
|
|
|
|
if ( target_pitch < 0 )
|
|
|
|
target_pitch = -target_pitch;
|
|
|
|
target_size = (FT_ULong)( target_pitch * target->rows );
|
|
|
|
|
|
|
|
if ( target_size != size )
|
2006-01-27 13:11:22 +01:00
|
|
|
(void)FT_QREALLOC( target->buffer, target_size, size );
|
2005-05-20 23:52:19 +02:00
|
|
|
}
|
|
|
|
else
|
2006-01-27 13:11:22 +01:00
|
|
|
(void)FT_QALLOC( target->buffer, size );
|
2005-05-20 23:52:19 +02:00
|
|
|
|
|
|
|
if ( !error )
|
|
|
|
{
|
|
|
|
unsigned char *p;
|
|
|
|
|
|
|
|
|
|
|
|
p = target->buffer;
|
|
|
|
*target = *source;
|
|
|
|
target->buffer = p;
|
|
|
|
|
|
|
|
FT_MEM_COPY( target->buffer, source->buffer, size );
|
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-05-25 07:51:01 +02:00
|
|
|
static FT_Error
|
|
|
|
ft_bitmap_assure_buffer( FT_Memory memory,
|
|
|
|
FT_Bitmap* bitmap,
|
|
|
|
FT_UInt xpixels,
|
|
|
|
FT_UInt ypixels )
|
|
|
|
{
|
|
|
|
FT_Error error;
|
|
|
|
int pitch;
|
|
|
|
int new_pitch;
|
|
|
|
FT_UInt ppb;
|
2007-01-13 01:19:18 +01:00
|
|
|
FT_Int i, width;
|
2005-05-25 07:51:01 +02:00
|
|
|
unsigned char* buffer;
|
|
|
|
|
|
|
|
|
2007-01-13 01:19:18 +01:00
|
|
|
width = bitmap->width;
|
2005-05-25 07:51:01 +02:00
|
|
|
pitch = bitmap->pitch;
|
|
|
|
if ( pitch < 0 )
|
|
|
|
pitch = -pitch;
|
|
|
|
|
|
|
|
switch ( bitmap->pixel_mode )
|
|
|
|
{
|
|
|
|
case FT_PIXEL_MODE_MONO:
|
|
|
|
ppb = 8;
|
|
|
|
break;
|
|
|
|
case FT_PIXEL_MODE_GRAY2:
|
|
|
|
ppb = 4;
|
|
|
|
break;
|
|
|
|
case FT_PIXEL_MODE_GRAY4:
|
|
|
|
ppb = 2;
|
|
|
|
break;
|
|
|
|
case FT_PIXEL_MODE_GRAY:
|
2005-05-30 09:54:20 +02:00
|
|
|
case FT_PIXEL_MODE_LCD:
|
|
|
|
case FT_PIXEL_MODE_LCD_V:
|
2005-05-25 07:51:01 +02:00
|
|
|
ppb = 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return FT_Err_Invalid_Glyph_Format;
|
|
|
|
}
|
|
|
|
|
2005-05-30 09:54:20 +02:00
|
|
|
/* if no need to allocate memory */
|
2005-05-25 07:51:01 +02:00
|
|
|
if ( ypixels == 0 && pitch * ppb >= bitmap->width + xpixels )
|
2005-05-30 09:54:20 +02:00
|
|
|
{
|
|
|
|
/* zero the padding */
|
|
|
|
for ( i = 0; i < bitmap->rows; i++ )
|
|
|
|
{
|
|
|
|
unsigned char* last_byte;
|
|
|
|
int bits = xpixels * ( 8 / ppb );
|
|
|
|
int mask = 0;
|
|
|
|
|
|
|
|
|
|
|
|
last_byte = bitmap->buffer + i * pitch + ( bitmap->width - 1 ) / ppb;
|
|
|
|
|
|
|
|
if ( bits >= 8 )
|
|
|
|
{
|
|
|
|
FT_MEM_ZERO( last_byte + 1, bits / 8 );
|
|
|
|
bits %= 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( bits > 0 )
|
|
|
|
{
|
|
|
|
while ( bits-- > 0 )
|
|
|
|
mask |= 1 << bits;
|
|
|
|
|
|
|
|
*last_byte &= ~mask;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-05-25 07:51:01 +02:00
|
|
|
return FT_Err_Ok;
|
2005-05-30 09:54:20 +02:00
|
|
|
}
|
2005-05-25 07:51:01 +02:00
|
|
|
|
|
|
|
new_pitch = ( bitmap->width + xpixels + ppb - 1 ) / ppb;
|
|
|
|
|
2006-05-02 11:00:29 +02:00
|
|
|
if ( FT_QALLOC_MULT( buffer, new_pitch, bitmap->rows + ypixels ) )
|
2005-05-25 07:51:01 +02:00
|
|
|
return error;
|
|
|
|
|
|
|
|
if ( bitmap->pitch > 0 )
|
|
|
|
{
|
2007-01-13 08:34:23 +01:00
|
|
|
FT_Int len = ( width + ppb - 1 ) / ppb;
|
|
|
|
|
2007-01-13 01:19:18 +01:00
|
|
|
|
2005-05-25 07:51:01 +02:00
|
|
|
for ( i = 0; i < bitmap->rows; i++ )
|
|
|
|
FT_MEM_COPY( buffer + new_pitch * ( ypixels + i ),
|
2007-01-13 01:19:18 +01:00
|
|
|
bitmap->buffer + pitch * i, len );
|
2005-05-25 07:51:01 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-01-13 01:19:18 +01:00
|
|
|
FT_Int len = ( width + ppb - 1 ) / ppb;
|
|
|
|
|
2007-01-13 08:34:23 +01:00
|
|
|
|
2005-05-25 07:51:01 +02:00
|
|
|
for ( i = 0; i < bitmap->rows; i++ )
|
|
|
|
FT_MEM_COPY( buffer + new_pitch * i,
|
2007-01-13 01:19:18 +01:00
|
|
|
bitmap->buffer + pitch * i, len );
|
2005-05-25 07:51:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
FT_FREE( bitmap->buffer );
|
|
|
|
bitmap->buffer = buffer;
|
|
|
|
|
|
|
|
if ( bitmap->pitch < 0 )
|
|
|
|
new_pitch = -new_pitch;
|
|
|
|
|
|
|
|
/* set pitch only */
|
|
|
|
bitmap->pitch = new_pitch;
|
|
|
|
|
|
|
|
return FT_Err_Ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* documentation is in ftbitmap.h */
|
|
|
|
|
|
|
|
FT_EXPORT_DEF( FT_Error )
|
|
|
|
FT_Bitmap_Embolden( FT_Library library,
|
|
|
|
FT_Bitmap* bitmap,
|
|
|
|
FT_Pos xStrength,
|
|
|
|
FT_Pos yStrength )
|
|
|
|
{
|
|
|
|
FT_Error error;
|
|
|
|
unsigned char* p;
|
|
|
|
FT_Int i, x, y, pitch;
|
|
|
|
FT_Int xstr, ystr;
|
|
|
|
|
|
|
|
|
|
|
|
if ( !library )
|
|
|
|
return FT_Err_Invalid_Library_Handle;
|
|
|
|
|
2005-05-30 21:22:44 +02:00
|
|
|
if ( !bitmap || !bitmap->buffer )
|
2005-05-25 07:51:01 +02:00
|
|
|
return FT_Err_Invalid_Argument;
|
|
|
|
|
2005-05-30 09:54:20 +02:00
|
|
|
xstr = FT_PIX_ROUND( xStrength ) >> 6;
|
|
|
|
ystr = FT_PIX_ROUND( yStrength ) >> 6;
|
|
|
|
|
2005-05-30 21:22:44 +02:00
|
|
|
if ( xstr == 0 && ystr == 0 )
|
|
|
|
return FT_Err_Ok;
|
|
|
|
else if ( xstr < 0 || ystr < 0 )
|
|
|
|
return FT_Err_Invalid_Argument;
|
|
|
|
|
2005-05-25 07:51:01 +02:00
|
|
|
switch ( bitmap->pixel_mode )
|
|
|
|
{
|
|
|
|
case FT_PIXEL_MODE_GRAY2:
|
|
|
|
case FT_PIXEL_MODE_GRAY4:
|
2005-05-30 21:22:44 +02:00
|
|
|
{
|
|
|
|
FT_Bitmap tmp;
|
|
|
|
FT_Int align;
|
|
|
|
|
|
|
|
|
|
|
|
if ( bitmap->pixel_mode == FT_PIXEL_MODE_GRAY2 )
|
|
|
|
align = ( bitmap->width + xstr + 3 ) / 4;
|
|
|
|
else
|
|
|
|
align = ( bitmap->width + xstr + 1 ) / 2;
|
|
|
|
|
|
|
|
FT_Bitmap_New( &tmp );
|
|
|
|
error = FT_Bitmap_Convert( library, bitmap, &tmp, align );
|
|
|
|
|
|
|
|
if ( error )
|
|
|
|
return error;
|
|
|
|
|
|
|
|
FT_Bitmap_Done( library, bitmap );
|
|
|
|
*bitmap = tmp;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FT_PIXEL_MODE_MONO:
|
|
|
|
if ( xstr > 8 )
|
|
|
|
xstr = 8;
|
|
|
|
break;
|
|
|
|
|
2005-05-30 09:54:20 +02:00
|
|
|
case FT_PIXEL_MODE_LCD:
|
|
|
|
xstr *= 3;
|
|
|
|
break;
|
2005-05-30 21:22:44 +02:00
|
|
|
|
2005-05-30 09:54:20 +02:00
|
|
|
case FT_PIXEL_MODE_LCD_V:
|
|
|
|
ystr *= 3;
|
|
|
|
break;
|
2005-05-25 07:51:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
error = ft_bitmap_assure_buffer( library->memory, bitmap, xstr, ystr );
|
|
|
|
if ( error )
|
|
|
|
return error;
|
|
|
|
|
|
|
|
pitch = bitmap->pitch;
|
|
|
|
if ( pitch > 0 )
|
|
|
|
p = bitmap->buffer + pitch * ystr;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pitch = -pitch;
|
2005-05-28 23:52:37 +02:00
|
|
|
p = bitmap->buffer + pitch * ( bitmap->rows - 1 );
|
2005-05-25 07:51:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* for each row */
|
|
|
|
for ( y = 0; y < bitmap->rows ; y++ )
|
|
|
|
{
|
2005-06-30 13:46:46 +02:00
|
|
|
/*
|
2005-05-25 07:51:01 +02:00
|
|
|
* Horizontally:
|
|
|
|
*
|
|
|
|
* From the last pixel on, make each pixel or'ed with the
|
|
|
|
* `xstr' pixels before it.
|
|
|
|
*/
|
|
|
|
for ( x = pitch - 1; x >= 0; x-- )
|
|
|
|
{
|
|
|
|
unsigned char tmp;
|
|
|
|
|
|
|
|
|
|
|
|
tmp = p[x];
|
|
|
|
for ( i = 1; i <= xstr; i++ )
|
|
|
|
{
|
|
|
|
if ( bitmap->pixel_mode == FT_PIXEL_MODE_MONO )
|
|
|
|
{
|
|
|
|
p[x] |= tmp >> i;
|
|
|
|
|
|
|
|
/* the maximum value of 8 for `xstr' comes from here */
|
|
|
|
if ( x > 0 )
|
|
|
|
p[x] |= p[x - 1] << ( 8 - i );
|
2005-05-28 23:52:37 +02:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
if ( p[x] == 0xff )
|
|
|
|
break;
|
|
|
|
#endif
|
2005-05-25 07:51:01 +02:00
|
|
|
}
|
2005-05-30 09:54:20 +02:00
|
|
|
else
|
2005-05-25 07:51:01 +02:00
|
|
|
{
|
|
|
|
if ( x - i >= 0 )
|
|
|
|
{
|
2005-05-30 09:54:20 +02:00
|
|
|
if ( p[x] + p[x - i] > bitmap->num_grays - 1 )
|
2005-05-28 23:52:37 +02:00
|
|
|
{
|
2005-06-30 13:46:46 +02:00
|
|
|
p[x] = (unsigned char)(bitmap->num_grays - 1);
|
2005-05-28 23:52:37 +02:00
|
|
|
break;
|
|
|
|
}
|
2005-05-25 07:51:01 +02:00
|
|
|
else
|
2005-05-28 23:52:37 +02:00
|
|
|
{
|
2005-06-30 13:46:46 +02:00
|
|
|
p[x] = (unsigned char)(p[x] + p[x-i]);
|
2005-05-30 09:54:20 +02:00
|
|
|
if ( p[x] == bitmap->num_grays - 1 )
|
2005-05-28 23:52:37 +02:00
|
|
|
break;
|
|
|
|
}
|
2005-05-25 07:51:01 +02:00
|
|
|
}
|
2005-05-28 23:52:37 +02:00
|
|
|
else
|
|
|
|
break;
|
2005-05-25 07:51:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-06-30 13:46:46 +02:00
|
|
|
/*
|
2005-05-25 07:51:01 +02:00
|
|
|
* Vertically:
|
|
|
|
*
|
|
|
|
* Make the above `ystr' rows or'ed with it.
|
|
|
|
*/
|
|
|
|
for ( x = 1; x <= ystr; x++ )
|
|
|
|
{
|
|
|
|
unsigned char* q;
|
|
|
|
|
|
|
|
|
|
|
|
q = p - bitmap->pitch * x;
|
|
|
|
for ( i = 0; i < pitch; i++ )
|
|
|
|
q[i] |= p[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
p += bitmap->pitch;
|
|
|
|
}
|
|
|
|
|
|
|
|
bitmap->width += xstr;
|
|
|
|
bitmap->rows += ystr;
|
|
|
|
|
|
|
|
return FT_Err_Ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-12-14 17:01:29 +01:00
|
|
|
/* documentation is in ftbitmap.h */
|
|
|
|
|
|
|
|
FT_EXPORT_DEF( FT_Error )
|
|
|
|
FT_Bitmap_Convert( FT_Library library,
|
|
|
|
const FT_Bitmap *source,
|
|
|
|
FT_Bitmap *target,
|
|
|
|
FT_Int alignment )
|
|
|
|
{
|
2004-12-28 08:31:35 +01:00
|
|
|
FT_Error error = FT_Err_Ok;
|
2004-12-14 17:01:29 +01:00
|
|
|
FT_Memory memory;
|
|
|
|
|
|
|
|
|
|
|
|
if ( !library )
|
|
|
|
return FT_Err_Invalid_Library_Handle;
|
|
|
|
|
|
|
|
memory = library->memory;
|
|
|
|
|
|
|
|
switch ( source->pixel_mode )
|
|
|
|
{
|
|
|
|
case FT_PIXEL_MODE_MONO:
|
|
|
|
case FT_PIXEL_MODE_GRAY:
|
|
|
|
case FT_PIXEL_MODE_GRAY2:
|
|
|
|
case FT_PIXEL_MODE_GRAY4:
|
2005-02-10 17:11:29 +01:00
|
|
|
{
|
|
|
|
FT_Int pad;
|
|
|
|
FT_Long old_size;
|
|
|
|
|
2005-02-10 17:59:37 +01:00
|
|
|
|
2005-02-10 17:11:29 +01:00
|
|
|
old_size = target->rows * target->pitch;
|
|
|
|
if ( old_size < 0 )
|
|
|
|
old_size = -old_size;
|
|
|
|
|
|
|
|
target->pixel_mode = FT_PIXEL_MODE_GRAY;
|
|
|
|
target->rows = source->rows;
|
|
|
|
target->width = source->width;
|
2004-12-14 17:01:29 +01:00
|
|
|
|
2005-02-10 17:11:29 +01:00
|
|
|
pad = 0;
|
|
|
|
if ( alignment > 0 )
|
|
|
|
{
|
|
|
|
pad = source->width % alignment;
|
|
|
|
if ( pad != 0 )
|
|
|
|
pad = alignment - pad;
|
|
|
|
}
|
2004-12-14 17:01:29 +01:00
|
|
|
|
2005-02-10 17:11:29 +01:00
|
|
|
target->pitch = source->width + pad;
|
|
|
|
|
2005-02-10 17:59:37 +01:00
|
|
|
if ( target->rows * target->pitch > old_size &&
|
2005-02-10 17:11:29 +01:00
|
|
|
FT_QREALLOC( target->buffer,
|
2004-12-14 17:01:29 +01:00
|
|
|
old_size, target->rows * target->pitch ) )
|
|
|
|
return error;
|
2005-02-10 17:11:29 +01:00
|
|
|
}
|
2004-12-14 17:01:29 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
error = FT_Err_Invalid_Argument;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ( source->pixel_mode )
|
|
|
|
{
|
|
|
|
case FT_PIXEL_MODE_MONO:
|
|
|
|
{
|
2005-02-10 17:11:29 +01:00
|
|
|
FT_Byte* s = source->buffer;
|
|
|
|
FT_Byte* t = target->buffer;
|
|
|
|
FT_Int i;
|
2004-12-14 17:01:29 +01:00
|
|
|
|
2005-02-10 17:59:37 +01:00
|
|
|
|
2005-02-10 17:11:29 +01:00
|
|
|
target->num_grays = 2;
|
2004-12-14 17:01:29 +01:00
|
|
|
|
2005-02-10 17:11:29 +01:00
|
|
|
for ( i = source->rows; i > 0; i-- )
|
2004-12-14 17:01:29 +01:00
|
|
|
{
|
2005-02-10 17:11:29 +01:00
|
|
|
FT_Byte* ss = s;
|
|
|
|
FT_Byte* tt = t;
|
|
|
|
FT_Int j;
|
|
|
|
|
2005-02-10 17:59:37 +01:00
|
|
|
|
2005-02-10 17:11:29 +01:00
|
|
|
/* get the full bytes */
|
|
|
|
for ( j = source->width >> 3; j > 0; j-- )
|
|
|
|
{
|
|
|
|
FT_Int val = ss[0]; /* avoid a byte->int cast on each line */
|
|
|
|
|
2005-02-10 17:59:37 +01:00
|
|
|
|
2005-02-10 17:11:29 +01:00
|
|
|
tt[0] = (FT_Byte)( ( val & 0x80 ) >> 7 );
|
|
|
|
tt[1] = (FT_Byte)( ( val & 0x40 ) >> 6 );
|
|
|
|
tt[2] = (FT_Byte)( ( val & 0x20 ) >> 5 );
|
|
|
|
tt[3] = (FT_Byte)( ( val & 0x10 ) >> 4 );
|
|
|
|
tt[4] = (FT_Byte)( ( val & 0x08 ) >> 3 );
|
|
|
|
tt[5] = (FT_Byte)( ( val & 0x04 ) >> 2 );
|
|
|
|
tt[6] = (FT_Byte)( ( val & 0x02 ) >> 1 );
|
|
|
|
tt[7] = (FT_Byte)( val & 0x01 );
|
|
|
|
|
|
|
|
tt += 8;
|
|
|
|
ss += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get remaining pixels (if any) */
|
|
|
|
j = source->width & 7;
|
|
|
|
if ( j > 0 )
|
|
|
|
{
|
|
|
|
FT_Int val = *ss;
|
|
|
|
|
2005-02-10 17:59:37 +01:00
|
|
|
|
2005-02-10 17:11:29 +01:00
|
|
|
for ( ; j > 0; j-- )
|
|
|
|
{
|
2005-02-10 17:59:37 +01:00
|
|
|
tt[0] = (FT_Byte)( ( val & 0x80 ) >> 7);
|
2005-02-10 17:11:29 +01:00
|
|
|
val <<= 1;
|
|
|
|
tt += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
s += source->pitch;
|
|
|
|
t += target->pitch;
|
2004-12-14 17:01:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
2005-02-10 17:11:29 +01:00
|
|
|
case FT_PIXEL_MODE_GRAY:
|
2004-12-14 17:01:29 +01:00
|
|
|
{
|
2005-02-10 17:11:29 +01:00
|
|
|
FT_Int width = source->width;
|
|
|
|
FT_Byte* s = source->buffer;
|
|
|
|
FT_Byte* t = target->buffer;
|
|
|
|
FT_Int s_pitch = source->pitch;
|
|
|
|
FT_Int t_pitch = target->pitch;
|
|
|
|
FT_Int i;
|
2004-12-14 17:01:29 +01:00
|
|
|
|
2005-02-10 17:59:37 +01:00
|
|
|
|
2005-02-10 17:11:29 +01:00
|
|
|
target->num_grays = 256;
|
|
|
|
|
|
|
|
for ( i = source->rows; i > 0; i-- )
|
|
|
|
{
|
|
|
|
FT_ARRAY_COPY( t, s, width );
|
2004-12-14 17:01:29 +01:00
|
|
|
|
2005-02-10 17:11:29 +01:00
|
|
|
s += s_pitch;
|
|
|
|
t += t_pitch;
|
|
|
|
}
|
2004-12-14 17:01:29 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
2005-02-10 17:11:29 +01:00
|
|
|
case FT_PIXEL_MODE_GRAY2:
|
2004-12-14 17:01:29 +01:00
|
|
|
{
|
2005-02-10 17:11:29 +01:00
|
|
|
FT_Byte* s = source->buffer;
|
|
|
|
FT_Byte* t = target->buffer;
|
|
|
|
FT_Int i;
|
2004-12-14 17:01:29 +01:00
|
|
|
|
2005-02-10 17:59:37 +01:00
|
|
|
|
2005-02-10 17:11:29 +01:00
|
|
|
target->num_grays = 4;
|
2004-12-14 17:01:29 +01:00
|
|
|
|
2005-02-10 17:11:29 +01:00
|
|
|
for ( i = source->rows; i > 0; i-- )
|
2004-12-14 17:01:29 +01:00
|
|
|
{
|
2005-02-10 17:11:29 +01:00
|
|
|
FT_Byte* ss = s;
|
|
|
|
FT_Byte* tt = t;
|
|
|
|
FT_Int j;
|
|
|
|
|
2005-02-10 17:59:37 +01:00
|
|
|
|
2005-02-10 17:11:29 +01:00
|
|
|
/* get the full bytes */
|
|
|
|
for ( j = source->width >> 2; j > 0; j-- )
|
|
|
|
{
|
|
|
|
FT_Int val = ss[0];
|
|
|
|
|
2005-02-10 17:59:37 +01:00
|
|
|
|
|
|
|
tt[0] = (FT_Byte)( ( val & 0xC0 ) >> 6 );
|
|
|
|
tt[1] = (FT_Byte)( ( val & 0x30 ) >> 4 );
|
|
|
|
tt[2] = (FT_Byte)( ( val & 0x0C ) >> 2 );
|
|
|
|
tt[3] = (FT_Byte)( ( val & 0x03 ) );
|
2005-02-10 17:11:29 +01:00
|
|
|
|
|
|
|
ss += 1;
|
|
|
|
tt += 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
j = source->width & 3;
|
|
|
|
if ( j > 0 )
|
|
|
|
{
|
|
|
|
FT_Int val = ss[0];
|
|
|
|
|
2005-02-10 17:59:37 +01:00
|
|
|
|
2005-02-10 17:11:29 +01:00
|
|
|
for ( ; j > 0; j-- )
|
|
|
|
{
|
|
|
|
tt[0] = (FT_Byte)( ( val & 0xC0 ) >> 6 );
|
|
|
|
val <<= 2;
|
|
|
|
tt += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
s += source->pitch;
|
|
|
|
t += target->pitch;
|
2004-12-14 17:01:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
2005-02-10 17:11:29 +01:00
|
|
|
case FT_PIXEL_MODE_GRAY4:
|
2004-12-14 17:01:29 +01:00
|
|
|
{
|
2005-02-10 17:11:29 +01:00
|
|
|
FT_Byte* s = source->buffer;
|
|
|
|
FT_Byte* t = target->buffer;
|
|
|
|
FT_Int i;
|
2004-12-14 17:01:29 +01:00
|
|
|
|
2005-02-10 17:59:37 +01:00
|
|
|
|
2005-02-10 17:11:29 +01:00
|
|
|
target->num_grays = 16;
|
|
|
|
|
|
|
|
for ( i = source->rows; i > 0; i-- )
|
2004-12-14 17:01:29 +01:00
|
|
|
{
|
2005-02-10 17:11:29 +01:00
|
|
|
FT_Byte* ss = s;
|
|
|
|
FT_Byte* tt = t;
|
|
|
|
FT_Int j;
|
2004-12-14 17:01:29 +01:00
|
|
|
|
2005-02-10 17:59:37 +01:00
|
|
|
|
2005-02-10 17:11:29 +01:00
|
|
|
/* get the full bytes */
|
|
|
|
for ( j = source->width >> 1; j > 0; j-- )
|
|
|
|
{
|
|
|
|
FT_Int val = ss[0];
|
2004-12-14 17:01:29 +01:00
|
|
|
|
2005-02-10 17:59:37 +01:00
|
|
|
|
|
|
|
tt[0] = (FT_Byte)( ( val & 0xF0 ) >> 4 );
|
|
|
|
tt[1] = (FT_Byte)( ( val & 0x0F ) );
|
2004-12-14 17:01:29 +01:00
|
|
|
|
2005-02-10 17:11:29 +01:00
|
|
|
ss += 1;
|
|
|
|
tt += 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( source->width & 1 )
|
|
|
|
tt[0] = (FT_Byte)( ( ss[0] & 0xF0 ) >> 4 );
|
|
|
|
|
|
|
|
s += source->pitch;
|
|
|
|
t += target->pitch;
|
|
|
|
}
|
2004-12-14 17:01:29 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2005-02-10 17:59:37 +01:00
|
|
|
|
2005-02-10 17:11:29 +01:00
|
|
|
default:
|
|
|
|
;
|
2004-12-14 17:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* documentation is in ftbitmap.h */
|
|
|
|
|
|
|
|
FT_EXPORT_DEF( FT_Error )
|
|
|
|
FT_Bitmap_Done( FT_Library library,
|
|
|
|
FT_Bitmap *bitmap )
|
|
|
|
{
|
|
|
|
FT_Memory memory;
|
|
|
|
|
|
|
|
|
|
|
|
if ( !library )
|
|
|
|
return FT_Err_Invalid_Library_Handle;
|
|
|
|
|
|
|
|
if ( !bitmap )
|
|
|
|
return FT_Err_Invalid_Argument;
|
|
|
|
|
|
|
|
memory = library->memory;
|
|
|
|
|
|
|
|
FT_FREE( bitmap->buffer );
|
|
|
|
*bitmap = null_bitmap;
|
|
|
|
|
|
|
|
return FT_Err_Ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* END */
|