Autor Beitrag
Popov
Gast
Erhaltene Danke: 1



BeitragVerfasst: Do 16.01.03 14:31 
Ich will meine Bitmaps in Graustuffen umwandeln. Das kann mehrmals pro Minute passieren. Deshalb brauch ich eine schnelle Convert2Gray Prozedur. Hat einer sowas fertig?
thebe
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 128

WinXP Home
D6 Enterprise
BeitragVerfasst: Do 16.01.03 18:49 
is schnell aussem Kopf

ausblenden Quelltext
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:
function Convert32ToGray( t: TColor ): TColor;
var
b: byte; //Helligkeit
begin
b := (((t shr 16) and $FF)+((t shr 8) and $FF)+(t and $FF)) div 3;
Result := (b shl 16) or (b shl 8) or b;
end;

procedure GrayBMP( bmp: TBitmap );
var
colors: PIntegerArray;
x, y, height, width: word;
Index: integer;
begin

height := bmp.height;
width := bmp.width;
colors := bmp.scanline[heigth-1];

for y := 0 to heigth-1 do
begin
for x := 0 to width-1 do
begin
index := ((height-y)*(width))+x;
colors^[index] := Convert32ToGray(colors^[index]);
end;
end;
end;


Sollte fehlerfrei sein und auch recht zügig

-Thebe
AndyB
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1173
Erhaltene Danke: 14


RAD Studio XE2
BeitragVerfasst: Fr 17.01.03 00:40 
Du musst dazuschreiben, dass bmp.PixelFormat auf pf32Bit stehen muss.

_________________
Ist Zeit wirklich Geld?
OregonGhost
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 215



BeitragVerfasst: Fr 17.01.03 11:31 
Dürfte das nicht deutlich schneller gehen, wenn man den Code der Convert32ToGray-Funktion direkt in GrayBMP integriert?

_________________
Oregon Ghost
---
Wenn NULL besonders groß ist, ist es fast schon wie ein bisschen eins.
Matthias
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 121



BeitragVerfasst: Fr 17.01.03 16:26 
Hallo,

@OregonGhost
Klar ist das schneller, da etliche Befehle, wie Unterprogrammaufruf und die gesamte Stackverwaltung wegfällt. Dies kann sich gerade bei grossen Bildern auswirken.

Außerdem kostet es Zeit den Index jedesmal neu zu berechnen.

Hier also eine kleine Änderung:

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
procedure GrayBMP( bmp: TBitmap ); 
var 
  colors: PIntegerArray; 
  index: integer; 
  len: integer;
  b: byte;
begin 
  Len  (bmp.Height - 1) * (bmp.Width - 1);
  colors := bmp.scanline[bmp.Heigth-1]; 
  for index := 0 to  len do
  begin
    b := (((colors^[index] shr 16) and $FF)+
             ((colors^[index] shr 8) and $FF)+
              (colors^[index] and $FF)) div 3; 
    colors^[index] := (b shl 16) or (b shl 8) or b;  end;
  end;
end;


Müsste eigentlich so klappen

Achso und nicht, wie schon gesagt, pf24Bit bzw pf32Bit vergessen.

ciao
Matthias
Popov
Gast
Erhaltene Danke: 1



BeitragVerfasst: Fr 17.01.03 16:31 
@thebe

Danke, sieht gut aus. Werde es heute abend testen. Ich muß mir langsam ScanLine genauer angucken, dann brauche ich solchen Fragen nicht zu stellen.

AndyB hat folgendes geschrieben:
Du musst dazuschreiben, dass bmp.PixelFormat auf pf32Bit stehen muss.


Was mich angeht, so war es mir schon klar, daß es 32Bit tiefe sein muß. Sieht man aus dem Code.
AndyB
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1173
Erhaltene Danke: 14


RAD Studio XE2
BeitragVerfasst: Fr 17.01.03 19:05 
Popov hat folgendes geschrieben:
Was mich angeht, so war es mir schon klar, daß es 32Bit tiefe sein muß. Sieht man aus dem Code.

Natürlich sieht ein geschultes Auge das aus dem Code, aber es gibt ja noch andere, die dieses Thema interessiert.

_________________
Ist Zeit wirklich Geld?
Popov
Gast
Erhaltene Danke: 1



BeitragVerfasst: Fr 17.01.03 20:46 
Hast natürlich recht.
littlemike1005
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 187



BeitragVerfasst: Sa 18.01.03 13:09 
Hier habe ich auch was zu diesem Thema gefunden.

www.tipps.delphi-sou.../tut20010107-1.shtml
AndyB
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1173
Erhaltene Danke: 14


RAD Studio XE2
BeitragVerfasst: Sa 18.01.03 14:31 
Das basiert auf Pixels[] und ist dementsprechend "schnell".

_________________
Ist Zeit wirklich Geld?
Aya
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1964
Erhaltene Danke: 15

MacOSX 10.6.7
Xcode / C++
BeitragVerfasst: Sa 18.01.03 17:49 
huhu,

das Thema ist zwar im grunde schon beantwortet.. aber trotzdem *g*
Ich bastel - wie einieg inzwischen eventuell wissen - an einer Komponente sammlung in der unter anderem auch eine ImageKomponente drin ist.

Ein paar Effekte die diese Komponente unterstüzt (nochdazu sehr schnell) sind:

- 17 Blending Methoden (Alpha, Freeze, Multiply, etc)
- Colorize
- Negativ
- Flip Horizontal/Vertikal
- Interlace (in mehreren arten)
- Ein Bild aus dem Bild heraus, bzw hinein zoomen.

- Alle (!!) Effekte sind Animierbar :)

Ok, genug werbung :)
Zwar ist die Komponenten Sammlung nochnicht komplett fertig, aber wenn dringende nachfrage besteht rück ich die Image-Kompo schonmal raus *g* (Wobei 3 der BlendModes nochnicht funktionieren)

Au'revoir,
Aya~
Ist die Frage beantwortet? Das Problem gelöst?

Dann klicke hier, um das Thema entsprechend zu markieren!