1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336
|
/*
* Any bit blitters are not included in FreeType 1.x.
* Because bitmap glyph is visible for client aplictions and
* FreeType is not provide any text renderers.
*/
#include "xttblit.h"
/*
* SBit blitter
* Derived from ttsbit.c of FreeType 2 (with modifications)
*/
/***************************************************************************/
/* */
/* ttsbit.c */
/* */
/* TrueType and OpenType embedded bitmap support (body). */
/* */
/* Copyright 1996-1999 by */
/* 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. */
/* */
/* */
/* WARNING: This file should not be compiled directly, it is meant to be */
/* included in the source of several font drivers (i.e., the TTF */
/* and OTF drivers). */
/* */
/***************************************************************************/
static
void blit_stream( TT_Raster_Map* target,
TT_Byte* source,
TT_Int line_bits,
TT_Int height,
TT_Bool align,
TT_Int x_offset,
TT_Int y_offset,
TT_Bool inverted )
{
TT_Byte* line_buff;
TT_Int line_incr;
TT_Int start_incr;
TT_Int cursor_sign;
TT_UInt acc;
TT_Byte loaded;
TT_Int y;
/* first of all, compute starting write position */
if ( target->flow == TT_Flow_Down )
{
line_buff = (TT_Byte*)target->bitmap;
start_incr = target->cols;
}
else
{
line_buff = (TT_Byte*)target->bitmap + (target->rows-1)*target->cols;
start_incr = -target->cols;
}
/* We must set height when inverted is true */
if (inverted)
{
if (height < 0)
return;
line_incr = -target->cols;
}
else
line_incr = target->cols;
cursor_sign = (( target->flow == TT_Flow_Down ) ^ inverted ) ? 1 : -1;
/* preperation for clipping */
if ( x_offset > 0 )
line_buff += x_offset / 8;
if ( y_offset > 0 )
line_buff += y_offset * start_incr;
if ( height < 0 )
height = target->rows;
/*********************************************************************/
/* */
/* We use the extra-classic 'accumulator' trick to extract the */
/* bits from the source byte stream. */
/* */
/* Namely, the variable 'acc' is a 16-bit accumulator containing */
/* the last 'loaded' bits from the input stream. The bits are */
/* shifted to the upmost position in 'acc'.. */
/* */
acc = 0; /* clear accumulator */
loaded = 0; /* no bits were loaded */
/* clip */
if ( y_offset < 0 )
{
switch ( align )
{
TT_Int step;
case -1:
source -= ((TT_Int)( line_bits + 7 ) / 8 ) * y_offset;
break;
case 0:
step = ( - line_bits * y_offset ) & 7;
source += ( - line_bits * y_offset ) / 8;
if (step)
{
acc = ((TT_UShort)*source++) << (step+8);
loaded = 8 - step;
}
break;
default:
source += - align * y_offset;
break;
}
}
/* y axis */
for ( y = 0 ; y < height ; y++ )
{
TT_Byte* cur = line_buff; /* current write cursor */
TT_Int count = line_bits; /* number of bits to extract per line */
TT_Byte shift = x_offset & 7; /* current write shift */
TT_Byte space = 8 - shift;
TT_Byte* source_position = source;
TT_Int byte_count;
if ( x_offset >= 0 )
byte_count = x_offset / 8;
else
byte_count = ( x_offset - 7 ) / 8 ;
if (( y_offset + cursor_sign * y ) >= target->rows )
break;
/* x axis */
if ( byte_count < 0 )
{
TT_Int skip_byte = - byte_count - 1;
if (!skip_byte)
acc = loaded = 0;
source += skip_byte;
if (loaded < 8)
{
acc |= ((TT_UShort)*source++) << (8-loaded);
loaded += 8;
}
acc <<= space;
loaded -= space;
count += x_offset;
/* In this case, start cursor is always left-sided */
byte_count = 0;
shift = 0;
space = 8;
}
/* first of all, read individual source bytes */
if ( count >= 8 )
{
count -= 8;
#if 0
/* This part is not modified yet */
/* small speedups for trivial cases */
if ( loaded == 0 )
{
/* super trivial case :-) */
if ( shift == 0 )
{
do
{
*cur++ |= *source++;
count -= 8;
}
while (count >= 0);
}
/* otherwise .... */
else
{
TT_Byte cache = cur[0];
do
{
TT_Byte val = *source++;
cur[0] = cache | (val >> shift);
cache = val << space;
cur++;
count -= 8;
}
while (count >= 0);
cur[0] |= cache;
}
}
else /* normal cases */
#endif /* 0 */
{
do
{
TT_Byte val;
/* ensure that there are at least 8 bits in the accumulator */
if (loaded < 8)
{
acc |= ((TT_UShort)*source++) << (8-loaded);
loaded += 8;
}
/* now write one byte */
val = (TT_Byte)(acc >> 8);
if ( byte_count < target->cols )
{
cur[0] |= val >> shift;
if ( byte_count < target->cols - 1 )
cur[1] |= val << space;
}
cur++;
byte_count++;
acc <<= 8; /* remove bits from accumulator */
loaded -= 8;
count -= 8;
}
while ( count >= 0 );
}
/* restore 'count' to correct value */
count += 8;
}
/* now write remaining bits (count < 8) */
if ( count > 0 )
{
TT_Byte val;
/* ensure that there are at least 'count' bits in the accumulator */
if (loaded < count)
{
acc |= ((TT_UShort)*source++) << (8-loaded);
loaded += 8;
}
/* now write remaining bits */
val = ((TT_Byte)(acc >> 8)) & ~(0xFF >> count);
if ( byte_count < target->cols )
{
cur[0] |= val >> shift;
if ((count > space) && (byte_count < target->cols - 1))
cur[1] |= val << space;
}
acc <<= count;
loaded -= count;
}
/* now, skip to next line */
if ( align )
{
acc = loaded = 0; /* clear accumulator on byte-padded lines */
if ( align > 0 )
{
source_position += align;
source = source_position;
}
}
line_buff += line_incr;
}
}
/* */
/*
* This function is not included in FreeType 1 engine.
* Because SBit_Image is able to access from any applications directory.
*/
TT_Error XTT_Get_SBit_Bitmap( TT_Raster_Map* target,
TT_SBit_Image* source_sbit,
TT_Int x_offset,
TT_Int y_offset )
{
TT_Raster_Map* source = &source_sbit->map;
TT_Int inverted = 0;
TT_Int line_bits;
TT_Int height;
if ((target->flow != TT_Flow_Up) && (target->flow != TT_Flow_Down))
return TT_Err_Invalid_Argument;
/* calculate offset */
x_offset += ( source_sbit->metrics.bbox.xMin & -64 ) / 64;
x_offset *= source_sbit->bit_depth;
y_offset = target->rows
- ( y_offset + (( source_sbit->metrics.bbox.yMax + 63 ) & -64 ) / 64 );
inverted = (( source->flow * target->flow ) == -1 );
/* correct??? */
line_bits = source->width * source_sbit->bit_depth;
/* return if offsets are obvious mismatched */
if (( x_offset + line_bits < 0 ) ||
( x_offset >= target->width ) ||
( y_offset >= target->rows ) ||
( y_offset + source->rows < 0 ))
return TT_Err_Invalid_Argument;
/* return if the size of source is invalid */
if (( source->cols <= 0 ) ||
( source->rows <= 0 ) ||
( source->size <= 0 ))
return TT_Err_Invalid_Argument;
height = ( y_offset >= 0 ) ? source->rows : ( source->rows + y_offset );
blit_stream( target, source->bitmap, line_bits, height,
source->cols, x_offset, y_offset, inverted );
return TT_Err_Ok;
}
|