SDL PixelFormat: Unterschied zwischen den Versionen

Aus DGL Wiki
Wechseln zu: Navigation, Suche
K
Zeile 1: Zeile 1:
 
= SDL_Pixelformat =
 
= SDL_Pixelformat =
 
{{Offline|Abschnitt Beispiel wird überarbeitet}}
 
  
 
== Name ==
 
== Name ==
 
'''SDL_Pixelformat''' - Speichert Surfaceformatinformationen
 
'''SDL_Pixelformat''' - Speichert Surfaceformatinformationen
<br>
+
 
 +
 
 
== Delphi-Spezifikation ==
 
== Delphi-Spezifikation ==
type SDL_Pixelformat = record
+
<pascal> type SDL_Pixelformat = record
 
       ''palette''                        : PSDL_Palette;
 
       ''palette''                        : PSDL_Palette;
 
       ''BitsPerPixel''                  : Uint8;
 
       ''BitsPerPixel''                  : Uint8;
Zeile 16: Zeile 15:
 
       ''colorkey''                      : Uint32;
 
       ''colorkey''                      : Uint32;
 
       ''alpha''                          : Uint8;
 
       ''alpha''                          : Uint8;
  end;
+
  end;</pascal>
<br>
 
  
 
== Parameter ==
 
== Parameter ==
Zeile 23: Zeile 21:
 
{| border="1" rules="all"
 
{| border="1" rules="all"
 
!''palette''
 
!''palette''
|Zeiger auf die Farbpalette oder '''nil''' wenn BitsPerPixel>8 ist.
+
|Zeiger auf die Farbpalette oder '''nil''' wenn keine Palette vorhanden (meistens BitsPerPixel > 8).
 
|-
 
|-
 
!''BitsPerPixel''
 
!''BitsPerPixel''
Zeile 35: Zeile 33:
 
|-
 
|-
 
!''[RGBA]loss''
 
!''[RGBA]loss''
|Prezisionsverlust jedes Farbwertes (2^[RGBA]loss).
+
|Präzisionsverlust jedes Farbwertes (2^[RGBA]loss).
 
|-
 
|-
 
!''[RGBA]shift''
 
!''[RGBA]shift''
Zeile 59: Zeile 57:
 
Wenn man einzelne Pixel in einer Surface verändern will sollte man erst verstehen wie SDL diese Farbinformationen speichert.
 
Wenn man einzelne Pixel in einer Surface verändern will sollte man erst verstehen wie SDL diese Farbinformationen speichert.
  
Das 8-Bit Format ist am einfachsten zu verstehen. Jeder Pixel ist ein Uint8 welcher den Farbindex aus palette.colors enthält.
+
Ein palettiertes 8-Bit Format ist am einfachsten zu verstehen. Jeder Pixel ist ein Uint8 welcher den Farbindex aus ''palette.colors'' enthält. Um die Farbe eines Pixels in einer 8-Bit Surface zu bestimmen lesen wir einen den Farbindex aus ''surface.pixels'' und benutzen diesen Index um die [[SDL_Color]] Struktur von ''surface.format.palette.colors'' zu lesen:
Um die Farbe eines Pixels in einer 8-Bit Surface zu bestimmen lesen wir einen den Farbindex aus surface.pixels und benutzen diesen Index um die [[SDL_Color]] Struktur von surface.format.palette.colors zu lesen:
 
  
 
<pascal>var surface: PSDL_Surface;
 
<pascal>var surface: PSDL_Surface;
Zeile 70: Zeile 67:
 
.
 
.
 
.
 
.
   fmt:=surface.format;
+
   fmt := surface.format;
 
    
 
    
 
   //Überprüfung der Bitsperpixel
 
   //Überprüfung der Bitsperpixel
   if fmt.BitsPerPixel<>8 then
+
   if fmt.BitsPerPixel <> 8 then
 
   begin
 
   begin
 
     writeln('keine 8-Bit Surface');
 
     writeln('keine 8-Bit Surface');
Zeile 83: Zeile 80:
  
 
   //den link oberen Pixel bekommen
 
   //den link oberen Pixel bekommen
   index:=Uint8(surface.pixels^);
+
   index := Uint8(surface.pixels^);
   color:=fmt.palette.colors[index];
+
   color := fmt.palette.colors[index];
  
 
   //Entsperren der Surface
 
   //Entsperren der Surface
Zeile 91: Zeile 88:
 
end;</pascal>
 
end;</pascal>
 
<br>
 
<br>
Pixelformate über 8 Bit sind eine komplett andere Erfahrung. Dies sind "TrueColor" Formate und die Farbinformationen sind im Pixel selber gespeichert, nicht in einer Palette. Die ''mask'', ''shift'' und ''loss'' Felder sagen uns wie die Farbinformationen codiert sind.
+
Pixelformate ohne Palette sind eine komplett andere Erfahrung. Bei diesen Formaten sind die Farbinformationen in dem Pixel direkt codiert. Das ''mask'' Feld erlaubt uns jede einzelne Farbkomponente zu isolieren. Das ''shift'' Feld sagt uns die Anzahl der Bits rechts von jeder Komponente und das ''loss'' Feld sagt wieviele Bits von jeder Komponente verloren gingen als sie in 8 Bit Farbkomponenten gepackt wurden.
Das ''mask'' Feld erlaubt uns jede einzelne Farbkomponente zu isolieren. Das ''shift'' Feld sagt uns die Anzahl der Bits rechts von jeder Komponente und das ''loss'' Feld sagt wieviele Bits von jeder Komponente verloren gingen als sie in 8 Bit Farbkomponenten gepackt wurden.
 
  
 
<pascal>var fmt: PSDL_Pixelformat;
 
<pascal>var fmt: PSDL_Pixelformat;
Zeile 102: Zeile 98:
 
.
 
.
 
.
 
.
   fmt:=surface.format;
+
   fmt := surface.format;
 
   SDL_LockSurface(surface);
 
   SDL_LockSurface(surface);
   pixel:=Uint32(surface.pixels^);
+
   pixel := Uint32(surface.pixels^);
 
   SDL_UnlockSurface(surface);
 
   SDL_UnlockSurface(surface);
  
 
   //Rote Komponente
 
   //Rote Komponente
   temp:=pixel and fmt.Rmask; //Isolieren der roten Komponente
+
   temp := pixel and fmt.Rmask; //Isolieren der roten Komponente
   temp:=temp shr fmt.Rshift; //Auf 8 Bit zurückschieben
+
   temp := temp shr fmt.Rshift; //Auf 8 Bit zurückschieben
   temp:=temp shl fmt.Rloss;  //Auf eine volle 8 Bit Zahl expandieren
+
   temp := temp shl fmt.Rloss;  //Auf eine volle 8 Bit Zahl expandieren
   red:=(Uint8)temp;
+
   red := (Uint8)temp;
  
 
   //Grüne Komponente
 
   //Grüne Komponente
   temp:=pixel and fmt.Gmask; //Isolieren der grünen Komponente
+
   temp := pixel and fmt.Gmask; //Isolieren der grünen Komponente
   temp:=temp shr fmt.Gshift; //Auf 8 Bit zurückschieben
+
   temp := temp shr fmt.Gshift; //Auf 8 Bit zurückschieben
   temp:=temp shl fmt.Gloss;  //Auf eine volle 8 Bit Zahl expandieren
+
   temp := temp shl fmt.Gloss;  //Auf eine volle 8 Bit Zahl expandieren
   green:=(Uint8)temp;
+
   green := (Uint8)temp;
  
 
   //Blaue Komponente
 
   //Blaue Komponente
   temp:=pixel and fmt.Bmask; //Isolieren der blauen Komponente
+
   temp := pixel and fmt.Bmask; //Isolieren der blauen Komponente
   temp:=temp shr fmt.Bshift; //Auf 8 Bit zurückschieben
+
   temp := temp shr fmt.Bshift; //Auf 8 Bit zurückschieben
   temp:=temp shl fmt.Bloss;  //Auf eine volle 8 Bit Zahl expandieren
+
   temp := temp shl fmt.Bloss;  //Auf eine volle 8 Bit Zahl expandieren
   blue:=(Uint8)temp;
+
   blue := (Uint8)temp;
  
 
   //Alpha Komponente
 
   //Alpha Komponente
   temp:=pixel and fmt.Amask; //Isolieren des Alphawerts
+
   temp := pixel and fmt.Amask; //Isolieren des Alphawerts
   temp:=temp shr fmt.Ashift; //Auf 8 Bit zurückschieben
+
   temp := temp shr fmt.Ashift; //Auf 8 Bit zurückschieben
   temp:=temp shl fmt.Aloss;  //Auf eine volle 8 Bit Zahl expandieren
+
   temp := temp shl fmt.Aloss;  //Auf eine volle 8 Bit Zahl expandieren
   alpha:=(Uint8)temp;
+
   alpha := (Uint8)temp;
  
 
   writeln('Pixelfarbe -> R: '+InttoStr(red)+' G: '+InttoStr(green)+' B: '+InttoStr(blue)+' A: '+InttoStr(alpha));
 
   writeln('Pixelfarbe -> R: '+InttoStr(red)+' G: '+InttoStr(green)+' B: '+InttoStr(blue)+' A: '+InttoStr(alpha));

Version vom 28. Januar 2007, 01:17 Uhr

SDL_Pixelformat

Name

SDL_Pixelformat - Speichert Surfaceformatinformationen


Delphi-Spezifikation

 type SDL_Pixelformat = record
      ''palette''                        : PSDL_Palette;
      ''BitsPerPixel''                   : Uint8;
      ''BytesPerPixel''                  : Uint8;
      ''Rloss'', ''Gloss'', ''Bloss'', ''Aloss''     : Uint8;
      ''Rshift'', ''Gshift'', ''Bshift'', ''Ashift'' : Uint8;
      ''Rmask'', ''Gmask'', ''Bmask'', ''Amask''     : Uint8;
      ''colorkey''                       : Uint32;
      ''alpha''                          : Uint8;
 end;

Parameter

palette Zeiger auf die Farbpalette oder nil wenn keine Palette vorhanden (meistens BitsPerPixel > 8).
BitsPerPixel Die Anzahl der Bits die benutzt werden um einen Pixel in einer Surface zu beschreiben. Normalerweise 8, 16, 24 oder 32.
BytesPerPixel Die Anzahl der Bytes die einen Pixel in einer Surface beschreiben. Normalerweise 1 bis 4.
[RGBA]mask Binäre Maske die benutzt wird um die individuellen Farbwerte zu bekommen.
[RGBA]loss Präzisionsverlust jedes Farbwertes (2^[RGBA]loss).
[RGBA]shift Binäre Linksverschiebung von der Farbekomponente in dem Pixelwert.
colorkey Pixelwert von transpartenten Pixeln.
alpha Allgemeiner Surface Alphawert.



Beschreibung

SDL_PixelFormat beschreibt das Format der Pixeldaten die im Pixelfeld einer SDL_Surface gespeichert sind. Jede Surface speichert ein SDL_Pixelformat in ihrem Formatfeld.


Beispiel

Wenn man einzelne Pixel in einer Surface verändern will sollte man erst verstehen wie SDL diese Farbinformationen speichert.

Ein palettiertes 8-Bit Format ist am einfachsten zu verstehen. Jeder Pixel ist ein Uint8 welcher den Farbindex aus palette.colors enthält. Um die Farbe eines Pixels in einer 8-Bit Surface zu bestimmen lesen wir einen den Farbindex aus surface.pixels und benutzen diesen Index um die SDL_Color Struktur von surface.format.palette.colors zu lesen:

var surface: PSDL_Surface;
    fmt: PSDL_PixelFormat;
    color: PSDL_Color;
    index: Uint8;
begin
//Erstellung der Surface
.
.
  fmt := surface.format;
  
  //Überprüfung der Bitsperpixel
  if fmt.BitsPerPixel <> 8 then
  begin
    writeln('keine 8-Bit Surface');
    exit;
  end;

  //Surface sperren
  SDL_LockSurface(surface);

  //den link oberen Pixel bekommen
  index := Uint8(surface.pixels^);
  color := fmt.palette.colors[index];

  //Entsperren der Surface
  SDL_UnlockSurface(surface);
  writeln('Rot: '+InttoStr(color.r)+' Grün: '+InttoStr(color.g)+' Blau: '+InttoStr(color.b);
end;


Pixelformate ohne Palette sind eine komplett andere Erfahrung. Bei diesen Formaten sind die Farbinformationen in dem Pixel direkt codiert. Das mask Feld erlaubt uns jede einzelne Farbkomponente zu isolieren. Das shift Feld sagt uns die Anzahl der Bits rechts von jeder Komponente und das loss Feld sagt wieviele Bits von jeder Komponente verloren gingen als sie in 8 Bit Farbkomponenten gepackt wurden.

var fmt: PSDL_Pixelformat;
    surface: PSDL_Surface;
    temp, pixel: Uint32;
    red, green, blue, alpha: Uint8;
begin
.
.
.
  fmt := surface.format;
  SDL_LockSurface(surface);
  pixel := Uint32(surface.pixels^);
  SDL_UnlockSurface(surface);

  //Rote Komponente
  temp := pixel and fmt.Rmask; //Isolieren der roten Komponente
  temp := temp shr fmt.Rshift; //Auf 8 Bit zurückschieben
  temp := temp shl fmt.Rloss;  //Auf eine volle 8 Bit Zahl expandieren
  red := (Uint8)temp;

  //Grüne Komponente
  temp := pixel and fmt.Gmask; //Isolieren der grünen Komponente
  temp := temp shr fmt.Gshift; //Auf 8 Bit zurückschieben
  temp := temp shl fmt.Gloss;  //Auf eine volle 8 Bit Zahl expandieren
  green := (Uint8)temp;

  //Blaue Komponente
  temp := pixel and fmt.Bmask; //Isolieren der blauen Komponente
  temp := temp shr fmt.Bshift; //Auf 8 Bit zurückschieben
  temp := temp shl fmt.Bloss;  //Auf eine volle 8 Bit Zahl expandieren
  blue := (Uint8)temp;

  //Alpha Komponente
  temp := pixel and fmt.Amask; //Isolieren des Alphawerts
  temp := temp shr fmt.Ashift; //Auf 8 Bit zurückschieben
  temp := temp shl fmt.Aloss;  //Auf eine volle 8 Bit Zahl expandieren
  alpha := (Uint8)temp;

  writeln('Pixelfarbe -> R: '+InttoStr(red)+' G: '+InttoStr(green)+' B: '+InttoStr(blue)+' A: '+InttoStr(alpha));
end;



Siehe auch

SDL_Surface, SDL_MapRGB, SDL_Palette