加好友 发短信
等级:七尾狐
帖子:1791
积分:12764
威望:0
精华:1
注册:2013/7/18 15:51:00
|
[求助]转换代码 Post By:2015/6/20 3:57:00 [显示全部帖子]
如何将下面代码转换成狐表的代码,谢谢 -
-
- FORCEINLINE
- INT CheckValue(INT value)
- {
- return (value & ~0xff) == 0? value : value > 255? 255 : 0;
- }
-
-
-
- VOID LineBrightAndContrast(BitmapData *data, INT bright, INT contrast, BYTE threshold)
- {
- if (bright == 0 && contrast == 0)
- return;
-
- FLOAT bv = bright <= -255? -1.0f : bright / 255.0f;
- if (bright > 0 && bright < 255)
- bv = 1.0f / (1.0f - bv) - 1.0f;
-
- FLOAT cv = contrast <= -255? -1.0f : contrast / 255.0f;
- if (contrast > 0 && contrast < 255)
- cv = 1.0f / (1.0f - cv) - 1.0f;
-
- BYTE values[256];
- for (INT i = 0; i < 256; i ++)
- {
- INT v = contrast > 0? CheckValue(i + (INT)(i * bv + 0.5f)) : i;
- if (contrast >= 255)
- v = v >= threshold? 255 : 0;
- else
- v = CheckValue(v + (INT)((v - threshold) * cv + 0.5f));
- values[i] = contrast <= 0? CheckValue(v + (INT)(v * bv + 0.5f)) : v;
- }
-
- PARGBQuad p = (PARGBQuad)data->Scan0;
- INT offset = data->Stride - data->Width * sizeof(ARGBQuad);
-
- for (UINT y = 0; y < data->Height; y ++, (BYTE*)p += offset)
- {
- for (UINT x = 0; x < data->Width; x ++, p ++)
- {
- p->Blue = values[p->Blue];
- p->Green = values[p->Green];
- p->Red = values[p->Red];
- }
- }
- }
-
-
- void __fastcall TForm1::Button2Click(TObject *Sender)
- {
- Gdiplus::Bitmap *bmp = new Gdiplus::Bitmap(L"..\\..\\media\\source1.jpg");
-
- Gdiplus::Graphics *g = new Gdiplus::Graphics(Canvas->Handle);
- g->DrawImage(bmp, 0, 0);
-
- BitmapData data;
- LockBitmap(bmp, &data);
- LineBrightAndContrast(&data, 20, 0, 121);
- UnlockBitmap(bmp, &data);
-
- g->DrawImage(bmp, data.Width, 0);
-
- delete g;
- delete bmp;
- }
-
|
|