Search code examples
iosobjective-copengl-esgpuimage

GPUImage - Custom Histogram Generator


I'm trying to use GPUImage to implement a histogram into my app. The example project on the GPUImage github called FilterShowcase comes with a good histogram generator, but due to the UI design of the app I'm making I'll need to write my own custom graph to display the histogram values. Does anyone know how can I get the RGB values from the GPUImageHistogramFilter so I can pop them into my own graph?


Solution

  • The GPUImageHistogramFilter produces a 256x3 image where the center 256x1 line of that contains the red, green, and blue values for the histogram packed in the RGB channels. iOS doesn't support a 1-pixel-high render framebuffer, so I have to pad it out to three pixels high.

    The GPUImageHistogramGenerator creates the visible histogram overlay you see in the sample applications, and it does that by taking in the 256x3 image and rendering an output image using a custom shader that colors in bars whose height depends on the input color value. It's a quick, on-GPU implementation.

    If you want to do something more custom that doesn't use a shader, you can extract the histogram values using a GPUImageRawDataOutput and pulling out the RGB components of the center 256x1 line. From there, you could draw the rest of your interface overlay, although something done using Core Graphics may chew a lot of processing power to update on every frame.