From: Robert Rossmair Subject: Re: calculating the average color of a bitmap Date: 02 Feb 2000 00:00:00 GMT Message-ID: <3897B3DB.3A2CFC9@t-online.de> Content-Transfer-Encoding: 8bit References: <8746jg$3b6sm$1@fu-berlin.de> <3895C653.AF3E4724@iname.com> <876lqo$3efhs$1@fu-berlin.de> X-Accept-Language: de,en X-Sender: 340065752685-0001@t-dialin.net Content-Type: text/plain; charset=iso-8859-1 X-Complaints-To: abuse@t-online.de X-Trace: news07.btx.dtag.de 949465956 18576 340065752685-0001 000202 04:32:36 Organization: - Mime-Version: 1.0 Newsgroups: borland.public.delphi.graphics Hi Martin, Martin Schnieder schrieb: > bmp.pixelformat := pf24bit; Note that converting a bitmap's pixel format is a time-consuming process. Chances are that this line will eat up more computing time than the remainder of your routine if the bitmap is not a genuine 24-bit-bitmap. I did some tests with a 889 x 932 bitmap. execution times in msec (366 MHz Celeron): RGB averaging code: 37 pixel format conversion pf4bit: 67 pf8bit: 63 pf16bit: 94 pf24bit (no conv.): 0.01 pf32bit: 84 it is possible to speed up the averaging code a bit using assembler. The following code needs about 23 msec (instead of 37) to scan the 889 x 932 bitmap mentioned above. var X, Y, W: Integer; P: PRGBTriple; r, g, b, Pixels: Integer; averagecolor: TColor; Bmp: TBitmap; begin //... r := 0; g := 0; b := 0; W := Width; for y := 0 to Height-1 do begin P := ScanLine[y]; asm mov ecx, W and ecx, ecx jz @end push ebx push esi push edi mov edi, ecx mov ebx, b mov ecx, g mov edx, r mov esi, P @Next: movzx eax, BYTE PTR [esi] add ebx, eax movzx eax, BYTE PTR [esi]+1 add ecx, eax movzx eax, BYTE PTR [esi]+2 add edx, eax dec edi jz @finis movzx eax, BYTE PTR [esi]+3 add ebx, eax movzx eax, BYTE PTR [esi]+4 add ecx, eax movzx eax, BYTE PTR [esi]+5 add edx, eax dec edi jz @finis movzx eax, BYTE PTR [esi]+6 add ebx, eax movzx eax, BYTE PTR [esi]+7 add ecx, eax movzx eax, BYTE PTR [esi]+8 add edx, eax dec edi jz @finis movzx eax, BYTE PTR [esi]+9 add ebx, eax movzx eax, BYTE PTR [esi]+10 add ecx, eax movzx eax, BYTE PTR [esi]+11 add edx, eax add esi, TYPE TRGBTriple * 4 dec edi jnz @Next @finis: mov b, ebx mov g, ecx mov r, edx pop edi pop esi pop ebx @end: end; Greetings, Robert -- Robert Roßmair http://home.t-online.de/home/Robert.Rossmair/ Programming environment: Delphi 5 Professional, WinNT 4.0 SP6