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 minimum value processing of an image is centered on the current pixel. the minimum value of the RGB component of all pixels within a certain radius is used as the component value of the current pixel. If the image contains Alpha information, the Alpha component must be processed in the opposite way, that is, the maximum value.
Procedure dominvalue (var dest: timagedata; const Source: timagedata; radius: integer); var height, ioffset, joffset, dstoffset, srcoffset: integer; ASM push ESI push EDI push EBX push ECx SHL ECx, 1 mov EBX, [edX]. timagedata. stride imul EBX, ECx SHL ECx, 2 add EBX, ECx sub EBX, 4 neg EBX mov ioffset, EBX mov EBX, [edX]. timagedata. stride push ebx shl ebx, 1 sub EBX, ECx mov joffset, EBX call _ setcopyr EGS mov dstoffset, EBX mov srcoffset, eax mov height, EDX pop EBX pop eax @ yloop: Push ECx @ xloop: mov edX, eax pcmpeqb mm0, mm0 movq MM1, mm0 movq mm2, mm0 @ iloop: Push eax @ jloop: pminub MM1, [esi] pminub mm2, [ESI + EBX] add ESI, 8 Dec eax jnz @ jloop movd mm3, [esi] movd mm4, [ESI + EBX] pminub mm0, mm3 pminub mm0, mm4 pop eax add ESI, joffset dec edX jnz @ iloop push eax @ jlloop: pminub MM1, [ESI] Add ESI, 8 Dec eax jnz @ jlloop movd mm3, [esi] pminub mm0, mm3 pop eax pminub mm0, MM1 pminub mm0, mm2 psrscsi MM1, 32 psrscsi mm2, 32 pminub mm0, MM1 pminub mm0, mm2 movd [EDI], mm0 add ESI, ioffset add EDI, 4 loop @ xloop pop ECx add ESI, srcoffset add EDI, dstoffset dec height jnz @ yloop pop EBX pop EDI pop ESI emmsend; Procedure domaxalpha (var dest: timagedata; const Source: timagedata; radius: Integer); var height, ioffset, joffset, dstoffset, srcoffset: integer; ASM push ESI push EDI push ebx shl ECx, 1 Inc ECx push ECx mov EBX, [edX]. timagedata. stride imul EBX, ECx sub EBX, 4 neg EBX mov ioffset, ebx shl ECx, 2 mov EBX, [edX]. timagedata. stride sub EBX, ECx mov joffset, EBX call _ setcopyregs mov dstoffset, EBX mov srcoffset, eax mov height, EDX add ESI, 3 add EDI, 3 POP edX @ yloop: Push ECX @ xloop: mov EBX, edx xor eax, eax @ iloop: Push edX @ jloop: CMP Al, [esi] Jae @ 1 mov Al, [esi] @ 1: Add ESI, 4 Dec edX jnz @ jloop pop edX add ESI, joffset dec EBX jnz @ iloop mov [EDI], Al add ESI, ioffset add EDI, 4 loop @ xloop pop ECx add ESI, srcoffset add EDI, dstoffset dec height jnz @ yloop pop EBX pop EDI pop esiend; // minimum value of image data processing. Parameter: image data, radius procedure imageminvalue (VAR data: timagedata; radius: integer); var SRC: timagedata; begin if data. alphaflag then argbconvertpargb (data); // if the image data contains Alpha information, convert it to pargb SRC: = _ getexpanddata (data, radius ); // obtain the image data source dominvalue (data, SRC, radius) after the extended radius; // the minimum value of image data processing if data. alphaflag then // if the image data contains Alpha information begin domaxalpha (data, SRC, radius); // The Alpha component is used for maximum processing pargbconvertargb (data); // restore pargb to argb end; freeimagedata (SRC); end;
Call example and running effect:
procedure TForm1.Button3Click(Sender: TObject);var bmp: TGpBitmap; g: TGpGraphics; data: TImageData;begin// bmp := TGpBitmap.Create('..\..\media\apple.png'); bmp := TGpBitmap.Create('..\..\media\source.bmp'); data := LockGpBitmap(bmp); ImageMinValue(data, 3); UnlockGpBitmap(bmp, data); g := TGpGraphics.Create(Canvas.Handle); g.DrawImage(bmp, 140, 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".