Skip to content

Commit 546e60c

Browse files
committed
Support BGRA color bitmap
1 parent adc9efd commit 546e60c

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

bitmap_to_surface.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@
3333
3434
Limitation: Surface.create_for_data is not in the "python 3, pycairo < 1.11" combo.
3535
'''
36-
from freetype import FT_PIXEL_MODE_MONO, FT_PIXEL_MODE_GRAY, FT_Pointer, FT_Bitmap
36+
from freetype import FT_PIXEL_MODE_MONO, FT_PIXEL_MODE_GRAY, FT_PIXEL_MODE_BGRA, FT_Pointer, FT_Bitmap
3737
#from freetype import get_handle, FT_Bitmap_Init, FT_Bitmap_Convert, FT_Exception
3838

39-
from cairo import ImageSurface, FORMAT_A1, FORMAT_A8
40-
#from cairocffi import ImageSurface, FORMAT_A1, FORMAT_A8
39+
from cairo import ImageSurface, FORMAT_A1, FORMAT_A8, FORMAT_ARGB32
40+
#from cairocffi import ImageSurface, FORMAT_A1, FORMAT_A8, FORMAT_ARGB32
4141

4242
from array import array
4343
from ctypes import cast, memmove, CDLL, c_void_p, c_int, byref
@@ -67,6 +67,8 @@ def make_image_surface(bitmap, copy = True) :
6767
cairo_format = FORMAT_A1
6868
elif content.pixel_mode == FT_PIXEL_MODE_GRAY :
6969
cairo_format = FORMAT_A8
70+
elif content.pixel_mode == FT_PIXEL_MODE_BGRA : # small-endian
71+
cairo_format = FORMAT_ARGB32 # platform native
7072
else :
7173
raise NotImplementedError("unsupported bitmap format %d" % content.pixel_mode)
7274
src_pitch = content.pitch

0 commit comments

Comments
 (0)