Skip to content

Commit df129de

Browse files
committed
Minor changes
1 parent 25e1f4c commit df129de

File tree

3 files changed

+21
-15
lines changed

3 files changed

+21
-15
lines changed

src/PIL/VtfImagePlugin.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,9 @@ def _get_texture_size(pixel_format: VtfPF, width, height):
163163
return width * height
164164
elif pixel_format in LA_FORMATS:
165165
return width * height * 2
166-
elif pixel_format in (VtfPF.RGB888,):
166+
elif pixel_format == VtfPF.RGB888:
167167
return width * height * 3
168-
elif pixel_format in (VtfPF.RGBA8888,):
168+
elif pixel_format == VtfPF.RGBA8888:
169169
return width * height * 4
170170
raise VTFException(f"Unsupported VTF pixel format: {pixel_format}")
171171

@@ -205,7 +205,7 @@ def _open(self):
205205
0,
206206
)
207207
self.fp.seek(header.header_size)
208-
elif (7, 2) <= version < (7, 3):
208+
elif version < (7, 3):
209209
header = VTFHeader(
210210
*struct.unpack(HEADER_V72, self.fp.read(struct.calcsize(HEADER_V72))),
211211
0,
@@ -214,7 +214,7 @@ def _open(self):
214214
0,
215215
)
216216
self.fp.seek(header.header_size)
217-
elif (7, 3) <= version < (7, 5):
217+
elif version < (7, 5):
218218
header = VTFHeader(
219219
*struct.unpack(HEADER_V73, self.fp.read(struct.calcsize(HEADER_V73)))
220220
)
@@ -270,9 +270,9 @@ def _save(im, fp, filename):
270270
im: Image.Image
271271
if im.mode not in ("RGB", "RGBA"):
272272
raise OSError(f"cannot write mode {im.mode} as VTF")
273-
arguments = im.encoderinfo
274-
pixel_format = VtfPF(arguments.get("pixel_format", VtfPF.RGBA8888))
275-
version = arguments.get("version", (7, 4))
273+
encoderinfo = im.encoderinfo
274+
pixel_format = VtfPF(encoderinfo.get("pixel_format", VtfPF.RGBA8888))
275+
version = encoderinfo.get("version", (7, 4))
276276
flags = CompiledVtfFlags(0)
277277
if "A" in im.mode:
278278
if pixel_format == VtfPF.DXT1_ONEBITALPHA:

src/encode.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ get_packer(ImagingEncoderObject *encoder, const char *mode, const char *rawmode)
376376
}
377377

378378
/* -------------------------------------------------------------------- */
379-
/* BNC */
379+
/* BCN */
380380
/* -------------------------------------------------------------------- */
381381

382382
PyObject *

src/libImaging/BcnEncode.c

+13-7
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,11 @@ selection_sort(Color arr[], UINT32 n) {
7777

7878
for (i = 0; i < n - 1; i++) {
7979
min_idx = i;
80-
for (j = i + 1; j < n; j++)
81-
if (arr[j].frequency < arr[min_idx].frequency)
80+
for (j = i + 1; j < n; j++) {
81+
if (arr[j].frequency < arr[min_idx].frequency) {
8282
min_idx = j;
83+
}
84+
}
8385
SWAP(Color, arr[min_idx], arr[i]);
8486
}
8587
}
@@ -103,8 +105,9 @@ pick_2_major_colors(
103105

104106
if (color_count == 1) {
105107
*color1 = colors[color_count - 1].value;
106-
} else
108+
} else {
107109
*color1 = colors[color_count - 2].value;
110+
}
108111
}
109112

110113
static UINT8
@@ -131,8 +134,9 @@ encode_bc1(Imaging im, ImagingCodecState state, UINT8 *buf, int bytes) {
131134
bc1_color *blocks = (bc1_color *)buf;
132135
UINT8 no_alpha = 0;
133136
INT32 block_index;
134-
if (strchr(im->mode, 'A') == NULL)
137+
if (strchr(im->mode, 'A') == NULL) {
135138
no_alpha = 1;
139+
}
136140
UINT32 block_count = (im->xsize * im->ysize) / 16;
137141
if (block_count * sizeof(bc1_color) > bytes) {
138142
state->errcode = IMAGING_CODEC_MEMORY;
@@ -185,8 +189,9 @@ encode_bc1(Imaging im, ImagingCodecState state, UINT8 *buf, int bytes) {
185189

186190
UINT16 c0 = 0, c1 = 0;
187191
pick_2_major_colors(unique_colors, color_frequency, unique_count, &c0, &c1);
188-
if (c0 < c1 && no_alpha)
192+
if (c0 < c1 && no_alpha) {
189193
SWAP(UINT16, c0, c1);
194+
}
190195

191196
UINT16 palette[4] = {c0, c1, 0, 0};
192197
if (no_alpha) {
@@ -203,10 +208,11 @@ encode_bc1(Imaging im, ImagingCodecState state, UINT8 *buf, int bytes) {
203208
UINT32 color_id;
204209
for (color_id = 0; color_id < 16; ++color_id) {
205210
UINT8 bc_color_id;
206-
if (opaque[color_id] || no_alpha)
211+
if (opaque[color_id] || no_alpha) {
207212
bc_color_id = get_closest_color_index(palette, all_colors[color_id]);
208-
else
213+
} else {
209214
bc_color_id = 3;
215+
}
210216
SET_BITS(block->lut, color_id * 2, 2, bc_color_id);
211217
}
212218
}

0 commit comments

Comments
 (0)