Autor Beitrag
Martok
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 3661
Erhaltene Danke: 604

Win 8.1, Win 10 x64
Pascal: Lazarus Snapshot, Delphi 7,2007; PHP, JS: WebStorm
BeitragVerfasst: Fr 25.08.06 13:34 
Hallo,

Nach dieser doch etwas komischen Überschrift erstmal mein Problem: Ich habe eine Grafik in einem TBitmap.
Diese möchte ich nun auf genau die Hälfte der Größe bringen. Dazu hab ich mir gedacht, ich lösche jedes 2. Pixel.
Dabei möchte ich aber keine 2. Grafik erstellen und die Ergebnisse in dieser ablegen, dann könnte ich auch StretchDraw nehmen. Ich dachte eher daran, die Scanlines durchzugehen, und die Rows jeweils um eine Reihe zu verschieben.
Irgendwie steh ich dabei aber auf'm Schlauch, soll heißen mir fällt kein sinnvoller Anfang ein.

Kann mir mal jemand einen Denkanstoß geben?
(Ich nehme auch fertigen Code, falls ich was habt ;) )

Danke schonmal,
Martok

_________________
"The phoenix's price isn't inevitable. It's not part of some deep balance built into the universe. It's just the parts of the game where you haven't figured out yet how to cheat."
rbertus2000
Hält's aus hier
Beiträge: 7


Turbo Delphi für Win32
BeitragVerfasst: Fr 25.08.06 13:47 
Hallo Martok,
ich würde versuchen, die Breite und die Höhe des Bildes mittels der Eigenschaften Width und Height zu ändern.

_________________
mfg rbertus2000
Martok Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 3661
Erhaltene Danke: 604

Win 8.1, Win 10 x64
Pascal: Lazarus Snapshot, Delphi 7,2007; PHP, JS: WebStorm
BeitragVerfasst: Fr 25.08.06 13:52 
Hm, ich glaube du hast mich nicht verstanden.
Wenn man nur Width und Height ändert, wird das Bild nicht skaliert. Das Ändern der Maße wäre der letzte Schritt, den ich machen würde, wenn die jeweils graden Zeilen/Spalten schon weg sind.

//Martok

_________________
"The phoenix's price isn't inevitable. It's not part of some deep balance built into the universe. It's just the parts of the game where you haven't figured out yet how to cheat."
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5285
Erhaltene Danke: 28

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Fr 25.08.06 13:54 
möchtest du einen verkleinerungsalgo schreiben ?
Martok Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 3661
Erhaltene Danke: 604

Win 8.1, Win 10 x64
Pascal: Lazarus Snapshot, Delphi 7,2007; PHP, JS: WebStorm
BeitragVerfasst: Fr 25.08.06 13:58 
Genau. Einen der genau auf die Hälfte skaliert, und das ganze auch noch schnell tut.

//Martok

_________________
"The phoenix's price isn't inevitable. It's not part of some deep balance built into the universe. It's just the parts of the game where you haven't figured out yet how to cheat."
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5285
Erhaltene Danke: 28

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Fr 25.08.06 14:00 
das ist ganz einfach, zb du willst höhe und breite halbieren, dann nimmst du immer 2*2 pixel und berechnest deren durchschnittsfarbe. diese speicherst du dann in einen pixel, somit hast du von 2*2 auf 1*1 reduziert. das machst du mit jeder vierer gruppe. mit scanline sollte das extrem schnell sein.


wobei du 2*2 durch eben xskalierung und yskalierung ersetzen solltest, dann hast du das ganze auch schön variable und unabhängig.

mfg
Martok Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 3661
Erhaltene Danke: 604

Win 8.1, Win 10 x64
Pascal: Lazarus Snapshot, Delphi 7,2007; PHP, JS: WebStorm
BeitragVerfasst: Fr 25.08.06 16:32 
Dank F34r hab ich jetzt einen Algo, der das macht. Hab ihn aber ebend mit PerformanceCounter nachgemessen, 62 ms für ein 1280*1024 Bild. Im Prinzip nicht schlecht, aber der Rest vom Programm ist schon so langsam, dass die gesenkte Datenmenge nichts mehr bringt. Damit weiß ich jetzt: für mein Problem gibts keine Lösung, denn ich müsste schneller sein als das, was wohl kaum geht.
Ich hab den Fragestatus mal auf kein Status gesetzt, da die Frage ja weder offen noch wirklich gelöst(weil unlösbar) ist.

Ich häng den Algo mal an, vielleicht braucht je jemand sowas (bei normalen Bildgrößen ist der verdammt schnell^^):

ausblenden volle Höhe Delphi-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:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
procedure DecreaseSize(BM:TBitmap; Fract:byte);
type
  PRGBQuads=^TRGBQuads;
  TRGBQuads=packed array[0..0]of TRGBQuad;

var ln,cl,x,y:integer;
    l:array of PRGBQuads;
    r,g,b,cnt:integer;
    current:PRGBQuad;
begin
  if Fract<=1 then exit;
  if BM.PixelFormat<>pf32Bit then exit;
  BM.Width:= ceil(BM.Width / Fract)*Fract;
  BM.Height:= ceil(BM.Height / Fract)*Fract;
  SetLength(l,Fract);
  cnt:= Fract*Fract;
  ln:= 0;
  while ln<BM.Height do begin
    current:= BM.ScanLine[ln div Fract];
    for y:= 0 to Fract-1 do
      l[y]:= BM.ScanLine[ln+y];
    cl:= 0;
    while cl<BM.Width do begin
      r:=0; g:= 0; b:= 0;
      for x:= cl to cl+Fract-1 do
        for y:= 0 to Fract-1 do begin
          inc(r,l[y,x].rgbRed);
          inc(g,l[y,x].rgbGreen);
          inc(b,l[y,x].rgbBlue);
        end;
      current^.rgbRed:= r div cnt;
      current^.rgbGreen:= g div cnt;
      Current^.rgbBlue:=b div cnt;
      inc(current);
      inc(cl,Fract);
    end;
    inc(ln,Fract);
  end;
  BM.Width:= BM.Width div Fract;
  BM.Height:= BM.Height div Fract;
end;


//Martok

_________________
"The phoenix's price isn't inevitable. It's not part of some deep balance built into the universe. It's just the parts of the game where you haven't figured out yet how to cheat."