unit JPG_Image interface uses Classes jpeg type TJPG_Image class TJPEG

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
unit JPG_Image;
interface
uses Classes,jpeg;
type
TJPG_Image = class (TJPEGImage)
private
function GetRealSize(Stream: TStream):Integer;
public
procedure LoadFromStream(Stream: TStream); //override;
end;
implementation
{ TJPG_Image }
function sw2(x: Word): Word;
begin
Result:=x and $ff;
Result:=(Result shl 8)+((x shr 8) and $ff);
end;
function TJPG_Image.GetRealSize(Stream: TStream): Integer;
var
pos:Int64;
w: Word;
begin
Result:=0;
pos:=Stream.Position;
Stream.Read(w,2);
if (w=$d8ff) then
begin
while (True) do
begin
if Stream.Position>=Stream.Size-2 then Exit;
Stream.Read(w,2);
if w=$d9ff then Break;
if Lo(w)=$ff then
begin
Stream.Read(w,2);
w:=sw2(w);
Stream.Position:=Stream.Position+w-2;
end
else
Stream.Position:=Stream.Position-1;
end;
Result:=Stream.Position-pos;
end;
end;
procedure TJPG_Image.LoadFromStream(Stream: TStream);
begin
ReadStream(GetRealSize(Stream),Stream);
end;
end.