Skip to content

Commit c9086c2

Browse files
authored
ppmsave: remove explicit cast to target format (#4531)
This became unnecessary after PR #4516.
1 parent 659458c commit c9086c2

File tree

1 file changed

+14
-28
lines changed

1 file changed

+14
-28
lines changed

libvips/foreign/ppmsave.c

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -218,12 +218,11 @@ vips_foreign_save_ppm_build(VipsObject *object)
218218
VipsObjectClass *class = VIPS_OBJECT_GET_CLASS(object);
219219
VipsForeignSave *save = (VipsForeignSave *) object;
220220
VipsForeignSavePpm *ppm = (VipsForeignSavePpm *) object;
221-
VipsImage **t = (VipsImage **) vips_object_local_array(object, 5);
221+
VipsImage **t = (VipsImage **) vips_object_local_array(object, 4);
222222

223223
VipsImage *image;
224224
char *magic;
225225
char *date;
226-
VipsBandFormat target_format;
227226
VipsInterpretation target_interpretation;
228227
int target_bands;
229228

@@ -236,8 +235,8 @@ vips_foreign_save_ppm_build(VipsObject *object)
236235
*/
237236
if (vips_image_hasalpha(image)) {
238237
if (vips_flatten(image, &t[0],
239-
"background", save->background,
240-
NULL))
238+
"background", save->background,
239+
NULL))
241240
return -1;
242241
image = t[0];
243242
}
@@ -254,37 +253,27 @@ vips_foreign_save_ppm_build(VipsObject *object)
254253
case VIPS_FOREIGN_PPM_FORMAT_PBM:
255254
if (!vips_object_argument_isset(object, "bitdepth"))
256255
ppm->bitdepth = 1;
257-
target_format = VIPS_FORMAT_UCHAR;
258256
target_interpretation = VIPS_INTERPRETATION_B_W;
259257
target_bands = 1;
260258
break;
261259

262260
case VIPS_FOREIGN_PPM_FORMAT_PGM:
263-
if (image->BandFmt == VIPS_FORMAT_USHORT) {
261+
if (image->BandFmt == VIPS_FORMAT_USHORT)
264262
target_interpretation = VIPS_INTERPRETATION_GREY16;
265-
target_format = VIPS_FORMAT_USHORT;
266-
}
267-
else {
263+
else
268264
target_interpretation = VIPS_INTERPRETATION_B_W;
269-
target_format = VIPS_FORMAT_UCHAR;
270-
}
271265
target_bands = 1;
272266
break;
273267

274268
case VIPS_FOREIGN_PPM_FORMAT_PPM:
275-
if (image->BandFmt == VIPS_FORMAT_USHORT) {
269+
if (image->BandFmt == VIPS_FORMAT_USHORT)
276270
target_interpretation = VIPS_INTERPRETATION_RGB16;
277-
target_format = VIPS_FORMAT_USHORT;
278-
}
279-
else {
271+
else
280272
target_interpretation = VIPS_INTERPRETATION_sRGB;
281-
target_format = VIPS_FORMAT_UCHAR;
282-
}
283273
target_bands = 3;
284274
break;
285275

286276
case VIPS_FOREIGN_PPM_FORMAT_PFM:
287-
target_format = VIPS_FORMAT_FLOAT;
288277
target_interpretation = VIPS_INTERPRETATION_scRGB;
289278
if (image->Bands > 1)
290279
target_bands = 3;
@@ -295,27 +284,25 @@ vips_foreign_save_ppm_build(VipsObject *object)
295284

296285
case VIPS_FOREIGN_PPM_FORMAT_PNM:
297286
default:
298-
/* Just use the input format and interpretation.
287+
/* Just use the input interpretation and bands.
299288
*/
300-
target_format = image->BandFmt;
301289
target_interpretation = image->Type;
302290
target_bands = image->Bands;
303291
break;
304292
}
305293

306-
if (vips_colourspace(image, &t[1], target_interpretation, NULL) ||
307-
vips_cast(t[1], &t[2], target_format, NULL))
294+
if (vips_colourspace(image, &t[1], target_interpretation, NULL))
308295
return -1;
309-
image = t[2];
296+
image = t[1];
310297

311298
/* Get bands right.
312299
*/
313300
if (image->Bands > target_bands) {
314-
if (vips_extract_band(image, &t[3], 0,
301+
if (vips_extract_band(image, &t[2], 0,
315302
"n", target_bands,
316303
NULL))
317304
return -1;
318-
image = t[3];
305+
image = t[2];
319306
}
320307
if (image->Bands < target_bands) {
321308
vips_error(class->nickname, "%s", _("too few bands for format"));
@@ -406,9 +393,8 @@ vips_foreign_save_ppm_build(VipsObject *object)
406393
char buf[G_ASCII_DTOSTR_BUF_SIZE];
407394

408395
scale = 1.0;
409-
if (vips_image_get_typeof(image, "pfm-scale") &&
410-
!vips_image_get_double(image, "pfm-scale", &scale))
411-
;
396+
if (vips_image_get_typeof(image, "pfm-scale"))
397+
vips_image_get_double(image, "pfm-scale", &scale);
412398

413399
/* Need to be locale independent.
414400
*/

0 commit comments

Comments
 (0)