Giter Club home page Giter Club logo

animatedpngcreator's People

Contributors

cmk1988 avatar dmahnkopf avatar

Stargazers

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

Watchers

 avatar  avatar

animatedpngcreator's Issues

does not run in docker (microsoft/dotnet/)

I tried to run AnimatedPngCreator.Console using the official docker image, but got an error:

/usr/share/dotnet/sdk/2.1.403/Microsoft.Common.CurrentVersion.targets(1179,5): error MSB3644: The reference assemblies for framework ".NETFramework,Version=v4.5.2" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed. Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place of reference assemblies. Therefore your assembly may not be correctly targeted for the framework you intend. [/home/nils/Projects/AnimatedPngCreator/AnimatedPngCreator.Console/AnimatedPngCreator.Console.csproj]
The build failed. Please fix the build errors and run again.

The docker run call:

~/Projects/AnimatedPngCreator/AnimatedPngCreator.Console$ docker run --rm -it -w $(pwd) -v $(pwd):$(pwd) microsoft/dotnet dotnet run

Maybe you can set the proper version in the project config to run in dotnet core?

Slow image change analysis with solution

Thanks for your code! I noticed that checking for image changes was the slowest part due to the use of GetPixel and SetPixel. The code below passes your tests and is much faster due to the use of 'LockBits' and direct access to the data. Requires the build properties to be set to 'allow unsafe code', though.

using System.Drawing;

namespace CMK
{
internal class ImageChangeAnalyser
{
private Bitmap oldImage = null;

    public unsafe Image BlackoutImage(Image newImage, out bool equal)
    {
        equal = false;
        if (newImage == null)
        {
            return null;
        }
        // Make sure we have a bitmap
        var newImageBmp = new Bitmap(newImage);
        // Copy of new image
        var copy_new_image = new Bitmap(newImageBmp);
        // Dimensions
        var x = newImage.Width;            
        var y = newImage.Height;
        var x4 = 4 * x; // argb format

        // Something to do?
        if (oldImage != null)
        {
            // Lock bits of old and new image
            var o_img = oldImage.LockBits(new Rectangle(0, 0, x, y), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            var n_img = newImageBmp.LockBits(new Rectangle(0, 0, x, y), System.Drawing.Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            // To track equality
            bool is_equal = true;

            for (int j = 0; j < y; j++)
            {
                byte* o_row = ((byte *) o_img.Scan0) + o_img.Stride * j;
                byte* n_row = ((byte * )n_img.Scan0) + n_img.Stride * j;
                for (int i = 0; i < x4; i+=4)
                {                    
                    // Compare b, g, and r values (+0, +1, +2)
                    if (o_row[i+0] == n_row[i+0] && o_row[i+1] == n_row[i+1] && o_row[i+2] == n_row[i+2])
                    {   
                        // For compatibility with tests
                        n_row[i + 0] = 255;
                        n_row[i + 1] = 255;
                        n_row[i + 2] = 255;
                        // Set 'A' value(+3) of new image to 0: fully transparent (whatever the other colors!)
                        n_row[i + 3] = 0;
                    }
                    else
                    {
                        is_equal = false;
                    }
                }
            }
            // Unlock bits
            oldImage.UnlockBits(o_img);
            newImageBmp.UnlockBits(n_img);
            // Update equality
            equal = is_equal;
        }
        // old image is current new image (but without our transparancy changes, so use copy0
        oldImage = copy_new_image;            
        // Return bitmap with transparance changes
        return newImageBmp;
    }

}

}

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.