File: tiffimage.inc

package info (click to toggle)
lazarus 4.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 275,760 kB
  • sloc: pascal: 2,341,904; xml: 509,420; makefile: 348,726; cpp: 93,608; sh: 3,387; java: 609; perl: 297; sql: 222; ansic: 137
file content (149 lines) | stat: -rw-r--r-- 4,299 bytes parent folder | download
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
{%MainUnit ../graphics.pp}

{******************************************************************************
                                TTiffImage
 ******************************************************************************

 *****************************************************************************
  This file is part of the Lazarus Component Library (LCL)

  See the file COPYING.modifiedLGPL.txt, included in this distribution,
  for details about the license.
 *****************************************************************************
}

{ TTiffImage }

constructor TTiffImage.Create;
begin
  inherited Create;
  FSoftware := 'TTiffImage - Lazarus LCL: ' + lcl_version + ' - FPC: ' + {$I %FPCVERSION%};
end;

procedure TTiffImage.FinalizeReader(AReader: TFPCustomImageReader);
var
  D, T: TDateTime;
  S: String;
  YY, MM, DD, HH, NN, SS: Integer;
  IFD: TTiffIFD;
begin
  IFD:=TFPReaderTiff(AReader).FirstImg;
  FArtist := IFD.Artist;
  FCopyright := IFD.Copyright;

  S := IFD.DateAndTime;
  // YYYY:MM:DD HH:MM:SS
  // 0000000001111111111
  // 1234567890123456789
  if  TryStrToInt(Copy(S, 1, 4), YY)
  and TryStrToInt(Copy(S, 6, 2), MM)
  and TryStrToInt(Copy(S, 9, 2), DD)
  and TryStrToInt(Copy(S, 12, 2), HH)
  and TryStrToInt(Copy(S, 15, 2), NN)
  and TryStrToInt(Copy(S, 18, 2), SS)
  and TryEncodeDate(YY, MM, DD, D)
  and TryEncodeTime(HH, NN, SS, 0, T)
  then FDateTime := ComposeDateTime(D,T)
  else FDateTime := 0;

  FDocumentName := IFD.DocumentName;
  FHostComputer := IFD.HostComputer;
  FImageDescription := IFD.ImageDescription;
  FMake := IFD.Make_ScannerManufacturer;
  FModel := IFD.Model_Scanner;
  case IFD.ResolutionUnit of
    1: FResolutionUnit := tuNone;
    2: FResolutionUnit := tuInch;
    3: FResolutionUnit := tuCentimeter;
  else
    FResolutionUnit := tuUnknown;
  end;
  FSoftware := IFD.Software;
  FXResolution := IFD.XResolution;
  FYResolution := IFD.YResolution;
  inherited;
end;

class function TTiffImage.GetFileExtensions: string;
begin
  Result := 'tif;tiff';
end;

class function TTiffImage.GetReaderClass: TFPCustomImageReaderClass;
begin
  Result := TLazReaderTiff;
end;

class function TTiffImage.GetSharedImageClass: TSharedRasterImageClass;
begin
  Result := TSharedTiffImage;
end;

class function TTiffImage.GetWriterClass: TFPCustomImageWriterClass;
begin
  Result := TLazWriterTiff;
end;

procedure TTiffImage.InitializeReader(AImage: TLazIntfImage; AReader: TFPCustomImageReader);
begin
  inherited;
end;

procedure TTiffImage.InitializeWriter(AImage: TLazIntfImage; AWriter: TFPCustomImageWriter);
begin
  inherited;

  if FArtist = ''
  then AImage.RemoveExtra(TiffArtist)
  else AImage.Extra[TiffArtist] := FArtist;

  if FCopyright = ''
  then AImage.RemoveExtra(TiffCopyright)
  else AImage.Extra[TiffCopyright] := FCopyright;

  if FDateTime = 0
  then AImage.RemoveExtra(TiffDateTime)
  else AImage.Extra[TiffDateTime] := FormatDateTime('YYYY:MM:DD HH:NN:SS', FDateTime);

  if FDocumentName = ''
  then AImage.RemoveExtra(TiffDocumentName)
  else AImage.Extra[TiffDocumentName] := FDocumentName;

  if FImageDescription = ''
  then AImage.RemoveExtra(TiffImageDescription)
  else AImage.Extra[TiffImageDescription] := FImageDescription;

  case FResolutionUnit of
    tuNone: AImage.Extra[TiffResolutionUnit] := '1';
    tuInch: AImage.Extra[TiffResolutionUnit] := '2';
    tuCentimeter: AImage.Extra[TiffResolutionUnit] := '3';
  else
    AImage.RemoveExtra(TiffResolutionUnit);
  end;

  if (FXResolution.Denominator = 0) and (FXResolution.Numerator = 0)
  then AImage.RemoveExtra(TiffXResolution)
  else AImage.Extra[TiffXResolution] := TiffRationalToStr(FXResolution);

  if (FYResolution.Denominator = 0) and (FYResolution.Numerator = 0)
  then AImage.RemoveExtra(TiffYResolution)
  else AImage.Extra[TiffYResolution] := TiffRationalToStr(FYResolution);

  if FHostComputer = ''
  then AImage.RemoveExtra(LazTiffHostComputer)
  else AImage.Extra[LazTiffHostComputer] := FHostComputer;

  if FMake = ''
  then AImage.RemoveExtra(LazTiffMake)
  else AImage.Extra[LazTiffMake] := FMake;

  if FModel = ''
  then AImage.RemoveExtra(LazTiffModel)
  else AImage.Extra[LazTiffModel] := FModel;

  if FSoftware = ''
  then AImage.RemoveExtra(LazTiffSoftware)
  else AImage.Extra[LazTiffSoftware] := FSoftware;

end;