Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simply wrong code with cairo format_A1 for Bitmap.make_image_surface #1

Open
HinTak opened this issue Apr 23, 2017 · 2 comments
Open

Comments

@HinTak
Copy link

HinTak commented Apr 23, 2017

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
Copy link
Author

HinTak commented Apr 25, 2017

s-broken

Here is how the bug looks like.

@HinTak
Copy link
Author

HinTak commented Apr 25, 2017

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)

ldo/python_freetype_examples#1

@HinTak HinTak changed the title Simply wrong code with cairo format_a1 for Bitmap.make_image_surface Simply wrong code with cairo format_A1 for Bitmap.make_image_surface Apr 25, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant