From 2dfb5cafe1a225826eea0260edf9102900effd2b Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Sat, 5 Jan 2019 13:39:14 +0100 Subject: [PATCH] load/save Aspect ratio in TIFF --- src/tifformat.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/tifformat.c b/src/tifformat.c index 5b163eca..0989162b 100644 --- a/src/tifformat.c +++ b/src/tifformat.c @@ -303,6 +303,7 @@ void Load_TIFF_Sub(T_IO_Context * context, TIFF * tif, unsigned long file_size) word bps, spp; word photometric = PHOTOMETRIC_RGB; char * desc; + float xresol, yresol; TIFFPrintDirectory(tif, stdout, TIFFPRINT_NONE); if (!TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &width) || !TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &height)) @@ -322,6 +323,17 @@ void Load_TIFF_Sub(T_IO_Context * context, TIFF * tif, unsigned long file_size) } } TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, &photometric); + if (TIFFGetField(tif, TIFFTAG_XRESOLUTION, &xresol) && TIFFGetField(tif, TIFFTAG_YRESOLUTION, &yresol)) + { + float ratiof = xresol / yresol; + if (ratiof > 1.6f) + ratio = PIXEL_TALL; + else if (ratiof > 1.4f) + ratio = PIXEL_TALL3; + else if (ratiof < 0.7f) + ratio = PIXEL_WIDE; + } + File_error = 0; Pre_load(context, width, height, file_size, FORMAT_TIFF, ratio, bps * spp); if (File_error != 0) @@ -576,6 +588,24 @@ void Save_TIFF_Sub(T_IO_Context * context, TIFF * tif) const word photometric = PHOTOMETRIC_PALETTE; float xresol = 1.0f, yresol = 1.0f; + switch (context->Ratio) + { + case PIXEL_WIDE: + case PIXEL_WIDE2: + yresol = 2.0f; + break; + case PIXEL_TALL: + case PIXEL_TALL2: + xresol = 2.0f; + break; + case PIXEL_TALL3: + xresol = 4.0f; + yresol = 3.0f; + break; + default: + break; + } + snprintf(version, sizeof(version), "GrafX2 %s.%s", Program_version, SVN_revision); width = context->Width; height = context->Height;