本文的线性亮度/对比度调整方法是在《改进的图像线性亮度调整方法》一文中线性亮度调整方法与《Delphi图像处理 -- Photoshop图像亮度/对比度调整》中的对比度调整方法基础上形成的,其原理和特点可参见这2篇文章:
过程定义:
// 线性调整亮度,Value亮度值
procedure ImageLinearBrightness(Data: TImageData; Value: Integer);
// 调整亮度(线性)和对比度
procedure ImageLinearBrightnessAndContrast(Data: TImageData;
Bright, Contrast: Integer; Threshold: LongWord);
实现代码:
procedure ImageLinearbrightness(Data: TImageData; Value: Integer);
asm
push ebp
push esi
push edi
push ebx
test edx, edx // if (Value == 0) return
jz @end
mov ebp, edx
jl @@2
push eax
cmp ebp, 255 // if (Value > 0)
jle @@1 // {
mov ebp, 255 // if (Value > 255) Value = 255
@@1:
mov eax, 65536 // Value = 65536 / (256 - Value) - 256
mov ecx, 256
sub ecx, ebp
cdq
div ecx
sub eax, 256
mov ebp, eax // }
pop eax
@@2:
call SetDataReg32
cld
@yLoop:
push ecx
@xLoop:
push ecx
mov ecx, 3
@RGBLoop:
movzx eax, [edi] // rgb = rgb + rgb * value / 256
mov esi, eax
imul eax, ebp
sar eax, 8
add eax, esi
jns @@3
xor eax, eax
jmp @@4
@@3:
cmp eax, 255
jle @@4
mov eax, 255
@@4:
stosb
loop @RGBLoop
inc edi
pop ecx
loop @xLoop
pop ecx
add edi, ebx
dec edx
jnz @yLoop
@end:
pop ebx
pop edi
pop esi
pop ebp
end;
procedure ImageLinearBrightnessAndContrast(Data: TImageData;
Bright, Contrast: Integer; Threshold: LongWord);
begin
if (Bright <> 0) and (Contrast > 0) then
ImageLinearBrightness(Data, Bright);
ImageContrast(Data, Contrast, Threshold);
if (Bright <> 0) and (Contrast <= 0) then
ImageLinearBrightness(Data, Bright);
end;
&
1.[Error] DCansactionIformationManagement.pas(171): String literals may have at most 255 elements
[Fatal Error] DCMain.pas(32): Could not compile used unit 'DCansactionIformationManagement.pas'
报错:‘不正常定义了参数。提供了不一致或不完整信息’
解决方法:语法
数据定义要一致
2. ......