Skip to content

Commit

Permalink
Allow specifying the color space using a parameter, #19
Browse files Browse the repository at this point in the history
Suggested by Lucie Anglade.
  • Loading branch information
takis committed Feb 16, 2024
1 parent 2bee054 commit 33c03c8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/common_use_cases.rst
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ Display inline QR-code image
y = 0
stream.transform(width, 0, 0, height, x, y)
# Add the 1-bit grayscale image inline in the PDF
stream.inline_image(width, height, 1, raw_data)
stream.inline_image(width, height, 'Gray', 1, raw_data)
stream.pop_state()
document.add_object(stream)
Expand Down
6 changes: 4 additions & 2 deletions pydyf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,13 +365,15 @@ def transform(self, a, b, c, d, e, f):
_to_bytes(a), _to_bytes(b), _to_bytes(c),
_to_bytes(d), _to_bytes(e), _to_bytes(f), b'cm')))

def inline_image(self, width, height, bpc, raw_data):
def inline_image(self, width, height, color_space, bpc, raw_data):
"""Add an inline image.
:param width: The width of the image.
:type width: :obj:`int`
:param height: The height of the image.
:type height: :obj:`int`
:param colorspace: The color space of the image, f.e. RGB, Gray.
:type colorspace: :obj:`str`
:param bpc: The bits per component. 1 for BW, 8 for grayscale.
:type bpc: :obj:`int`
:param raw_data: The raw pixel data.
Expand All @@ -390,7 +392,7 @@ def inline_image(self, width, height, bpc, raw_data):
b'/H', _to_bytes(height),
b'/BPC', _to_bytes(bpc),
b'/CS',
b'/DeviceGray',
b'/Device' + color_space.encode(),
b'/F',
b'[/A85 /Fl]' if self.compress else b'/A85',
b'/L', _to_bytes(len(enc_data) + 2),
Expand Down

0 comments on commit 33c03c8

Please sign in to comment.