private static (ProcessState state, SKImage image) ReadFullImage(T.Tiff tiff, ImageRequest request, bool allowSizeAboveFull)
{
int width = tiff.GetField(T.TiffTag.IMAGEWIDTH)[0].ToInt();
int height = tiff.GetField(T.TiffTag.IMAGELENGTH)[0].ToInt();
var restag = tiff.GetField(T.TiffTag.RESOLUTIONUNIT);
var xrestag = tiff.GetField(T.TiffTag.XRESOLUTION);
var yrestag = tiff.GetField(T.TiffTag.YRESOLUTION);
var resunit = restag == null ? 2 : restag[0].ToShort();
var xres = xrestag == null ? 96 : xrestag[0].ToDouble();
var yres = yrestag == null ? 96 : yrestag[0].ToDouble();
// pixels per metre
if (resunit == 3)
{
xres = xres / 0.0254;
yres = yres / 0.0254;
}
var isTileable = tiff.IsTiled();
var state = ImageRequestInterpreter.GetInterpretedValues(request, width, height, allowSizeAboveFull);
state.HorizontalResolution = Convert.ToUInt16(xres);
state.VerticalResolution = Convert.ToUInt16(yres);
var raster = new int[width * height];
if (!tiff.ReadRGBAImageOriented(width, height, raster, T.Orientation.TOPLEFT))
{
throw new IOException("Unable to decode TIFF file");
}
using (var bmp = CreateBitmapFromPixels(raster, width, height))
{
var desiredWidth = Math.Max(1, (int)Math.Round(state.RegionWidth * state.ImageScale));
var desiredHeight = Math.Max(1, (int)Math.Round(state.RegionHeight * state.ImageScale));
Log.Debug("Desired size {@DesiredWidth}, {@DesiredHeight}", desiredWidth, desiredHeight);
var regionWidth = state.RegionWidth;
var regionHeight = state.RegionHeight;
var srcRegion = SKRectI.Create(state.StartX, state.StartY, regionWidth, regionHeight);
return(state, CopyImageRegion2(bmp, desiredWidth, desiredHeight, srcRegion));
}
}