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
Png's are encoding wrong after 1.0.0-alpha-000047 #24
Comments
the actual last known good version is 1.0.0-alpha-000047 i have a large batch of images and on version 48 and up some of them are not getting processed all the way |
@KLuuKer Thanks for all the extra info that was really useful! Turns out I'd moved a line inside the using statement for the deflater stream. 1.0.0-alpha-000062 work fine now for me. |
bad news everyone.... :( seems it's not completely fixed (although its allot better now) there is a small amount of images that have the same "it just stop encoding parts" or weird block parts or other encodings issues i only get some issues for some resolutions tough, so maybe it's not the pngencoder but some other resizing stuff i will check\try some more stuff later, but i have todo some other stuff first using (var thisIsMyOutputData = new MemoryStream())
{
// yes its a normal memorystream and not something weird
ImageResizer.Resize(img.Blob, thisIsMyOutputData, true, 300, 300)
} internal static void Resize(byte[] image, Stream outputStream, bool resize, int newWidth, int newHeight)
{
using (var stream = new MemoryStream(image, false))
{
Image<Color, uint> img = new Image(stream);
{
if (resize && (img.Width > newWidth || img.Height > newHeight))
{
if (img.Width > img.Height)
{
newHeight = (int)(img.Height / (img.Width / (double)newWidth));
}
else
{
newWidth = (int)(img.Width / (img.Height / (double)newHeight));
}
img = img.Resize(newWidth, newHeight, new Lanczos3Resampler(), true);
}
img.ExifProfile = null; // i have no idea what you are talking about....
if (img.Properties != null && img.Properties.Count > 0)
{
img.Properties.Clear();
}
var encoder = new PngEncoder()
{
Quality = int.MaxValue,
CompressionLevel = 9,
};
encoder.Encode(img, outputStream);
}
}
} |
@KLuuKer Making a small sidestep here... Why are you not setting the ExifProfile to null to remove the profile? I do think I still need to add a |
@dlemstra wouldn't it be better if it didn't get loaded in the first place? :) |
hmmmm, i think all of the images that are encoded incorrectly are jpeg files |
Odd @KLuuKer... I'm not seeing this in my tests. Here's the image encoded as a png And here is it resized as a png using the Lancsoz3 sampler BTW that whole code could be written in a much more concise manner... // Resizing with one dimensions will automatically preserve the aspect ratio.
// Png doesn't preserve EXIF data so you don't need to remove it.
new Image(stream)
.Resize(newWidth, 0, new Lanczos3Resampler(), true)
.SaveAsPng(output); @dlemstra Could you also dl the image and test on your machine? I want to make sure there is nothing odd going on. |
@JimBobSquarePants even when using your code, i get errors internal static void Resize(byte[] image, Stream outputStream, bool resize, int newWidth, int newHeight)
{
using (var stream = new MemoryStream(image, false))
{
new Image(stream)
.Resize(newWidth, 0, new Lanczos3Resampler(), true)
.SaveAsPng(outputStream);
}
} i must admit I'm running this with multiple images simultaneous about 80 different webrequest (our product index page), so this could be a concurrency issue |
Ah... now that is interesting. Everything here should be threadsafe but maybe it isn't. And it's definitely fine before the commit at the top of the thread? And only happens when encoding png files? If so, The only real change I have made to the png encoder is using is an |
we can ignore the resize code, i commented that out and its still wrong, gonna try outputting jpegs jpges output just fine (with version 64) |
Ok... Can you do me a huge favour please and also test gif and bitmap. I want to narrow it down to the png encoder. |
Thanks for all that... Yeah bmps are uncompressed, they'll be massive. The encoder it is then. I'll knock up a parallel test and keep at it. |
my simple console app i made just now (same issue) Parallel.For(1, 50, (i) =>
{
var image = File.ReadAllBytes("resize-me.jpg");
using (var outputStream = new FileStream("output\\" + i + ".png", FileMode.Create))
{
using (var stream = new MemoryStream(image, false))
{
new Image(stream)
.SaveAsPng(outputStream);
}
}
}); |
so i tested 47-51 with the code above and they are fine |
Give that push a go please. I was able to recreate the issue with a test and fix it. Bonus was a 20% memory usage reduction. |
had to wait for the package to get pushed :) are you aware of ArrayPool.Shared documentation?
|
Sorry, didn't mean to close that. Yeah, I've read that, if you look I'm only ever reading the I can't for the life of me see how that would happen though, all the variables are private instance ones. It's after 1am here so I won't be able to do anything more tonight I'm afraid. I'll have another look when I'm more fresh. |
Go take your well deserved sleep, you have a great project I'm leeching off. |
Previous build failed test when using unmanaged buffer copying. via PixelRow
Once more unto the breach, dear friends, once more... |
Seems to work fine for me o wait you already did 😄 tested with 1.0.0-alpha-000075 |
Downgrade System.Buffers and Remove HashHelpers
Downgrade System.Buffers and Remove HashHelpers
Downgrade System.Buffers and Remove HashHelpers
png's are encoded incorrectly on version v1.0.0-alpha-000053 and higher (including 57)
last know good version is v1.0.0-alpha-000052
so i think something went wrong in this commit f814dc3
k so after version v1.0.0-alpha-000053 the error's get really obvious (weird colored blocks)
but before that some images are still encoded incorrectly (getting chopped off) and smaller resize actions turning into black images
currently checking how far back this starts occuring
The text was updated successfully, but these errors were encountered: