saving an image with the image quality flag set to high or best causes empty jpegs. #569

Closed
ofTheo opened this Issue May 11, 2011 · 10 comments

Comments

Projects
None yet
5 participants
Contributor

ofTheo commented May 11, 2011

No description provided.

@ghost ghost assigned bilderbuchi Oct 8, 2012

Owner

bilderbuchi commented Oct 8, 2012

I have assigned myself to try and reproduce this.

Owner

bilderbuchi commented Jan 12, 2013

I tried to reproduce this, but I can't.
Ubuntu 12.10, current OF develop. Modified the imageSaverExample to store jpg instead of png, the default compression level of ofImage::saveImage is already OF_IMAGE_QUALITY_BEST, so there was no need to change that.
@ofTheo, I suspect this bug was solved in the meantime (it's 2 years old). I'll close this, and if you still observe this bug, re-open it with a repro procedure. :-) Thanks!

Have this problem in IOS. I can store an image like a PNG, but a JPG is always 0 bytes.
I've used ofImage.saveImage()

Owner

bilderbuchi commented Apr 8, 2013

@ikillbombs please post some code and/or detailed reproduction steps which show your problem.

Used the imagePickerExample:

      void testApp::update(){
        if(camera) {
        if(camera->imageUpdated){

        int cameraW = camera->width;
        int cameraH = camera->height;
        unsigned const char * cameraPixels = camera->pixels;

        photo.setFromPixels(cameraPixels, cameraW, cameraH, OF_IMAGE_COLOR_ALPHA);

        imgPos.x = ofGetWidth()/2;
        imgPos.y = ofGetHeight()/2;

        camera->close();
        photo.saveImage(ofxiPhoneGetDocumentsDirectory()+"imageInUpdate.png");
        photo.saveImage(ofxiPhoneGetDocumentsDirectory()+"imageInUpdate.jpg");
        delete camera;
        camera = NULL;
        runOnce = true;
    }
  }
 }

@bilderbuchi bilderbuchi reopened this Apr 9, 2013

Owner

bilderbuchi commented Apr 9, 2013

Thanks, I reopened the issue. @ofTheo @julapy could you take a look at this?

I think it is a memory problem. Some other code I use gives a memory error during the usage.

Hi,

I had similar problems related to saving images (although for me it doesn't save no matter what quality I set). I noticed two issues here: memory problems are probably caused by wrong GL_PACK_ALIGNMENT value, the following change in ofTexture::readToPixels helped in my case:

    GLint prevAlignment;
    glGetIntegerv(GL_PACK_ALIGNMENT, &prevAlignment);
    glPixelStorei(GL_PACK_ALIGNMENT, 1);

    pixels.allocate(texData.width,texData.height,ofGetImageTypeFromGLType(texData.glType));
    bind();
    glGetTexImage(texData.textureTarget,0,texData.glType,GL_UNSIGNED_BYTE, pixels.getPixels());
    unbind();

    glPixelStorei(GL_PACK_ALIGNMENT, prevAlignment);

As to empty JPEGs, I noticed that the alpha channel is the problem (you can render to an FBO with GL_RGB format to get rid of it). Sounds reasonable since JPEG doesn't support alpha, but the framework should at least warn you about this.

Seems logical 👍

Contributor

kylemcdonald commented Dec 12, 2014

can't recreate this issue, closing unless @openframeworks/ios can reproduce (sounds like a platform-specific bug).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment