Coder Social home page Coder Social logo

pngcs's Introduction

GOALS: Complete PNG encoding and decoding for Unity engine

  • Simple API to read and write Texture2D objects, raw data
  • Drop "Pngcs" folder in your project, no other dependencies, just works.

API:

  • Texture2D PNG.Read
  • Texture2D PNG.ReadAsync (experimental)
  • Color[] PNG.ReadColors
  • Color[] PNG.ReadColorsAsync (experimental)
  • PNG.Write
  • PNG.WriteAsync (experimental)
  • PNG.WriteLargeAsync (experimental)
  • PNG.WriteGrayscaleAsync (experimental)

TODO:

  • PNG.Read creating Texture2D in every useful TextureFormat, infered from file (partially done already)
  • Improve READ/WRITE speeds
  • PNG.Read/Write byte[]
  • PNG.Read with target width and height arguments (to preview bigger image etc.)
  • PNG.Read with image rect argument (read texture atlas region)

HOW TO USE:

using UnityEngine;
using Pngcs.Unity;
public class PngcsTest : MonoBehaviour
{
    void Awake ()
    {
        // THIS IS HOW YOU READ:
        Texture2D texture = PNG.Read( @"D:/input.png" );

        // THIS IS HOW YOU WRITE:
        PNG.Write( texture , @"D:/output.png" );
    }
    
    void OnDestroy ()
    {
        //remember to always release memory when texture is not needed anymore:
        Destroy( texture );
    }
}

REQUIREMENTS:

  • Unity 2017.1
  • Scripting runtime version: C# 4.x

This window is available under top menu bar/Test/Pngcs Load Pngcs test window Note: Alpha8 images appear inverted here but aren't - it's due to no color info but black fill and transparency.

pngcs's People

Contributors

andrew-raphael-lukasik avatar leonbloy avatar sungiant 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

Watchers

 avatar  avatar  avatar

pngcs's Issues

Index was outside the bounds of the array

I tried the following code and got this error.

IndexOutOfRangeException: Index was outside the bounds of the array.
Pngcs.PngWriter.EncodeRowFromInt (System.Int32[] row) (at Assets/pngcs-master/Pngcs/PngWriter.cs:270)
Pngcs.PngWriter.WriteRowInt (System.Int32[] newrow, System.Int32 rown) (at Assets/pngcs-master/Pngcs/PngWriter.cs:549)
Pngcs.PngWriter.WriteRow (Pngcs.ImageLine line, System.Int32 rownumber) (at Assets/pngcs-master/Pngcs/PngWriter.cs:530)
Pngcs.Unity.PNG.Write (UnityEngine.Color[] pixels, System.Int32 width, System.Int32 height, System.Int32 bitDepth, System.Boolean alpha, System.Boolean greyscale, System.String filePath) (at Assets/pngcs-master/Pngcs/Unity/Unity.cs:238)
Pngcs.Unity.PNG.Write (UnityEngine.Texture2D texture, System.String filePath) (at Assets/pngcs-master/Pngcs/Unity/Unity.cs:152)
PngcsTest+d__0.MoveNext () (at Assets/pngcs-master/PngcsTest.cs:15)
UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at /Users/builduser/buildslave/unity/build/Runtime/Export/Scripting/Coroutines.cs:17)

IEnumerator Start()
{
    yield return new WaitForEndOfFrame();

    var texture = ScreenCapture.CaptureScreenshotAsTexture();
    var output = Path.Combine(Application.persistentDataPath, "test.png");

    PNG.Write(texture, output);
}

Memory Management

There seems so be quite a lot of garbage being created when using these calls.

My use case.
I export 7 Large PNG's in succession or in parallel with async.
When I run the same process again the Mobile Version crashes due to memory issues.

This suggests that something is not properly discarded. Will run through code and see if I have any suggestions.

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.