Autor Beitrag
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Mo 06.09.10 03:14 
Für Speed würde ich die Funktion MulDiv empfehlen. Was die macht, dürfte der Name bereits verraten ...
Doku gibt's dazu auch in der DOH bzw. bei M$, weil das eine API ist.

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
ALF Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1085
Erhaltene Danke: 53

WinXP, Win7, Win10
Delphi 7 Enterprise, XE
BeitragVerfasst: Mo 06.09.10 18:06 
So, hab jetzt das Teil fertig, würde sagen gefühlte 60%> schneller :wink: als meine!
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:
procedure TForm3.DrawBackround_Lines;
var
   ypos, h, x: integer;
   pcl, pcr: PRGBQUAD;
   pRGB: tagRGBQUAD;
   clfx: real;
begin
   .....
   .....

   for ypos:= 0 to peakbufr.Height-1 do
   begin
      clfx:= ypos / peakbufl.Height;
      
      pRGB.rgbRed:= trunc(102+ (153 *clfx));
      pRGB.rgbGreen:= trunc(113+ (142 *clfx));
      pRGB.rgbBlue:= trunc(126+ (129 *clfx));
      
      pcl:= peakbufl.ScanLine[ypos];
      pcr:= peakbufr.ScanLine[peakbufr.Height-1 - ypos];
      
      for x:= 0 to peakbufl.Width-1 do
      begin
         pcl^:= pRGB;
         pcr^:= pRGB;
         inc(pcl);
         inc(pcr);
      end;
   end;
   ....
   ....
end;

EDIT: bringt aber nur was, wenn man auch BitBlt benutzt! Sonst bleibt es etwa bei 40%

Ein BIG THX an alle für die Ausdauer.
Gruss Alf

_________________
Wenn jeder alles kann oder wüsste und keiner hätt' ne Frage mehr, omg, währe dieses Forum leer!


Zuletzt bearbeitet von ALF am Mo 06.09.10 19:38, insgesamt 1-mal bearbeitet
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: Mo 06.09.10 18:30 
Ich hab mich mal schnell durch MulDiv durchgesteppt; der macht auch nur eine normale Multiplikation und eine normale Division. Die Funktion hat paar Ifs drin, ich nehme an es geht um Bereichsprüfung und Overflowverhinderung. Bei dir würde ich aber sowieso kein Integer Overflow befürchten, daher könntest du einfach multiplizieren und dann dividieren und dir denn Call und Ifs sparen. Integer-Arithmetik sollte nochmals signifikant schneller sein. Aber ich könnte mir auch gut vorstellen, dass es sich mehr lohnt, die innere Schleife noch weiter zu optimieren, statt die äussere. Um das zu beantworten bräuchte man einen Profiler.

Aber vielleicht lassen wir's am besten so sein, wie's jetzt ist ;)
elundril
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3747
Erhaltene Danke: 123

Windows Vista, Ubuntu
Delphi 7 PE "Codename: Aurora", Eclipse Ganymede
BeitragVerfasst: Mo 06.09.10 18:37 
Kommt aber teilweise zu anderen ergebnissen mit MulDiv, da kaufmännisch gerundet wird und nicht einfach nur der ganzzahlige Anteil genommen wird. Und wenn man die Integerumwandlung vorzieht ebenso.

Muss man halt abwägen ob es auch mit diesen "Fehlern" leben kann oder ob man die etwas geringere Geschwindigkeit in kauf nimmt.

lg elundril

_________________
This Signature-Space is intentionally left blank.
Bei Beschwerden, bitte den Beschwerdebutton (gekennzeichnet mit PN) verwenden.
platzwart
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1054
Erhaltene Danke: 78

Win 7, Ubuntu 9.10
Delphi 2007 Pro, C++, Qt
BeitragVerfasst: Di 07.09.10 12:58 
user profile iconALF hat folgendes geschrieben Zum zitierten Posting springen:

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:
procedure TForm3.DrawBackround_Lines;
var
   ypos, h, x: integer;
   pcl, pcr: PRGBQUAD;
   pRGB: tagRGBQUAD;
   clfx: real;
begin
   .....
   .....

   for ypos:= 0 to peakbufr.Height-1 do
   begin
      clfx:= ypos / peakbufl.Height;
      
      pRGB.rgbRed:= trunc(102+ (153 *clfx));
      pRGB.rgbGreen:= trunc(113+ (142 *clfx));
      pRGB.rgbBlue:= trunc(126+ (129 *clfx));
      
      pcl:= peakbufl.ScanLine[ypos];
      pcr:= peakbufr.ScanLine[peakbufr.Height-1 - ypos];

      
      for x:= 0 to peakbufl.Width-1 do
      begin
         pcl^:= pRGB;
         pcr^:= pRGB;

         inc(pcl);
         inc(pcr);
      end;
   end;
   ....
   ....
end;



Das dürfte mit Graphics32 nochmals schneller gehen, ich schätze mal Faktor 5. Ich weiß, du willst es nicht benutzen, aber nur so als Info... ;)

_________________
Wissenschaft schafft Wissenschaft, denn Wissenschaft ist Wissenschaft, die mit Wissen und Schaffen Wissen schafft. (myself)