Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STY: Change variable names #3077

Merged
merged 5 commits into from
Jan 27, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
STY: Change variable names
Make it obvious that "mode" is the new value of "prev_mode". Also change "by" to "byte_buffer" for better readability.
j-t-1 authored Jan 25, 2025
commit d3f89ca1544aeddbddb45ab0e5d47cb0c1cff0b7
20 changes: 10 additions & 10 deletions pypdf/_xobj_image_helpers.py
Original file line number Diff line number Diff line change
@@ -103,7 +103,7 @@ def _get_imagemode(
)
return mode, invert_color

mode_map = {
mode_map: Dict[str, mode_str_type] = {
"1bit": "1", # pos [0] will be used for 1 bit
"/DeviceGray": "L", # must be in pos [1]
"palette": "P", # must be in pos [2] for color_components align.
@@ -112,30 +112,30 @@ def _get_imagemode(
"2bit": "2bits", # 2 bits images
"4bit": "4bits", # 4 bits
}
mode_: mode_str_type = (
mode_map.get(color_space) # type: ignore
mode = (
mode_map.get(color_space)
or list(mode_map.values())[color_components]
or prev_mode
)
return mode_, mode_ == "CMYK"
return mode, mode == "CMYK"


def bits2byte(data: bytes, size: Tuple[int, int], bits: int) -> bytes:
mask = (1 << bits) - 1
buff = bytearray(size[0] * size[1])
byt = 0
byte_buffer = bytearray(size[0] * size[1])
data_index = 0
bit = 8 - bits
for y in range(size[1]):
if bit != 8 - bits:
byt += 1
data_index += 1
bit = 8 - bits
for x in range(size[0]):
buff[x + y * size[0]] = (data[byt] >> bit) & mask
byte_buffer[x + y * size[0]] = (data[data_index] >> bit) & mask
bit -= bits
if bit < 0:
byt += 1
data_index += 1
bit = 8 - bits
return bytes(buff)
return bytes(byte_buffer)


def _extended_image_frombytes(