Skip to content

Modification to resolution handling in TIFF reader / writer #4185

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions libvips/foreign/tiff2vips.c
Original file line number Diff line number Diff line change
Expand Up @@ -541,8 +541,8 @@ get_resolution(TIFF *tiff, VipsImage *out)
/* We used to warn about missing res data, but it happens so
* often and is so harmless, why bother.
*/
x = 1.0;
y = 1.0;
x = 0.0;
y = 0.0;
}

out->Xres = x;
Expand Down
14 changes: 8 additions & 6 deletions libvips/foreign/vips2tiff.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* TIFF PARTS:

Check notice on line 1 in libvips/foreign/vips2tiff.c

View workflow job for this annotation

GitHub Actions / cpp-linter

Run clang-format on libvips/foreign/vips2tiff.c

File libvips/foreign/vips2tiff.c does not conform to Custom style guidelines. (lines 890, 894, 895)
* Copyright (c) 1988, 1990 by Sam Leffler.
* All rights reserved.
*
Expand Down Expand Up @@ -885,13 +885,15 @@
!wtiff->tile)
wtiff->we_compress = FALSE;

/* Don't write mad resolutions (eg. zero), it confuses some programs.
/* Only set resolution if we actually have one. Also, mad resolutions (eg. zero) confuse some programs.
*/
TIFFSetField(tif, TIFFTAG_RESOLUTIONUNIT, wtiff->resunit);
TIFFSetField(tif, TIFFTAG_XRESOLUTION,
VIPS_FCLIP(0.01, wtiff->xres, 1000000));
TIFFSetField(tif, TIFFTAG_YRESOLUTION,
VIPS_FCLIP(0.01, wtiff->yres, 1000000));
if(wtiff->xres || wtiff->yres){
TIFFSetField(tif, TIFFTAG_RESOLUTIONUNIT, wtiff->resunit);
/* Scale resolution by the subsampling factor of the current level
*/
if(wtiff->xres) TIFFSetField(tif, TIFFTAG_XRESOLUTION, (wtiff->xres/layer->sub));
if(wtiff->yres) TIFFSetField(tif, TIFFTAG_YRESOLUTION, (wtiff->yres/layer->sub));
}

if (wtiff_embed_xmp(wtiff, tif) ||
wtiff_embed_iptc(wtiff, tif) ||
Expand Down
10 changes: 6 additions & 4 deletions libvips/foreign/vipspng.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Load/save png image with libpng

Check notice on line 1 in libvips/foreign/vipspng.c

View workflow job for this annotation

GitHub Actions / cpp-linter

Run clang-format on libvips/foreign/vipspng.c

File libvips/foreign/vipspng.c does not conform to Custom style guidelines. (lines 1168, 1169, 1170)
*
* 28/11/03 JC
* - better no-overshoot on tile loop
Expand Down Expand Up @@ -1163,11 +1163,13 @@
in->Xsize, in->Ysize, bitdepth, color_type, interlace_type,
PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);

/* Set resolution. libpng uses pixels per meter.
/* Set resolution if known. libpng uses pixels per meter.
*/
png_set_pHYs(write->pPng, write->pInfo,
VIPS_RINT(in->Xres * 1000), VIPS_RINT(in->Yres * 1000),
PNG_RESOLUTION_METER);
if(in->Xres && in->Yres){
png_set_pHYs(write->pPng, write->pInfo,
VIPS_RINT(in->Xres * 1000), VIPS_RINT(in->Yres * 1000),
PNG_RESOLUTION_METER);
}

/* Metadata
*/
Expand Down
4 changes: 2 additions & 2 deletions libvips/iofuncs/image.c
Original file line number Diff line number Diff line change
Expand Up @@ -1344,8 +1344,8 @@ vips_image_init(VipsImage *image)
image->Ysize = 1;
image->Bands = 1;

image->Xres = 1.0;
image->Yres = 1.0;
image->Xres = 0.0;
image->Yres = 0.0;

image->fd = -1; /* since 0 is stdout */
image->sslock = vips_g_mutex_new();
Expand Down
Loading