freetype
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[ft] Memory Stomp problem in FT_Embolden_Bitmap


From: Ted Packard
Subject: [ft] Memory Stomp problem in FT_Embolden_Bitmap
Date: Fri, 05 Jan 2007 15:46:44 -0500
User-agent: Thunderbird 1.5.0.9 (X11/20061206)

The code in FT_Embolden_Bitmap takes a bitmap and produces a bold version of it. I want to do this to use as an outline for my glyphs.

The code creates a new bitmap which may have a new pitch and then enters a loop to copy the data from the old bitmap to the new bitmap a scan line at a time.

However if there was extra padding in the original bitmap it's possible for the new bold bitmap to have a smaller pitch than the original bitmap. This is often the case if the original bitmap was produced by the monochrome Freetype renderer which pads bitmaps to a 16 bit boundary.

My fix is to compute the number of bytes to copy from the pixel width rather than just using the pitch.

    int nBytesToCopy = ( bitmap->width + ppb - 1 ) / ppb;
    if ( bitmap->pitch > 0 )
    {
      for ( i = 0; i < bitmap->rows; i++ )
        FT_MEM_COPY( buffer + new_pitch * ( ypixels + i ),
                     bitmap->buffer + pitch * i, nBytesToCopy );
    }
    else
    {
      for ( i = 0; i < bitmap->rows; i++ )
        FT_MEM_COPY( buffer + new_pitch * i,
                     bitmap->buffer + pitch * i, nBytesToCopy );
    }

What do you think ?

- Ted Packard







reply via email to

[Prev in Thread] Current Thread [Next in Thread]