title: Brightness without OpenGL call
body: <p>I am performing Brightness on UIImage with following src code ref. When I check this code with Instrument ,getting memory leak of 1 MB for each brightness call. I am changing brightness with slider. after debugging come to know    </p>
  
  <pre><code>CFDataRef dataref=CGDataProviderCopyData(CGImageGetDataProvider(aInputImage.CGImage));
  </code></pre>
  
  <p>is taking a memory, can anyone help me to optimize this code.</p>
  
  <pre><code> // ## Brightness without Open GL call
  
      CGImageRef Brightness(UIImage* aInputImage, float aFactor)
      {
          CGImageRef img=aInputImage.CGImage;
  
          CFDataRef dataref=CGDataProviderCopyData(CGImageGetDataProvider(aInputImage.CGImage));
  
  
          UInt8 *data=(UInt8 *)CFDataGetBytePtr(dataref);
  
          int length=CFDataGetLength(dataref);
  
          // Perform operation on pixels
          for(int index=0;index&lt;length;index+=4)
          {
              // Go For BRIGHTNESS
              for(int i=0;i&lt;3;i++)
              {
                  if(data[index+i]+aFactor&lt;0)
                  {
                      data[index+i]=0;
                  }
                  else
                  {
                      if(data[index+i]+aFactor&gt;255)
                      {
                          data[index+i]=255;
                      }
                      else
                      {
                          data[index+i]+=aFactor;
                      }
                  }
              }
          }
  
          // .. Take image attributes
          size_t width=CGImageGetWidth(img);
          size_t height=CGImageGetHeight(img);
          size_t bitsPerComponent=CGImageGetBitsPerComponent(img);
          size_t bitsPerPixel=CGImageGetBitsPerPixel(img);
          size_t bytesPerRow=CGImageGetBytesPerRow(img);
  
          // .. Do the pixel manupulation
          CGColorSpaceRef colorspace=CGImageGetColorSpace(img);
          CGBitmapInfo bitmapInfo=CGImageGetBitmapInfo(img);
          CFDataRef newData=CFDataCreate(NULL,data,length);
          CGDataProviderRef provider=CGDataProviderCreateWithCFData(newData);
  
          // .. Get the Image out of this raw data
          CGImageRef newImg=CGImageCreate(width,height,bitsPerComponent,bitsPerPixel,bytesPerRow,colorspace,bitmapInfo,provider,NULL,true,kCGRenderingIntentDefault);
  
          // .. Prepare the image from raw data
          UIImage* rawImage = [[UIImage alloc] initWithCGImage:newImg];
  
          // .. done with all,so release the references
          CGImageRelease(newImg);
          CGDataProviderRelease(provider);
          CFRelease(dataref);
  
          return rawImage.CGImage;
      }
  </code></pre>
  
  <p>Thanks,</p>
  
  <p>Sagar</p>