Bitmap brightness issue in c++
- by Suriyan Suresh
I have used the following code to adjust the image brightness, i am testing this application in Samsung BADA Platform and its SDK, While i am running this application in bada simulator it never ends runs infinity. Please point out the mistake in the code
int BitmapWidth = 0, BitmapHeight = 0;
result r = E_SUCCESS;
BufferInfo myBuffer;
Osp::Media::Image *pImage = null;
Osp::Graphics::Canvas *pCanvas = null;
Osp::Graphics::Rectangle *pRect = null;
String path("/Media/Images/tom1.jpg");
pImage = new Osp::Media::Image();
r = pImage->Construct();
pBitmap2 = pImage->DecodeN(path, BITMAP_PIXEL_FORMAT_ARGB8888,LCD_WIDTH, LCD_HEIGHT);
BitmapWidth = pBitmap2->GetWidth();
BitmapHeight = pBitmap2->GetHeight();
pBitmap2->Lock( myBuffer);
int nVal = 0;
int stride = myBuffer.pitch;
byte *p= (byte *)(void *)myBuffer.pPixels;
int nWidth = BitmapWidth *3;
int nOffset = stride - BitmapWidth*4;
for (int y = 0; y < BitmapHeight; ++y) {
for (int x = 0; x < nWidth; ++x) {
nVal = (int) (p[0] + nBrightness);
if (nVal < 0)
nVal = 0;
if (nVal > 255)
nVal = 255;
p[0] = (byte) nVal;
++p;
}
p+= nOffset;
}
pBitmap2->Unlock();
pCanvas = GetCanvasN();
// Step 3: Create Rectangle
pRect = new Osp::Graphics::Rectangle(0, 0, LCD_WIDTH, LCD_HEIGHT);
r = pCanvas->DrawBitmap(*pRect, *pBitmap2);
pCanvas->Show();
RequestRedraw(true);
delete pBitmap2;
delete pCanvas;
delete pRect;