mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-02-22 23:00:36 +03:00
Minor changes
This commit is contained in:
parent
2cc5893d87
commit
a05be82920
|
@ -163,9 +163,9 @@ def _get_texture_size(pixel_format: VtfPF, width, height):
|
|||
return width * height
|
||||
elif pixel_format in LA_FORMATS:
|
||||
return width * height * 2
|
||||
elif pixel_format in (VtfPF.RGB888,):
|
||||
elif pixel_format == VtfPF.RGB888:
|
||||
return width * height * 3
|
||||
elif pixel_format in (VtfPF.RGBA8888,):
|
||||
elif pixel_format == VtfPF.RGBA8888:
|
||||
return width * height * 4
|
||||
raise VTFException(f"Unsupported VTF pixel format: {pixel_format}")
|
||||
|
||||
|
@ -205,7 +205,7 @@ class VtfImageFile(ImageFile.ImageFile):
|
|||
0,
|
||||
)
|
||||
self.fp.seek(header.header_size)
|
||||
elif (7, 2) <= version < (7, 3):
|
||||
elif version < (7, 3):
|
||||
header = VTFHeader(
|
||||
*struct.unpack(HEADER_V72, self.fp.read(struct.calcsize(HEADER_V72))),
|
||||
0,
|
||||
|
@ -214,7 +214,7 @@ class VtfImageFile(ImageFile.ImageFile):
|
|||
0,
|
||||
)
|
||||
self.fp.seek(header.header_size)
|
||||
elif (7, 3) <= version < (7, 5):
|
||||
elif version < (7, 5):
|
||||
header = VTFHeader(
|
||||
*struct.unpack(HEADER_V73, self.fp.read(struct.calcsize(HEADER_V73)))
|
||||
)
|
||||
|
@ -270,9 +270,9 @@ def _save(im, fp, filename):
|
|||
im: Image.Image
|
||||
if im.mode not in ("RGB", "RGBA"):
|
||||
raise OSError(f"cannot write mode {im.mode} as VTF")
|
||||
arguments = im.encoderinfo
|
||||
pixel_format = VtfPF(arguments.get("pixel_format", VtfPF.RGBA8888))
|
||||
version = arguments.get("version", (7, 4))
|
||||
encoderinfo = im.encoderinfo
|
||||
pixel_format = VtfPF(encoderinfo.get("pixel_format", VtfPF.RGBA8888))
|
||||
version = encoderinfo.get("version", (7, 4))
|
||||
flags = CompiledVtfFlags(0)
|
||||
if "A" in im.mode:
|
||||
if pixel_format == VtfPF.DXT1_ONEBITALPHA:
|
||||
|
|
|
@ -376,7 +376,7 @@ get_packer(ImagingEncoderObject *encoder, const char *mode, const char *rawmode)
|
|||
}
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/* BNC */
|
||||
/* BCN */
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
PyObject *
|
||||
|
|
|
@ -77,9 +77,11 @@ selection_sort(Color arr[], UINT32 n) {
|
|||
|
||||
for (i = 0; i < n - 1; i++) {
|
||||
min_idx = i;
|
||||
for (j = i + 1; j < n; j++)
|
||||
if (arr[j].frequency < arr[min_idx].frequency)
|
||||
for (j = i + 1; j < n; j++) {
|
||||
if (arr[j].frequency < arr[min_idx].frequency) {
|
||||
min_idx = j;
|
||||
}
|
||||
}
|
||||
SWAP(Color, arr[min_idx], arr[i]);
|
||||
}
|
||||
}
|
||||
|
@ -103,8 +105,9 @@ pick_2_major_colors(
|
|||
|
||||
if (color_count == 1) {
|
||||
*color1 = colors[color_count - 1].value;
|
||||
} else
|
||||
} else {
|
||||
*color1 = colors[color_count - 2].value;
|
||||
}
|
||||
}
|
||||
|
||||
static UINT8
|
||||
|
@ -131,8 +134,9 @@ encode_bc1(Imaging im, ImagingCodecState state, UINT8 *buf, int bytes) {
|
|||
bc1_color *blocks = (bc1_color *)buf;
|
||||
UINT8 no_alpha = 0;
|
||||
INT32 block_index;
|
||||
if (strchr(im->mode, 'A') == NULL)
|
||||
if (strchr(im->mode, 'A') == NULL) {
|
||||
no_alpha = 1;
|
||||
}
|
||||
UINT32 block_count = (im->xsize * im->ysize) / 16;
|
||||
if (block_count * sizeof(bc1_color) > bytes) {
|
||||
state->errcode = IMAGING_CODEC_MEMORY;
|
||||
|
@ -185,8 +189,9 @@ encode_bc1(Imaging im, ImagingCodecState state, UINT8 *buf, int bytes) {
|
|||
|
||||
UINT16 c0 = 0, c1 = 0;
|
||||
pick_2_major_colors(unique_colors, color_frequency, unique_count, &c0, &c1);
|
||||
if (c0 < c1 && no_alpha)
|
||||
if (c0 < c1 && no_alpha) {
|
||||
SWAP(UINT16, c0, c1);
|
||||
}
|
||||
|
||||
UINT16 palette[4] = {c0, c1, 0, 0};
|
||||
if (no_alpha) {
|
||||
|
@ -203,10 +208,11 @@ encode_bc1(Imaging im, ImagingCodecState state, UINT8 *buf, int bytes) {
|
|||
UINT32 color_id;
|
||||
for (color_id = 0; color_id < 16; ++color_id) {
|
||||
UINT8 bc_color_id;
|
||||
if (opaque[color_id] || no_alpha)
|
||||
if (opaque[color_id] || no_alpha) {
|
||||
bc_color_id = get_closest_color_index(palette, all_colors[color_id]);
|
||||
else
|
||||
} else {
|
||||
bc_color_id = 3;
|
||||
}
|
||||
SET_BITS(block->lut, color_id * 2, 2, bc_color_id);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user