Skip to content

Commit 2aca66d

Browse files
authored
Never set the PFM header to little endian (#4242)
Never set the PFM header to little endian PFM files are always written in big endian: https://github.com/libvips/libvips/blob/master/libvips/foreign/ppmsave.c#L459 But the header is set to little endian if on a big endian machine (!) https://github.com/libvips/libvips/blob/master/libvips/foreign/ppmsave.c#L414-L415 Fixes #4241.
1 parent 2ad7907 commit 2aca66d

File tree

9 files changed

+134
-17
lines changed

9 files changed

+134
-17
lines changed

ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
8.17.0
2+
3+
- add Magic Kernel support [akimon658]
4+
15
8.16.1
26

37
- support multipage JXL

libvips/foreign/jxlload.c

Lines changed: 60 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,56 @@ vips_foreign_load_jxl_print_format(JxlPixelFormat *format)
439439
printf(" endianness = %d\n", format->endianness);
440440
printf(" align = %zd\n", format->align);
441441
}
442+
443+
static const char *
444+
vips_foreign_load_jxl_blend_mode(JxlBlendMode blendmode)
445+
{
446+
switch (blendmode) {
447+
case JXL_BLEND_REPLACE:
448+
return "JXL_BLEND_REPLACE";
449+
450+
case JXL_BLEND_ADD:
451+
return "JXL_BLEND_ADD";
452+
453+
case JXL_BLEND_BLEND:
454+
return "JXL_BLEND_BLEND";
455+
456+
case JXL_BLEND_MULADD:
457+
return "JXL_BLEND_MULADD";
458+
459+
case JXL_BLEND_MUL:
460+
return "JXL_BLEND_MUL";
461+
462+
default:
463+
return "<unknown JxlBlendMode";
464+
}
465+
}
466+
467+
static void
468+
vips_foreign_load_jxl_print_frame_header(JxlFrameHeader *h)
469+
{
470+
printf("JxlFrameHeader:\n");
471+
printf(" duration = %u\n", h->duration);
472+
printf(" timecode = %u\n", h->timecode);
473+
printf(" name_length = %u\n", h->name_length);
474+
printf(" is_last = %s\n", h->is_last ? "TRUE" : "FALSE");
475+
printf(" layer_info.have_crop = %s\n",
476+
h->layer_info.have_crop ? "TRUE" : "FALSE");
477+
printf(" layer_info.crop_x0 = %d\n", h->layer_info.crop_x0);
478+
printf(" layer_info.crop_y0 = %d\n", h->layer_info.crop_y0);
479+
printf(" layer_info.xsize = %u\n", h->layer_info.xsize);
480+
printf(" layer_info.ysize = %u\n", h->layer_info.ysize);
481+
printf(" layer_info.blend_info.blendmode = %s\n",
482+
vips_foreign_load_jxl_blend_mode(h->layer_info.blend_info.blendmode));
483+
printf(" layer_info.blend_info.source = %u\n",
484+
h->layer_info.blend_info.source);
485+
printf(" layer_info.blend_info.alpha = %u\n",
486+
h->layer_info.blend_info.alpha);
487+
printf(" layer_info.blend_info.clamp = %s\n",
488+
h->layer_info.blend_info.clamp ? "TRUE" : "FALSE");
489+
printf(" layer_info.save_as_reference = %u\n",
490+
h->layer_info.save_as_reference);
491+
}
442492
#endif /*DEBUG*/
443493

444494
static JxlDecoderStatus
@@ -455,9 +505,9 @@ vips_foreign_load_jxl_process(VipsForeignLoadJxl *jxl)
455505
size_t bytes_remaining;
456506
int bytes_read;
457507

458-
#ifdef DEBUG
508+
#ifdef DEBUG_VERBOSE
459509
printf("vips_foreign_load_jxl_process: reading ...\n");
460-
#endif /*DEBUG*/
510+
#endif /*DEBUG_VERBOSE*/
461511

462512
bytes_remaining = JxlDecoderReleaseInput(jxl->decoder);
463513
bytes_read = vips_foreign_load_jxl_fill_input(jxl, bytes_remaining);
@@ -498,6 +548,7 @@ vips_foreign_load_jxl_read_frame(VipsForeignLoadJxl *jxl, VipsImage *frame,
498548
#ifdef DEBUG_VERBOSE
499549
printf("vips_foreign_load_jxl_read_frame: skipping %d frames\n", skip);
500550
#endif /*DEBUG_VERBOSE*/
551+
501552
JxlDecoderSkipFrames(jxl->decoder, skip);
502553
jxl->frame_no += skip;
503554
}
@@ -822,8 +873,7 @@ vips_foreign_load_jxl_header(VipsForeignLoad *load)
822873
do {
823874
switch ((status = vips_foreign_load_jxl_process(jxl))) {
824875
case JXL_DEC_ERROR:
825-
vips_foreign_load_jxl_error(jxl,
826-
"JxlDecoderProcessInput");
876+
vips_foreign_load_jxl_error(jxl, "JxlDecoderProcessInput");
827877
return -1;
828878

829879
case JXL_DEC_BOX:
@@ -907,8 +957,7 @@ vips_foreign_load_jxl_header(VipsForeignLoad *load)
907957
&jxl->format,
908958
#endif
909959
JXL_COLOR_PROFILE_TARGET_DATA, &jxl->icc_size)) {
910-
vips_foreign_load_jxl_error(jxl,
911-
"JxlDecoderGetICCProfileSize");
960+
vips_foreign_load_jxl_error(jxl, "JxlDecoderGetICCProfileSize");
912961
return -1;
913962
}
914963

@@ -937,6 +986,10 @@ vips_foreign_load_jxl_header(VipsForeignLoad *load)
937986
return -1;
938987
}
939988

989+
#ifdef DEBUG
990+
vips_foreign_load_jxl_print_frame_header(&h);
991+
#endif /*DEBUG*/
992+
940993
if (jxl->info.have_animation) {
941994
// tick duration in seconds
942995
double tick = (double) jxl->info.animation.tps_denominator /
@@ -1010,8 +1063,7 @@ vips_foreign_load_jxl_load(VipsForeignLoad *load)
10101063

10111064
JxlDecoderRewind(jxl->decoder);
10121065
if (JxlDecoderSubscribeEvents(jxl->decoder,
1013-
JXL_DEC_FRAME |
1014-
JXL_DEC_FULL_IMAGE)) {
1066+
JXL_DEC_FRAME | JXL_DEC_FULL_IMAGE)) {
10151067
vips_foreign_load_jxl_error(jxl,
10161068
"JxlDecoderSubscribeEvents");
10171069
return -1;

libvips/foreign/ppmsave.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -411,9 +411,6 @@ vips_foreign_save_ppm_build(VipsObject *object)
411411
!vips_image_get_double(image, "pfm-scale", &scale))
412412
;
413413

414-
if (vips_amiMSBfirst())
415-
scale *= -1;
416-
417414
/* Need to be locale independent.
418415
*/
419416
g_ascii_dtostr(buf, G_ASCII_DTOSTR_BUF_SIZE, scale);

libvips/include/vips/resample.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ typedef enum {
4545
VIPS_KERNEL_MITCHELL,
4646
VIPS_KERNEL_LANCZOS2,
4747
VIPS_KERNEL_LANCZOS3,
48+
VIPS_KERNEL_MKS2013,
49+
VIPS_KERNEL_MKS2021,
4850
VIPS_KERNEL_LAST
4951
} VipsKernel;
5052

libvips/resample/reduce.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@
6666
* @VIPS_KERNEL_MITCHELL: Convolve with a Mitchell kernel.
6767
* @VIPS_KERNEL_LANCZOS2: Convolve with a two-lobe Lanczos kernel.
6868
* @VIPS_KERNEL_LANCZOS3: Convolve with a three-lobe Lanczos kernel.
69+
* @VIPS_KERNEL_MKS2013: Convolve with Magic Kernel Sharp 2013.
70+
* @VIPS_KERNEL_MKS2021: Convolve with Magic Kernel Sharp 2021.
6971
*
7072
* The resampling kernels vips supports. See vips_reduce(), for example.
7173
*/

libvips/resample/reduceh.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,12 @@ vips_reduce_get_points(VipsKernel kernel, double shrink)
125125
case VIPS_KERNEL_LANCZOS3:
126126
return 2 * rint(3 * shrink) + 1;
127127

128+
case VIPS_KERNEL_MKS2013:
129+
return 2 * rint(3 * shrink) + 1;
130+
131+
case VIPS_KERNEL_MKS2021:
132+
return 2 * rint(5 * shrink) + 1;
133+
128134
default:
129135
g_assert_not_reached();
130136
return 0;

libvips/resample/templates.h

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,48 @@ double inline filter<VIPS_KERNEL_LANCZOS3>(double x)
402402
return 0.0;
403403
}
404404

405+
template <>
406+
double inline filter<VIPS_KERNEL_MKS2013>(double x)
407+
{
408+
if (x < 0.0)
409+
x = -x;
410+
411+
if (x >= 2.5)
412+
return 0.0;
413+
414+
if (x >= 1.5)
415+
return (x - 5.0 / 2.0) * (x - 5.0 / 2.0) / -8.0;
416+
417+
if (x >= 0.5)
418+
return (4.0 * x * x - 11.0 * x + 7.0) / 4.0;
419+
420+
return 17.0 / 16.0 - 7.0 * x * x / 4.0;
421+
}
422+
423+
template <>
424+
double inline filter<VIPS_KERNEL_MKS2021>(double x)
425+
{
426+
if (x < 0.0)
427+
x = -x;
428+
429+
if (x >= 4.5)
430+
return 0.0;
431+
432+
if (x >= 3.5)
433+
return (4.0 * x * x - 36.0 * x + 81.0) / -1152.0;
434+
435+
if (x >= 2.5)
436+
return (4.0 * x * x - 27.0 * x + 45.0) / 144.0;
437+
438+
if (x >= 1.5)
439+
return (24.0 * x * x - 113.0 * x + 130.0) / -144.0;
440+
441+
if (x >= 0.5)
442+
return (140.0 * x * x - 379.0 * x + 239.0) / 144.0;
443+
444+
return 577.0 / 576.0 - 239.0 * x * x / 144.0;
445+
}
446+
405447
/* Given an x in [0,1] (we can have x == 1 when building tables),
406448
* calculate c0 .. c(@n_points), the coefficients. This is called
407449
* from the interpolator as well as from the table builder.
@@ -469,6 +511,16 @@ vips_reduce_make_mask(T *c, VipsKernel kernel, const int n_points,
469511
filter<VIPS_KERNEL_LANCZOS3>, shrink, x);
470512
break;
471513

514+
case VIPS_KERNEL_MKS2013:
515+
calculate_coefficients(c, n_points,
516+
filter<VIPS_KERNEL_MKS2013>, shrink, x);
517+
break;
518+
519+
case VIPS_KERNEL_MKS2021:
520+
calculate_coefficients(c, n_points,
521+
filter<VIPS_KERNEL_MKS2021>, shrink, x);
522+
break;
523+
472524
default:
473525
g_assert_not_reached();
474526
break;

meson.build

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
project('vips', 'c', 'cpp',
2-
version: '8.16.1',
2+
version: '8.17.0',
33
meson_version: '>=0.55',
44
default_options: [
55
# this is what glib uses (one of our required deps), so we use it too
@@ -23,9 +23,9 @@ version_patch = version_parts[2]
2323
# binary interface changed: increment current, reset revision to 0
2424
# binary interface changes backwards compatible?: increment age
2525
# binary interface changes not backwards compatible?: reset age to 0
26-
library_revision = 1
27-
library_current = 60
28-
library_age = 18
26+
library_revision = 0
27+
library_current = 61
28+
library_age = 19
2929
library_version = '@0@.@1@.@2@'.format(library_current - library_age, library_age, library_revision)
3030
darwin_versions = [library_current + 1, '@0@.@1@'.format(library_current + 1, library_revision)]
3131

test/test-suite/test_resample.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ def test_reduce(self):
8383
for fac in [1, 1.1, 1.5, 1.999]:
8484
for fmt in all_formats:
8585
for kernel in ["nearest", "linear",
86-
"cubic", "lanczos2", "lanczos3"]:
86+
"cubic", "lanczos2",
87+
"lanczos3", "mks2013", "mks2021"]:
8788
x = im.cast(fmt)
8889
r = x.reduce(fac, fac, kernel=kernel)
8990
d = abs(r.avg() - im.avg())
@@ -93,7 +94,8 @@ def test_reduce(self):
9394
for const in [0, 1, 2, 254, 255]:
9495
im = (pyvips.Image.black(10, 10) + const).cast("uchar")
9596
for kernel in ["nearest", "linear",
96-
"cubic", "lanczos2", "lanczos3"]:
97+
"cubic", "lanczos2",
98+
"lanczos3", "mks2013", "mks2021"]:
9799
# print "testing kernel =", kernel
98100
# print "testing const =", const
99101
shr = im.reduce(2, 2, kernel=kernel)

0 commit comments

Comments
 (0)