[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[ft] python_freetype Design: Bitmap Objects
From: |
Lawrence D'Oliveiro |
Subject: |
[ft] python_freetype Design: Bitmap Objects |
Date: |
Tue, 17 Feb 2015 20:37:40 +1300 |
It seems like the APIs for FT_Bitmap objects are not entirely public.
FT_Bitmap_New sets a Bitmap to null (zero dimensions, no pixel buffer
allocated). FT_Bitmap_Copy can allocate storage for the pixels, but
only to copy an existing non-null Bitmap. So there is no public API
call to allocate a user-specified amount storage for a Bitmap--not
storage that will be correctly disposed by FT_Bitmap_Done, at any rate.
However, FreeType will correctly copy pixels _from_ a user-supplied
Bitmap object without worrying where the storage is allocated. So my
Bitmap wrapper class allows the option of using a Python buffer array
<https://docs.python.org/3/library/array.html> for the pixel storage. I
provide methods “new_with_array” to allocate a Bitmap of specified
dimensions, and “copy_with_array” which will make a copy of a Bitmap
such that the storage is in an array. (The “copy” method wraps
FreeType’s FT_Bitmap_Copy routine to go the other way.) Since all access
(and disposal!) is managed through methods of my wrapper class, I can
handle all details of the difference between such Bitmaps and those with
storage managed by FreeType itself.
- [ft] python_freetype Design: Bitmap Objects,
Lawrence D'Oliveiro <=