GithubHelp home page GithubHelp logo

biggustave's People

Contributors

eliotjones avatar rokm avatar roobixx avatar zanedubya avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

biggustave's Issues

BigGustave does not read tRNS chunk = no transparency in Color type 3 images.

Hello again @EliotJones!

PNG images of Color type 3 may contain what the specification calls "simple transparency" - alpha values associated with the palette entries. These alpha values will be contained in single chunk of type tRNS, which must follow the PLTE chunk. The tRNS chunk will contain a series of one-byte alpha values corresponding to the entries in the PLTE chunk. This is described by the PNG Specification at 4.2.1.1.

BigGustave does not handle this part of the specification. I've added it on my end, and have submitted f9af15c if you would like to include it in upstream.

This PR might also fix the issue identified in #7, if that issue is associated with Color type 3. Alternatively, #7 might be caused by lack of transparency support for Color type 2. For Color type 2, the transparent color is represented by a tRNS chunk of length 6 that is not associated with a PLTE entry. f9af15c does not add this functionality.

Alpha channel 255 all the time

I've got these door and while reading pixel by pixel alpha component is 255 on each one.
I've tried saving this PNG in GIMP without background color, but it doesn't help.

Using Visual Studio 2019 Community + BigGustave v1.0.3 from NuGet

Code snippet:

var stream = File.OpenRead(path);
Png image = Png.Open(stream);

Console.WriteLine("X = 255 / SPACE = 0");
for (int y = 0; y < image.Height; ++y)
{
	for (int x = 0; x < image.Width; ++x)
	{
		Pixel px = image.GetPixel(x, y);
		if(px.A == 255)
			Console.Write("X");
		else
			Console.Write(" ");
	}
	Console.WriteLine("");
}
Console.WriteLine("\n");

door
obraz

Pixel order error

Hi @EliotJones,
I've found a problem with your lib trying to decode this file:

test

I was using a simple loop to read pixel by pixel the file but something in the output wasn't correct so I tried to simply copy the image into a new one, with this code:

var stream = File.OpenRead("test.png");
var image = Png.Open(stream);
var streamOut = File.Create("testOut.png");
var builder = PngBuilder.FromPng(image);
builder.Save(streamOut);
streamOut.Close();

The output image is this:

testout

The input file seems to be ok (you can inspect it here)
With other files (created using the same process) this problem doesn't shows up.

Any thoughts?

Thanks

PngOpener should return a Png object if there is trailing data after IEND.

Hi @EliotJones,

BigGustave's PngOpener class throws an exception and does not return a Png object if it encounters trailing data after an IEND chunk. The exception is thrown at PngOpener.cs:44.

while (TryReadChunkHeader(stream, out var header))
{
if (hasEncounteredImageEnd)
{
throw new InvalidOperationException($"Found another chunk {header} after already reading the IEND chunk.");
}

The W3C PNG specification at 3.2. states that the IEND chunk serves as the end-of-file marker, and BigGustave follows this requirement.

However, I think it is the common convention among PNG readers to ignore trailing data after IEND, and to return a valid image, if one has been successfully unpacked, upon encountering the IEND chunk.

If BigGustave were to follow this convention, then I think the easiest change to make would be to replace the throw statement on PngOpener.cs:44 with a break statement. Conditionally, one could disable throwing an exception using a static features boolean, and/or log a debug message using whatever method you would prefer. For my purposes, I do not care if there is trailing data and so I simply break at 44.

Thanks again for your great work on this library!

Error when loading non-paletted images with palette data.

Hi @EliotJones, thanks for this excellent library. I found a minor error while loading PNG images on this end, and am submitting a suggested fix.

A PNG file that is not paletted (header.ColorType != 3) can nonetheless have a PLTE header chunk. See the W3C PNG (Portable Network Graphics) Specification at 4.1.2. I do not know for certain, but I think this functionality is intended to be used as a suggested palette for rendering a 24/32-bit PNG in 8-bit color depth.

When BigGustave opens a PNG file with a PLTE header chunk, it will override the header.ColorType and use the palette to interpret the raw pixel data. This will either cause an exception to be thrown or cause unexpected behavior, depending on the values of the raw pixel data and the number of entries in the palette. I am attaching a sample PNG file that will cause an exception to be thrown when opened.

move-arrow-12

I have also proposed a very simple fix as Pull Request #2 on this repository: don't use the palette unless (header.ColorType | ColorType.PaletteUsed) == ColorType.PaletteUsed.

Thanks again for your work on this library! I am using it to replace a dependency on System.Drawing in an asset pipeline for a game I am working on.

SamplesPerPixel broken when header.ColorType = ColorType.PaletteUsed | ColorType.ColorUsed

SamplesPerPixel seems to return 0 on at least some 256 color images, resulting in some of the lines having incorrect filter applied.

Suggested fix might be adding a case for "case ColorType.PaletteUsed | ColorType.ColorUsed":

		switch (header.ColorType)
		{
			case ColorType.None:
				return 1;

			case ColorType.PaletteUsed | ColorType.ColorUsed:
			case ColorType.PaletteUsed:
				return 1;

			case ColorType.ColorUsed:
				return 3;
			case ColorType.AlphaChannelUsed:
				return 2;
			case ColorType.ColorUsed | ColorType.AlphaChannelUsed:
				return 4;
			default:
				return 0;
		}

Write of debugging files

Hi @EliotJones,

In the released library version 1.0.2 there are some File.WriteAllBytes(@"C:\temp\... calls present, which cause the library to fail.

For example in PngBuilder.cs on line 30.

Best regards,
Michael

vertical stripe error

When indexed color and transparent background are used together. If the program saves it as read, it will have vertical stripes where it should be on a transparent background.

The error file and source are enclosed.

demon2gradered_85x63
abc2
Class1.zip

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.