Einzelnen Beitrag anzeigen

Benutzerbild von himitsu
himitsu

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
43.097 Beiträge
 
Delphi 12 Athens
 
#4

AW: schnelle getPixel Funktion

  Alt 16. Aug 2011, 10:50
pf32bit und getPixel: Byte kann schonmal nicht stimmen, da ein Pixel hier 4 Byte ist.

Warum ist es langsamer?
- du änderst das Pixelformat, also den ganzen Bildinhalt auf pf32bit
- der andere Code geht einfach davon ausß daß das bild schon pf24bit ist (wenn nicht, dann knallt's oder so)

Delphi-Quellcode:
type
  TColorArray = array[0..0] of TColor;
  PColorArray = ^TColorArray;

PixelColor := PColorArray(Self.ScanLine[Self.Height - 1])[x * Self.Width + (Self.Height - y - 1)]
Delphi-Quellcode:
var P: PColorArray;
P := PColorArray(Self.ScanLine[Self.Height - 1]);

PixelColor := P[(Self.Height - y - 1) * Self.Width + x];
// entspricht
PixelColor := P + ((Self.Height - y - 1) * Self.Width + x);
// entspricht
PixelColor := PByte(P) + ((Self.Height - y - 1) * Self.Width + x) * 4;
Diese Berechnug stimmt nur für pf32bit (für die anderen Formate müßte man noch einen breitenabhängigen Offset je Zeile mit einrechnen).
Das dann in eine Funktion und diese als "inline" markieren.

Die eine Scannline-Adresse oder das Array aller Scanlines natürlich vorher zwischenspeichern
Garbage Collector ... Delphianer erzeugen keinen Müll, also brauchen sie auch keinen Müllsucher.
my Delphi wish list : BugReports/FeatureRequests

Geändert von himitsu (16. Aug 2011 um 10:56 Uhr)
  Mit Zitat antworten Zitat