source: trunk/FormMain.pas

Last change on this file was 2, checked in by chronos, 5 months ago
  • Modified: Code cleanup.
File size: 1.8 KB
Line 
1unit FormMain;
2
3interface
4
5uses
6 Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls;
7
8type
9
10 { TFormMain }
11
12 TFormMain = class(TForm)
13 MemoLog: TMemo;
14 procedure FormShow(Sender: TObject);
15 private
16
17 public
18 procedure ProcessImage(InputFileName, OutputFileName: string);
19 end;
20
21var
22 FormMain: TFormMain;
23
24
25implementation
26
27{$R *.lfm}
28
29{ TFormMain }
30
31procedure TFormMain.FormShow(Sender: TObject);
32begin
33 MemoLog.Lines.Clear;
34 ProcessImage('Input.png', 'Output.zip');
35 MemoLog.Lines.Add('Finished');
36end;
37
38procedure TFormMain.ProcessImage(InputFileName, OutputFileName: string);
39var
40 Image: TImage;
41 F: TFileStream;
42 Buffer: array of Byte;
43 Offset: TPoint;
44 X, Y: Integer;
45 Pixel: Cardinal;
46 Line: PColor;
47 I: Integer;
48 S: Integer;
49begin
50 Image := TImage.Create(nil);
51 Image.Picture.LoadFromFile(InputFileName);
52 Offset := Point(0, 100);
53
54 F := TFileStream.Create(OutputFileName, fmOpenWrite or fmCreate);
55 SetLength(Buffer, Image.Picture.Bitmap.Width * Image.Picture.Bitmap.Height * 4);
56 X := Offset.X;
57 Y := Offset.Y;
58 I := 0;
59 Line := Image.Picture.Bitmap.ScanLine[Y];
60 Pixel := PColor(Line + X)^ and $ffffff;
61 Inc(Y);
62 S := ((Pixel shr 16) and $ff) or (Pixel and $ff00) or (((Pixel shr 0) and $ff) shl 16);
63 SetLength(Buffer, S);
64 Inc(Y);
65 while Y < Image.Picture.Bitmap.Height do begin
66 Line := Image.Picture.Bitmap.ScanLine[Y];
67 X := Offset.X;
68 while X < Image.Picture.Bitmap.Width do begin
69 Pixel := PColor(Line + X)^;
70 Buffer[I] := (((Pixel shr 20) and $f) shl 0) or
71 (((Pixel shr 12) and $f) shl 4);
72 Inc(X, 2);
73 Inc(I, 1);
74 if I >= Length(Buffer) then Break;
75 end;
76 if I >= Length(Buffer) then Break;
77 Inc(Y, 2);
78 end;
79
80 F.Write(Buffer[0], Length(Buffer));
81 F.Size := Length(Buffer);
82 F.Free;
83 Image.Free;
84end;
85
86end.
87
Note: See TracBrowser for help on using the repository browser.