Registriert seit: 16. Jan 2004
Ort: Bendorf
5.219 Beiträge
Delphi 10.2 Tokyo Professional
|
Re: TGA - Was ein Dateiformat o.O
14. Aug 2006, 13:35
Also das Bild usw wird alles wunderbar ausgelesen, aber ab dem markierten Bereich läuft irgendwas falsch. Ich habe mir mal aus dem Metadata-Bereich einige Werte anzeigen lassen und die können einfach nicht so stimmen... Ich habe schon tausendmal drübergeguckt, aber ich konnte keinen Fehler entdecken
Meine Informationen habe ich aus Wikipedia:
Delphi-Quellcode:
procedure TTgaImage.LoadFromStream(AStream: TStream);
var i,j: Integer;
buf: Word;
lPtr: Pointer;
begin
AStream.Read(TGAInfo.Header.IDLength, SizeOf(Byte));
AStream.Read(TGAInfo.Header.HasPalette, SizeOf(Byte));
AStream.Read(TGAInfo.Header.PictureFormat, SizeOf(Byte));
// Palette-Info
AStream.Read(TGAInfo.Header.Palette.Start, SizeOf(Word));
AStream.Read(TGAInfo.Header.Palette.Length, SizeOf(Word));
AStream.Read(TGAInfo.Header.Palette.Size, SizeOf(Byte));
// Zero Point
AStream.Read(TGAInfo.Header.xZero, SizeOf(Word));
AStream.Read(TGAInfo.Header.yZero, SizeOf(Word));
// Picture Width/Height
AStream.Read(TGAInfo.Header.Width, SizeOf(Word));
AStream.Read(TGAInfo.Header.Height, SizeOf(Word));
// Bits per Pixel
AStream.Read(TGAInfo.Header.Bpp, SizeOf(Byte));
// Attrubutes
AStream.Read(TGAInfo.Header.Attributes, SizeOf(Byte));
if TGAInfo.Header.IDLength > 0 then
begin
SetLength(TGAInfo.ID, TGAInfo.Header.IDLength);
AStream.Read(TGAInfo.ID[0], TGAInfo.Header.IDLength);
end;
if Boolean(TGAInfo.Header.HasPalette) then
begin
SetLength(TGAInfo.Palette.Colors,TGAInfo.Header.Palette.Length);
case TGAInfo.Header.Palette.Size of
15,16: begin
for i:= 0 to TGAInfo.Header.Palette.Length-1 do
begin
AStream.Read(buf,2);
TGAInfo.Palette.Colors[i].R := (buf and $7C00) shr 10;
TGAInfo.Palette.Colors[i].G := (buf and $03E0) shr 5;
TGAInfo.Palette.Colors[i].B := (buf and $001F);
end;
// Ist alles noch beta
end;
24: begin
for i:= 0 to TGAInfo.Header.Palette.Length-1 do
begin
AStream.Read(TGAInfo.Palette.Colors[i].B,SizeOf(Byte));
AStream.Read(TGAInfo.Palette.Colors[i].G,SizeOf(Byte));
AStream.Read(TGAInfo.Palette.Colors[i].R,SizeOf(Byte));
end;
end;
32: begin
// Ist alles noch beta
end;
end;
end;
SetLength(TGAInfo.Picture, TGAInfo.Header.Width, TGAInfo.Header.Height);
// Read Picture Data
if TGAInfo.Header.PictureFormat in [1..3] then
begin
FBitmap.Width := TGAInfo.Header.Width;
FBitmap.Height := TGAInfo.Header.Height;
FBitmap.PixelFormat := pf24bit;
for i:= 0 to FBitmap.Height-1 do
begin
lptr := FBitmap.ScanLine[i];
AStream.Read(lptr^,SizeOf(Byte)*3*FBitmap.Width);
end;
end
else if TGAInfo.Header.PictureFormat in [9..11] then
begin
// Wird später eingefügt
end;
// Read First Footer
AStream.Position := AStream.Size - 26;
AStream.Read(TGAInfo.Footer.MetaOffset, SizeOf(Longword));
AStream.Read(TGAInfo.Footer.DevOffset, SizeOf(Longword));
for i:= 0 to 17 do
AStream.Read(TGAInfo.Footer.Signature[i], SizeOf(Char));
{
!!!!!!! ------------- !!!!!!! <-- ab hier läuft was schief :|
}
// Dev Area
AStream.Position := TGAInfo.Footer.DevOffset;
AStream.Read(TGAInfo.DevCount, SizeOf(Word));
SetLength(TGAInfo.DevelopmentAreas, TGAInfo.DevCount);
for i:= 0 to TGAInfo.DevCount-1 do
begin
AStream.Read(TGAInfo.DevelopmentAreas[i].ID, SizeOf(Word));
AStream.Read(TGAInfo.DevelopmentAreas[i].Offset, SizeOf(Longword));
AStream.Read(TGAInfo.DevelopmentAreas[i].Size, SizeOf(Longword));
end;
AStream.Position := TGAInfo.Footer.MetaOffset;
AStream.Read(TGAInfo.Metadata.Size, SizeOf(Longword));
SetLength(TGAInfo.Metadata.Author, 41);
AStream.Read(TGAInfo.Metadata.Author[0], 41);
SetLength(TgaInfo.Metadata.Comment, 324);
AStream.Read(TGAInfo.Metadata.Comment[0], 324);
AStream.Read(TGAInfo.Metadata.Month, SizeOf(Word));
AStream.Read(TGAInfo.Metadata.Day, SizeOf(Word));
AStream.Read(TGAInfo.Metadata.Year, SizeOf(Word));
AStream.Read(TGAInfo.Metadata.Hour, SizeOf(Word));
AStream.Read(TGAInfo.Metadata.Minute, SizeOf(Word));
AStream.Read(TGAInfo.Metadata.Second, SizeOf(Word));
SetLength(TGAInfo.Metadata.Jobname, 41);
AStream.Read(TGAInfo.Metadata.Jobname[0], 41);
AStream.Read(TGAInfo.Metadata.JHour, SizeOf(Word));
AStream.Read(TGAInfo.Metadata.JMinute, SizeOf(Word));
AStream.Read(TGAInfo.Metadata.JSecond, SizeOf(Word));
SetLength(TGAInfo.Metadata.SoftwareID, 41);
AStream.Read(TGAInfo.Metadata.SoftwareID[0], 41);
// Version
AStream.Read(TGAInfo.Metadata.Version, SizeOf(Word));
AStream.Read(TGAInfo.Metadata.VersionEx, SizeOf(Byte));
// Realations + BG Color
AStream.Read(TGAInfo.Metadata.BackgroundColor, SizeOf(Longword));
AStream.Read(TGAInfo.Metadata.PixRealationH, SizeOf(Word));
AStream.Read(TGAInfo.Metadata.PixRealationL, SizeOf(Word));
// Gamma Info
AStream.Read(TGAInfo.Metadata.GammaH, SizeOf(Word));
AStream.Read(TGAInfo.Metadata.GammaL, SizeOf(Word));
AStream.Read(TGAInfo.Metadata.ColorCorrTabOffset, SizeOf(Longword));
AStream.Read(TGAInfo.Metadata.ThumbnailOffset, SizeOf(Longword));
AStream.Read(TGAInfo.Metadata.ScanLineOffset, SizeOf(Longword));
// Scanline Info
SetLength(TGAInfo.ScanLineInfo, TGAInfo.Header.Height * SizeOf(Longword));
AStream.Read(TGAInfo.ScanLineInfo[0], TGAInfo.Header.Height * SizeOf(Longword));
// Thumbnail Width/Height
AStream.Read(TGAInfo.Tumbnail.Width, SizeOf(Byte));
AStream.Read(TGAInfo.Tumbnail.Width, SizeOf(Byte));
FThumb.Width := TGAInfo.Tumbnail.Width;
FThumb.Height := TGAInfo.Tumbnail.Height;
FThumb.PixelFormat := pf24bit;
// Thumbnail Data
for i:= 0 to FThumb.Height-1 do
begin
lptr := FThumb.ScanLine[i];
AStream.Read(lptr^,SizeOf(Byte)*3*FThumb.Width);
end;
// Color Correction Tab
for i:= 0 to 255 do begin
for j:= 0 to 4 do begin
AStream.Read(TGAInfo.ColorCorTab[i,j], SizeOf(Longword));
end;
end;
end;
Kann sich vielleicht einer die Mühe machen und mal gucken ob er einen Fehler findet ?
Also ich finde nichts...
[EDIT]: Ach ja wenn ich
Delphi-Quellcode:
AStream.Position := TGAInfo.Metadata.ScanLineOffset;
AStream.Position := TGAInfo.Metadata.ThumbnailOffset;
AStream.Position := TGAInfo.Metadata.ColorCorrTabOffset;
an den enstprechenden Stellen einfüge dann gibts en Fehler beim Laden -.- [/EDIT]
Gruß
Neutral General
Michael "Programmers talk about software development on weekends, vacations, and over meals not because they lack imagination,
but because their imagination reveals worlds that others cannot see."
|