load/save Aspect ratio in TIFF

This commit is contained in:
Thomas Bernard 2019-01-05 13:39:14 +01:00
parent 379dc4a092
commit 2dfb5cafe1
No known key found for this signature in database
GPG Key ID: 0FF11B67A5C0863C

View File

@ -303,6 +303,7 @@ void Load_TIFF_Sub(T_IO_Context * context, TIFF * tif, unsigned long file_size)
word bps, spp; word bps, spp;
word photometric = PHOTOMETRIC_RGB; word photometric = PHOTOMETRIC_RGB;
char * desc; char * desc;
float xresol, yresol;
TIFFPrintDirectory(tif, stdout, TIFFPRINT_NONE); TIFFPrintDirectory(tif, stdout, TIFFPRINT_NONE);
if (!TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &width) || !TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &height)) 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); 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; File_error = 0;
Pre_load(context, width, height, file_size, FORMAT_TIFF, ratio, bps * spp); Pre_load(context, width, height, file_size, FORMAT_TIFF, ratio, bps * spp);
if (File_error != 0) if (File_error != 0)
@ -576,6 +588,24 @@ void Save_TIFF_Sub(T_IO_Context * context, TIFF * tif)
const word photometric = PHOTOMETRIC_PALETTE; const word photometric = PHOTOMETRIC_PALETTE;
float xresol = 1.0f, yresol = 1.0f; 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); snprintf(version, sizeof(version), "GrafX2 %s.%s", Program_version, SVN_revision);
width = context->Width; width = context->Width;
height = context->Height; height = context->Height;