Delphi Image Processing-color embossed

Source: Internet
Author: User

Reading Tips:

Delphi Image ProcessingThe series focuses on efficiency. The general code is Pascal, and the core code is BaSm.

The C ++ image processing series focuses on code clarity and readability, all using 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" and "Delphi Image Processing-Plane Geometric transformation" transformmatrix. Pas unit.

 

Using the template matrix for Convolution can achieve the color embossed effect of the image. The following code uses the General convolution process described in "Delphi Image Processing-image convolution, to achieve the color embossed effect of the image:

 

var  Data: TImageData;begin  Data := GetImageData(TGpBitmap.Create('d:/56-3.jpg'), True);  ImageConvolutionI(Data, [1, 1, 0, 0, 0, 0, 1, 0, -2]);  DrawImage(Canvas, 0, 0, Data);  FreeImageData(Data);end;

However, similar to the normal implementation of gray relief, it is impossible to implement relief from any angle. Therefore, we adopt the same method of "Delphi Image Processing-grayscale relief, you can flexibly complete the color embossed effects of images of any angle and size. The following is the entire code:

Procedure imagecolorsculpture (VAR data: timagedata; angle: single; Size: longword); var X, Y, radius: integer; xdelta, ydelta: integer; xdelta2, ydelta2: integer; width, height: integer; dstoffset: integer; SRC: timagedata; begin radius: = (size + 1) SHR 1; // image border extension radius angle: = pI * angle/180; size: = size SHL 11; // size = size * 2048 xdelta: = round (COS (angle) * size); ydelta: = round (sin (angle) * size ); xdelta2: = xdelta SHL 1; ydelta2: = ydelta SHL 1; X: = (radius SHL 12)-xdelta; Y: = (radius SHL 12)-ydelta; width: = x + (data. width SHL 12); Height: = Y + (data. height SHL 12); If data. alphaflag then argbconvertpargb (data); SRC: = _ getexpanddata (data, radius); ASM push ESI push EDI push EBX mov eax, data Lea edX, Src call _ setcopyregs mov dstoffset, EBX pxor mm7, mm7 // mm7 = 00 00 00 00 00 00 00 pxor xmm7, xmm7 mov ESI, SRC. scan0 mov EBX, SRC. stride mov ECx, y // For (; y 

The Code uses the quadratic linear interpolation method to calculate the difference between 4 neighboring logical points for each pixel point. The difference calculation principle is the same as the preceding example of the color embossed Effect Using Convolution matrix.

The following is a simple test code:

 

procedure TForm1.Button3Click(Sender: TObject);var  bmp: TGpBitmap;  g: TGpGraphics;  data: TImageData;begin  bmp := TGpBitmap.Create('..\media\20041001.jpg');  g := TGpGraphics.Create(Canvas.Handle);  g.DrawImage(bmp, 0, 0);  data := LockGpBitmap(bmp);  ImageColorSculpture(data, 45, 3);  UnlockGpBitmap(bmp, data);  g.DrawImage(bmp, 0, data.Height);  g.Free;  bmp.Free;end;

Original graph:

Color embossed:

 

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".

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.