Reading Tips:
《Delphi Image ProcessingThe series focuses on efficiency. The general code is Pascal, and the core code is BaSm.
《C ++ Image ProcessingThe series focuses on code clarity and readability, and all uses C ++ code.
Make sure that the two items are consistent and can be compared with each other.
The code in this article must include the imagedata. Pas unit in "Delphi Image Processing-data type and public process.
The sharpening filter of Photoshop is simple. It is a convolution of the image. Its convolution template is:
0-1 0
-1 8-1
0-1 0
Available《Delphi Image Processing-image convolution"The general convolution process in. However, the special processing process should be faster. Therefore, I wrote an image sharpening process and pasted it below:
procedure DoSharpen(var Dest: TImageData; const Source: TImageData);asm push ebp push esi push edi push ebx mov ebp, [edx].TImageData.Stride call _SetCopyRegs pxor mm7, mm7 pcmpeqw mm5, mm5 psrlw mm5, 15 psllw mm5, 1@@yLoop: push ecx@@xLoop: // dest.argb = (center * 8 - up - down - left - right + 2) / 4 movd mm2, [esi+4] // up movd mm1, [esi+ebp] // left movd mm0, [esi+ebp+4] // center movd mm3, [esi+ebp+8] // right movd mm4, [esi+ebp*2+4]// down punpcklbw mm0, mm7 punpcklbw mm1, mm7 punpcklbw mm2, mm7 punpcklbw mm3, mm7 punpcklbw mm4, mm7 psllw mm0, 3 psubw mm0, mm1 psubw mm0, mm2 psubw mm0, mm3 psubw mm0, mm4 paddw mm0, mm5 psraw mm0, 2 packuswb mm0, mm7 movd [edi], mm0 add esi, 4 add edi, 4 loop @@xLoop pop ecx add esi, eax add edi, ebx dec edx jnz @@yLoop pop ebx pop edi pop esi pop ebp emmsend;procedure ImageSharpen(var Data: TImageData);var src: TImageData;begin if Data.AlphaFlag then ArgbConvertPArgb(Data); src := _GetExpandData(Data, 1); DoSharpen(Data, src); if Data.AlphaFlag then PArgbConvertArgb(Data); FreeImageData(src);end;
The following is a simple example of calling the sharpening process:
procedure TForm1.Button1Click(Sender: TObject);var bmp: TGpBitmap; g: TGpGraphics; data: TImageData;begin bmp := TGpBitmap.Create('..\..\media\source.bmp'); data := LockGpBitmap(bmp); ImageSharpen(data); UnlockGpBitmap(bmp, data); g := TGpGraphics.Create(Canvas.Handle); g.DrawImage(bmp, 0, 0); g.Free; bmp.Free;end;
For details about the use of GDI + units and descriptions in the "Delphi image processing" series, see the article 《GDI + for VCL basics-GDI + and VCL.
Due to limited levels, errors are inevitable. Correction and guidance are welcome. Email Address:Maozefa@hotmail.com
Here, you can access "Delphi Image Processing-Article Index".