b9chris / ArpanJpegEncoder

Public repo for CodeProject C# JPEG Encoder originally by Arpan Jati
7 stars 1 forks source link

Black Picture on some environments #1

Open Zerowalker opened 11 years ago

Zerowalker commented 11 years ago

Hi, don´t know how to contact you, so i guess i will do it here. As you know yourself, when you use the encoder, it only produces a black image.

Have you been able to solve it?

Really interesting, as the internal .Net encoder isn´t the greatest.

b9chris commented 11 years ago

I agree - it's very strange. I imagine it's because of Trust issues, although I've never run into a Trust issue where the code just failed to work properly rather than throwing an Exception. I should note though that running this locally on my machine Arpan did work fine - just not on the server, a very different environment.

However - since this encoder isn't great, my next efforts will be focused on wrapping the best libjpeg implementation I can find rather than expanding on ArpanJpegEncoder.

LibJpeg: http://sourceforge.net/projects/libjpeg/

The Google PageSpeed SDK, which includes a fork of LibJpeg; the source makes it hard to determine where this fork originates: https://developers.google.com/speed/pagespeed/psol

Preliminary testing appears to result in much higher quality output from some implementations (written in C++) than this or the base .Net version. I suspect I can just get a command-line build of the best published version working, then wrap that with a .Net call that passes the relevant arguments to get better results (and good enough performance).

If others are interested in investigating the black image on the server issue here and would like to contribute code to fix it, I'm happy to accept them as a committer.

Zerowalker commented 11 years ago

Sadly, i don´t even know what "Trust" means, except for the word Trust.

For me it doesn´t even work locally, if i use it to save a bitmap, it becomes just a black picture, with wrong resolution. 1080x500 could become 789x353, maybe it´s systematically wrong, don´t know.

Really? Thhat would be awesome, something like LibJpeg-Turbo perhaps?

Maybe you could ask them from where it´s originated?

Well i am very interested in testing it when it´s available. Though i am would like it to be faster (hence why i mentioned LibJpeg-Turbo).

b9chris commented 11 years ago

That's interesting it has those problems on your environment. That makes it less likely to be trust and more likely to be hardware-related, or even what's installed (DirectX etc).

As for Trust: http://stackoverflow.com/questions/2617454/what-is-medium-trust-in-asp-net

It's not strictly related but if I do wrap the implementation I'll comment on this issue so you're notified. I'll also update the homepage for this library to point to the libjpeg .Net-wrapped lib. Not an urgent need for me right now though, so it could be quite some time before I work on the wrapped library.

Zerowalker commented 11 years ago

Maybe, really weird though, but if it´s hardware accelerated somehow, then that could break it i guess.

Will read that, thanks:)

Please do, i would gladly Beta test anything you can come with in this, i find it very interesting!

starsriver commented 7 years ago

@Zerowalker @b9chris hi, I find Black Picture's reason maybe in static method Utils.Fill_Image_Buffer , the returned Bitmap_Buffer is empty, all data is 0 . I try to use this code

public static byte[,,] Fill_Image_Buffer(Bitmap bmp, IProgress progress, ICurrentOperation operation)
{
    if (operation != null)
        operation.SetOperation(CurrentOperation.FillImageBuffer);

    Point originalSize = GetActualDimension(new Point(bmp.Width, bmp.Height));
    byte[,,] Bitmap_Buffer = new byte[originalSize.X,originalSize.Y, 3];

    Color color;
    for(int y = 0; y < bmp.Height; y++)
    {
        for(int x = 0; x < bmp.Width; x++)
        {
            color = bmp.GetPixel(x, y);
            Bitmap_Buffer[x, y, 0] = color.R;
            Bitmap_Buffer[x, y, 1] = color.G;
            Bitmap_Buffer[x, y, 2] = color.B;
        }
    }

    return Bitmap_Buffer;
}

it can work normal, but will be slow . I hope this is helpful.

b9chris commented 7 years ago

For most image work, I've moved on to leveraging Magick.Net, which is discussed at the bottom of this blog post; I also discuss this library (ArpanJpeg):

http://b9dev.blogspot.com/2013/06/nets-built-in-jpeg-encoder-convenient.html

I've still tabled my work on the Arpan encoder because I found it mostly interesting from a curiosity perspective - cool to see how JPEG encoders work underneath the hood. And, I have an art idea for changing how Progressive JPEGs appear as they resolve, but, I need a month of free time to ever explore that.

So unfortunately I'm still not working on this, but in my using Magick.Net I've learned a lot about image writing, and sometimes I get black images out there as well - and it's almost always because a Stream has its position still set to the end of the Stream, rather than 0, before a write went out to it. It sounds obvious and trivial to fix until you pass Streams between multiple methods/stages in a pipeline. Then it becomes incredibly easy to pass one in the wrong position. And instead of an Exception (which I think should probably throw...) you just get a blank black image.

So that's my lead for others reading this... sorry I'm not working on this project.

ubunterro commented 3 years ago

@Zerowalker @b9chris hi, I find Black Picture's reason maybe in static method Utils.Fill_Image_Buffer , the returned Bitmap_Buffer is empty, all data is 0 . I try to use this code

public static byte[,,] Fill_Image_Buffer(Bitmap bmp, IProgress progress, ICurrentOperation operation)
{
    if (operation != null)
        operation.SetOperation(CurrentOperation.FillImageBuffer);

    Point originalSize = GetActualDimension(new Point(bmp.Width, bmp.Height));
    byte[,,] Bitmap_Buffer = new byte[originalSize.X,originalSize.Y, 3];

    Color color;
    for(int y = 0; y < bmp.Height; y++)
    {
        for(int x = 0; x < bmp.Width; x++)
        {
            color = bmp.GetPixel(x, y);
            Bitmap_Buffer[x, y, 0] = color.R;
            Bitmap_Buffer[x, y, 1] = color.G;
            Bitmap_Buffer[x, y, 2] = color.B;
        }
    }

    return Bitmap_Buffer;
}

it can work normal, but will be slow . I hope this is helpful.

Thanks a lot, I've been looking for a fix for this project and it actually works