123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- {
- Free Pascal port of the OpenPTC C++ library.
- Copyright (C) 2001-2006 Nikolay Nikolov ([email protected])
- Original C++ version by Glenn Fiedler ([email protected])
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
- You should have received a copy of the GNU Lesser General Public
- License along with this library; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- }
- Constructor TPTCFormat.Create;
- Begin
- { defaults }
- FFormat.r := 0;
- FFormat.g := 0;
- FFormat.b := 0;
- FFormat.a := 0;
- FFormat.bits := 0;
- FFormat.indexed := False;
- { initialize hermes }
- If Not Hermes_Init Then
- Raise TPTCError.Create('could not initialize hermes');
- End;
- Constructor TPTCFormat.Create(ABits : Integer);
- Begin
- { check bits per pixel }
- If ABits <> 8 Then
- Raise TPTCError.Create('unsupported bits per pixel');
- { indexed color }
- FFormat.r := 0;
- FFormat.g := 0;
- FFormat.b := 0;
- FFormat.a := 0;
- FFormat.bits := ABits;
- FFormat.indexed := True;
- { initialize hermes }
- If Not Hermes_Init Then
- Raise TPTCError.Create('could not initialize hermes');
- End;
- Constructor TPTCFormat.Create(ABits : Integer;
- ARedMask, AGreenMask, ABlueMask : Uint32;
- AAlphaMask : Uint32 = 0);
- Begin
- { check bits per pixel }
- If ((ABits And 7) <> 0) Or (ABits <= 0) Or (ABits > 32) Then
- Raise TPTCError.Create('unsupported bits per pixel');
- { direct color }
- FFormat.r := ARedMask;
- FFormat.g := AGreenMask;
- FFormat.b := ABlueMask;
- FFormat.a := AAlphaMask;
- FFormat.bits := ABits;
- FFormat.indexed := False;
- { initialize hermes }
- If Not Hermes_Init Then
- Raise TPTCError.Create('could not initialize hermes');
- End;
- Constructor TPTCFormat.Create(Const format : TPTCFormat);
- Begin
- { initialize hermes }
- If Not Hermes_Init Then
- Raise TPTCError.Create('could not initialize hermes');
- Hermes_FormatCopy(@format.FFormat, @FFormat)
- End;
- {$INFO TODO: check what happens if Hermes_Init blows up in the constructor...}
- Destructor TPTCFormat.Destroy;
- Begin
- Hermes_Done;
- Inherited Destroy;
- End;
- Procedure TPTCFormat.Assign(Const format : TPTCFormat);
- Begin
- If Self = format Then
- Exit;
- Hermes_FormatCopy(@format.Fformat, @Fformat);
- End;
- Function TPTCFormat.Equals(Const format : TPTCFormat) : Boolean;
- Begin
- Result := Hermes_FormatEquals(@format.FFormat, @FFormat);
- End;
- Function TPTCFormat.GetDirect : Boolean;
- Begin
- Result := Not FFormat.indexed;
- End;
- Function TPTCFormat.GetBytes : Integer;
- Begin
- Result := FFormat.bits Shr 3;
- End;
|