BradLarson / GPUImage

An open source iOS framework for GPU-based image and video processing
http://www.sunsetlakesoftware.com/2012/02/12/introducing-gpuimage-framework
BSD 3-Clause "New" or "Revised" License
20.23k stars 4.61k forks source link

GPUImageHistogramEqualizationFilter dosen't work #2466

Open kooalle opened 7 years ago

kooalle commented 7 years ago

when I use GPUImageHistogramEqualizationFilter, I found it doesn't work. If I set newHistogramType = kGPUImageHistogramRed , the red color was disappeared in the result. When I set newHistogramType = kGPUImageHistogramRGB , I got a black picture.

I guess the the value colorMapping was not sent to uniform sampler2D inputImageTexture2

the code in GPUImageHistogramEqualizationFilter.m: ` for (unsigned int x = 1; x < 256; x++) { histogramBins[0][x] = histogramBins[0][x-1] + data++; histogramBins[1][x] = histogramBins[1][x-1] + data++; histogramBins[2][x] = histogramBins[2][x-1] + *data++; data++; }

    [_rawDataOutputFilter unlockFramebufferAfterReading];

    GLubyte colorMapping[4 * 256];
    GLubyte *_colorMapping = colorMapping;

    for (unsigned int x = 0; x < 256; x++) {
        *_colorMapping++ = (GLubyte) (((histogramBins[0][x] - histogramBins[0][0]) * 255) / histogramBins[0][255]);
        *_colorMapping++ = (GLubyte) (((histogramBins[1][x] - histogramBins[1][0]) * 255) / histogramBins[1][255]);
        *_colorMapping++ = (GLubyte) (((histogramBins[2][x] - histogramBins[2][0]) * 255) / histogramBins[2][255]);
        *_colorMapping++ = 255;
    }

    _colorMapping = colorMapping;
    [_rawDataInputFilter updateDataFromBytes:_colorMapping size:CGSizeMake(256.0, 1.0)];

[_rawDataInputFilter processData];`

the method updateDataFromBytes in GPUImageRawDataInput.m: `- (void)uploadBytes:(GLubyte *)bytesToUpload; { [GPUImageContext useImageProcessingContext];

// TODO: This probably isn't right, and will need to be corrected
outputFramebuffer = [[GPUImageContext sharedFramebufferCache] fetchFramebufferForSize:uploadedImageSize textureOptions:self.outputTextureOptions onlyTexture:YES];

glBindTexture(GL_TEXTURE_2D, [outputFramebuffer texture]);
glTexImage2D(GL_TEXTURE_2D, 0, _pixelFormat, (int)uploadedImageSize.width, (int)uploadedImageSize.height, 0, (GLint)_pixelFormat, (GLenum)_pixelType, bytesToUpload);

}` the author note that " This probably isn't right, and will need to be corrected", and I want to know how to solve the problem. Thanks. Sorry for my poor English.