The general principle of image relief is to form a difference between each pixel on the image and its diagonal pixel, so that similar color values are reduced and different color values are highlighted, resulting in a vertical depth, to achieve the relief effect, the specific approach is to subtract two pixel values in the diagonal line, plus a background constant, generally 128. This Algorithm Its features are simple and quick, but its disadvantage is that it cannot adjust the angle and depth of the image relief effect.
Using Photoshop to implement image relief effects, you can adjust the relief angle and depth (the distance between two pixels), and adjust the number of pixel differences. The basic algorithm principle is the same as the general relief effect, but the specific method is different: For each pixel to be processed, the position of two corresponding points is calculated according to the relief angle and depth, then, calculate the color value of the two positions and make it form the difference value. Then, multiply the percentage of the difference value in the relief, and add the background color of 128. Note that the two corresponding points calculated here are logical points rather than actual pixels. For example, to implement an image relief effect with a 45 degree angle and a depth of 3, P (x, y). The locations of the two logical points are P0 (X-3*0.7071/2, Y-3*0.7071/2) and p1 (x + 3*0.7071/2, Y + 3*0.7071/2), obviously for such two logical points, it is impossible to find the corresponding pixel from the image directly. If it is simply rounded down, it will produce a large number of identical relief effects formed by different angles and depths, this is not the expected result, and it makes the relief angle and depth parameters lose its original meaning. To this end, the original image must be scaled according to the relief angle and depth, then the relief effect of each pixel is processed, and then the original image size is reduced to complete the relief effect process. The following is the Photoshop embossed effect implementation process I wrote after repeated experiments.Code:
Data Type:
-
- Type
- // Image data structure compatible with the GDI + tbitmapdata Structure
-
- Timagedata =Packed Record
-
- Width: longword;// Image Width
-
- Height: longword;// Image Height
-
- Stride: longword;// Scanned line Byte Length
-
- Pixelformat: longword;// Unused
- Scan0: pointer;// Image data address
-
- Reserved: longword;// Reserved
-
- End;
-
- Pimagedata = ^ timagedata;
-
-
-
- // Obtain the timagedata data structure of the tbitmap image to facilitate the processing of the tbitmap Image
-
- FunctionGetimagedata (BMP: tbitmap): timagedata;
-
- Begin
- BMP.Pixelformat: = pf32bit;
-
- Result.Width: = BMP.Width;
-
- Result.Height: = BMP.Height;
-
- Result.Scan0: = BMP.Scanline [BMP.Height-1];
-
- Result.Stride: = Result.WidthSHL 2;
- // Result. stride: = (32 * BMP. width) + 31) and $ ffffffe0) SHR 3;
-
- End;
-
-