python_freetype icon indicating copy to clipboard operation
python_freetype copied to clipboard

Simply wrong code with cairo format_A1 for Bitmap.make_image_surface

Open HinTak opened this issue 8 years ago • 2 comments

The code around line 3315 for Bitmap.make_image_surface is simply wrong:

...
        if self.pixel_mode == FT.PIXEL_MODE_MONO :
            cairo_format = cairo.FORMAT_A1
        elif self.pixel_mode == FT.PIXEL_MODE_GRAY :
            cairo_format = cairo.FORMAT_A8
...

Freetype pixel mode mono is most-significant bit first, while cairo format A1 is host order, and least-significant-bit first on small-endian platform, such as x86/x86_64.

HinTak avatar Apr 23 '17 05:04 HinTak

s-broken

Here is how the bug looks like.

HinTak avatar Apr 25 '17 02:04 HinTak

I have fixed this in my own code with libtiff successfully, though this seems non-ideal:

    # pillow/PIL itself requires libtiff so it is assumed to be around.
    # swap the bit-order from freetype's (MSB) to cairo's (host order) if needed
    if ( ( byteorder == 'little' ) and (pixel_mode == FT_PIXEL_MODE_MONO ) ):
        libtiff = CDLL("libtiff.so")
        libtiff.TIFFReverseBits.restype = None
        libtiff.TIFFReverseBits.argtypes = (c_void_p, c_int)
        libtiff.TIFFReverseBits(buffer.buffer_info()[0], buffer_size)

https://github.com/ldo/python_freetype_examples/issues/1

HinTak avatar Apr 25 '17 02:04 HinTak