MCPcopy Create free account
hub / github.com/pymupdf/PyMuPDF / set_pixel

Method set_pixel

src/__init__.py:14013–14036  ·  view source on GitHub ↗

Set color of pixel (x, y).

(self, x, y, color)

Source from the content-addressed store, hash-verified

14011 pm.m_internal.y = y
14012
14013 def set_pixel(self, x, y, color):
14014 """Set color of pixel (x, y)."""
14015 if g_use_extra:
14016 return extra.set_pixel(self.this.m_internal, x, y, color)
14017 pm = self.this
14018 if not _INRANGE(x, 0, pm.w() - 1) or not _INRANGE(y, 0, pm.h() - 1):
14019 raise ValueError( MSG_PIXEL_OUTSIDE)
14020 n = pm.n()
14021 for j in range(n):
14022 i = color[j]
14023 if not _INRANGE(i, 0, 255):
14024 raise ValueError( MSG_BAD_COLOR_SEQ)
14025 stride = mupdf.fz_pixmap_stride( pm)
14026 i = stride * y + n * x
14027 if 0:
14028 # Using a cached self._memory_view doesn't actually make much
14029 # difference to speed.
14030 if not self._memory_view:
14031 self._memory_view = self.samples_mv
14032 for j in range(n):
14033 self._memory_view[i + j] = color[j]
14034 else:
14035 for j in range(n):
14036 pm.fz_samples_set(i + j, color[j])
14037
14038 def set_rect(self, bbox, color):
14039 """Set color of all pixels in bbox."""

Callers 1

test_3050Function · 0.80

Calls 4

_INRANGEFunction · 0.85
wMethod · 0.80
hMethod · 0.80
nMethod · 0.45

Tested by 1

test_3050Function · 0.64