| 13234 | |
| 13235 | |
| 13236 | class Pixmap: |
| 13237 | |
| 13238 | def __init__(self, *args): |
| 13239 | """ |
| 13240 | Pixmap(colorspace, irect, alpha) - empty pixmap. |
| 13241 | Pixmap(colorspace, src) - copy changing colorspace. |
| 13242 | Pixmap(src, width, height,[clip]) - scaled copy, float dimensions. |
| 13243 | Pixmap(src, alpha=1) - copy and add or drop alpha channel. |
| 13244 | Pixmap(filename) - from an image in a file. |
| 13245 | Pixmap(image) - from an image in memory (bytes). |
| 13246 | Pixmap(colorspace, width, height, samples, alpha) - from samples data. |
| 13247 | Pixmap(PDFdoc, xref) - from an image at xref in a PDF document. |
| 13248 | """ |
| 13249 | # Cache for property `self.samples_mv`. Set here so __del_() sees it if |
| 13250 | # we raise. |
| 13251 | # |
| 13252 | self._samples_mv = None |
| 13253 | |
| 13254 | # 2024-01-16: Experimental support for a memory-view of the underlying |
| 13255 | # data. Doesn't seem to make much difference to Pixmap.set_pixel() so |
| 13256 | # not currently used. |
| 13257 | self._memory_view = None |
| 13258 | |
| 13259 | if 0: |
| 13260 | pass |
| 13261 | |
| 13262 | elif args_match(args, |
| 13263 | (Colorspace, mupdf.FzColorspace), |
| 13264 | (mupdf.FzRect, mupdf.FzIrect, IRect, Rect, tuple) |
| 13265 | ): |
| 13266 | # create empty pixmap with colorspace and IRect |
| 13267 | cs, rect = args |
| 13268 | alpha = 0 |
| 13269 | pm = mupdf.fz_new_pixmap_with_bbox(cs, JM_irect_from_py(rect), mupdf.FzSeparations(0), alpha) |
| 13270 | self.this = pm |
| 13271 | |
| 13272 | elif args_match(args, |
| 13273 | (Colorspace, mupdf.FzColorspace), |
| 13274 | (mupdf.FzRect, mupdf.FzIrect, IRect, Rect, tuple), |
| 13275 | (int, bool) |
| 13276 | ): |
| 13277 | # create empty pixmap with colorspace and IRect |
| 13278 | cs, rect, alpha = args |
| 13279 | pm = mupdf.fz_new_pixmap_with_bbox(cs, JM_irect_from_py(rect), mupdf.FzSeparations(0), alpha) |
| 13280 | self.this = pm |
| 13281 | |
| 13282 | elif args_match(args, (Colorspace, mupdf.FzColorspace, type(None)), (Pixmap, mupdf.FzPixmap)): |
| 13283 | # copy pixmap, converting colorspace |
| 13284 | cs, spix = args |
| 13285 | if isinstance(cs, Colorspace): |
| 13286 | cs = cs.this |
| 13287 | elif cs is None: |
| 13288 | cs = mupdf.FzColorspace(None) |
| 13289 | if isinstance(spix, Pixmap): |
| 13290 | spix = spix.this |
| 13291 | if not mupdf.fz_pixmap_colorspace(spix).m_internal: |
| 13292 | raise ValueError( "source colorspace must not be None") |
| 13293 |
no outgoing calls
searching dependent graphs…