I've been pulling my hair out with trying to get a tool made to work with 16 bit greyscale png, as well as 24 bit colour png. I've given up on doing it with Python, as the libraries that work with 16bit png files are all sorts of wonky and have incorrect documentation.
After doing some research, it seems that only Vampyre Imaging Library works with 16 bit greyscale png files, so I'm using that for now. If there's a better one, let me know.
What I have to do, is take a 4096x4096 image (image divisible by 256), and pad out the bottom & right sides of the image with black until it is 4112x4112 (divisible by 257). Then, split the image into 257x257 images by x&y coordinates.
How do I pad the image from being 4096x4096, into 4112x4112? My main idea was to create two images, fill them with black, and append them to the original.
Don't see a way to do that though.
Here is my current code:
procedure TformWindow.buttonHeightmapClick(Sender: TObject);
var
imageCurrent, imageResized, imageFillX, imageFillY: TSingleImage;
iSizeX, iSizeY, iAddX, iAddY: Integer;
strImageToSave: string;
infoCurrent: TImageFormatInfo;
begin
if dialogOpen.Execute then begin
imageCurrent := TSingleImage.CreateFromFile(dialogOpen.FileName);
strImageToSave := ExtractFileNameWithoutExt(dialogOpen.FileName);
imageResized := TSingleImage.CreateFromImage(imageCurrent);
iSizeX := imageCurrent.Height;
iSizeY := imageCurrent.Width;
GetImageFormatInfo(imageCurrent.Format, infoCurrent);
//We want: 'png' = DetermineFileFormat(dialogOpen.FileName)
//16 bit png: infoCurrent.BytesPerPixel = 2;
//Greyscale 1 ChannelAlpha: infoCurrent.ChannelCount = 1;
ShowMessage(DetermineFileFormat(dialogOpen.FileName) + ' '
+ inttostr(infoCurrent.BytesPerPixel * 8) + 'bit '
+ inttostr(infoCurrent.ChannelCount) + ' channel'
);
iAddX := 257 - (iSizeX mod 257);
iAddY := 257 - (iSizeY mod 257);
imageFillX := TSingleImage.CreateFromParams(257, iAddY, imageCurrent.Format);
imageFillY := TSingleImage.CreateFromParams(iAddX, 1, imageCurrent.Format);
//Somehow pad out imageCurrent until it is 4112x4112
end;
end;