first of all,you all do a great work and it help me a lot thanks.

i'm working on app that use some 256 colors bitmap

i've wrote this proc to know what is the most used color and how many times it is used...

but it's slow 'cause i scan the pic 256 time (one per colour)
here's my proc:
checkmaxcoul proc,srcpic:dword,num:dword
mov curcoul,0
mov ecx,256
mov curcount,0
push ecx
mov esi,srcpic
mov ecx,num
mov eax,0
cmp eax,curcoul
jne rbou1
inc curcount
loop boubou1
mov eax,maxcount
cmp curcount,eax
jg Max1
pop ecx
inc curcoul
loop boucheck1
mov eax,curcount
mov maxcount,eax
mov eax,curcoul
mov coulnum,eax
jmp rbou2
checkmaxcoul endp

the var coulnum is the most used coul and maxcount the number of times it is used

can someone help me i've tried to do something like:
try to read only once and increment a dword for each colour found then i'll have to check what dword of my table is the most important the i'll do the 2 op in one

checkmaxcoul2 proc,srcpic:dword,num:dword
mov eax,0
mov maxcount,eax
mov coulnum,eax
mov esi,srcpic
mov ecx,num
mov eax,0
mov ebx,coultbl2
inc ebx
mov coultbl2,ebx
loop boucheckmaccoul21
checkmaxcoul2 endp

thanks to help me
and you are all fantastic
Posted on 2002-11-03 11:55:12 by Thor0Asgard
Assuming you have the stack space to spare.

[size=12]; mostFreqByte

; Usage:
; push length (size of array)
; push offset byteArray (start addr. of array)
; call mostFreqByte
; On return:
; eax = most freq. byte
; edx = frequency


push edi
push esi
push ebx
push ecx
mov ecx, 256
sub esp, 1024
mov edi, esp
xor eax, eax
rep stosd
mov edi, [esp+1044]
mov ecx, [esp+1048]
xor edx, edx
mov al, byte ptr [edi+ecx-1]
inc dword ptr [esp+eax*4]
mov ebx, [esp+eax*4]
cmp ebx, edx
jna @f
mov edx, ebx
mov esi, eax
@@: dec ecx
jnz @begin
mov eax, esi
add esp, 1024
pop ecx
pop ebx
pop esi
pop edi
ret 8[/size]
Posted on 2002-11-03 13:06:33 by iblis
i join you the bitmap used for the test
with my routine (checked and work) the color is 10 and it's used 14233 times
please help me
Posted on 2002-11-03 13:17:32 by Thor0Asgard
Small error. I changed it (edited my post above). It should work now.
Posted on 2002-11-03 14:25:13 by iblis
Thor0Asgard, count the colors in one pass using a dword array, then just find the largest number in the array. Loop can be unrolled and limited by memory speed...

; ESI = source buffer
; ECX = byte count (colors)
; EDI = destination array
movzx eax, BYTE PTR

loop @B

; then find the greatest dword in array...
Posted on 2002-11-03 14:26:44 by bitRAKE
bitRake, that's what my algo does. ;)

But largest number in the array is kept track of during the pass, so you don't need to loop through the dword array afterwards.
Posted on 2002-11-03 14:29:13 by iblis
The count array is small (in comparison to the color bytes) and in the cache by the end of first loop. :) Also, that branch is unpredicatable and should be moved outside the main loop. Yes, your code is a good example, but he PM'd me so I thought I'd respond here.
Posted on 2002-11-03 15:39:27 by bitRAKE
iblis code now work (except i had to correct the @F label you wrote @:)

it is very faster than mine i think 256 times faster in fact...

and bitrake i can't test your code even if it's seems to be greater
i use tasm 5 and when compil the prog
it's saying
argument to operation or instruction has illegal size

movzx eax, DWORD PTR
please tell me what's wrong with that and i'll test it
Posted on 2002-11-03 16:35:20 by Thor0Asgard
Sorry, should be 'BYTE PTR'.
Posted on 2002-11-03 17:37:10 by bitRAKE
I'd like to see what you wrote.
Posted on 2002-11-03 18:29:52 by iblis

I'd like to see what you wrote.
It is all here - nothing really! I just responded here instead of PM. I have corrected my brief post above - sorry, to confuse you.
Posted on 2002-11-03 19:48:37 by bitRAKE
put the files in the attachement:

is the main project

i'e tried to put the funcs of into bitmap.asm
i prefer the dll use to a **** include.

but i've got something strange with test2

in source you'll see a moment i've put 'filecreate,.....'
and i close this file later

if i remove this the results are wrong i don't understand why

in my degguger (W32DASM 8.93) the only changes are in the processor flags

but i also don't know why can someone good (a real coder) can help me
to understand what is bad in my code.
Posted on 2002-11-03 20:38:40 by Thor0Asgard
checkcoulnonused expects the direction flag to be clear and your CopyMemory is setting it!
CopyMemory proc,dest:dword,src:dword,nums:dword

mov esi,src
mov edi,dest
mov ecx,nums
loop boucopymemory
std ; <------------ this sets everything going backwards ;)
CopyMemory endp
Use OllyDbg - this was easy to find with such a great tool!
Posted on 2002-11-03 21:59:21 by bitRAKE
i don't remeber why i put it there but it was the problem.

now it wroks perfectly thansk again for helpin'.
Posted on 2002-11-04 02:59:34 by Thor0Asgard
now i tried to use the 4th byte of the rgb quad to put and id to the pic (plitting a dword id into 4 bytes)

but i've got a strange but with my GetBitMapMaskIndex func
it done it well
open the file read the val (a dword)
close it

but when it ret

it do not return to the rest of my code and i have an eception bug

please help me again tell me where i'm wrong

thanks again for the help
Posted on 2002-11-04 04:23:57 by Thor0Asgard
Its a case for the debugger by the look of it...

Things to check for:
#1 Make sure the stack isn't getting corrupted... Place a watch on the return address

#2 Make a note of esp at the very start of the function call (after the enter, or hand coded variant, so on the pusha), given that the function takes no argument, it may not set up a stack frame.... Then check that after the popa in your code that it is the same at it was when you entered.

The prime culprit I would suspect would be the calling convention of one of the function calls is wrong, or the clean up for it (if it is C, or vararg) hasn't been done properly.

------------------------------------ additional ------------------------------------
I just loaded it up (pain in the proverbial rear end, because there was no debugging information), and the word on the street is that the culprit is the fileopen function. Pre-pushing esp = 0x12FFA0, after fn call esp = 0x12FF98, which is bad.... The popad call at the end of the function confirms it, ebx is getting the value that should end up in esp, so when it comes to clean up the stack frame, that all goes Pete Tong, and the dword on the top of the stack isn't the return address, and it should be.

Posted on 2002-11-04 05:19:53 by Mirno
my esp strangly change after the popa in GetBitMapMaskIndex
i don't know why
Posted on 2002-11-04 05:44:08 by Thor0Asgard
FileOpen proc,file:dword
mov eax,0
mov fileheader,eax
call CreateFileA,file,GENERIC_READWRITE,0,0,OPEN_EXISTING,0,0 ;don't need to coment i suppose
cmp eax,-1
je FileOpenFailed
mov fileheader,eax
mov eax,1
mov ebx,fileheader
mov eax,-1
FileOpen endp

GetBitMapMaskIndex proc
call fileopen,offset bitmapmaskindexfile,2,0
mov bitmapmaskindexh,ebx
call Fileread,bitmapmaskindexh,offset bitmapmaskindex,4
call fileclose,bitmapmaskindexh
mov eax,bitmapmaskindex
GetBitMapMaskIndex endp
Posted on 2002-11-04 05:49:14 by Thor0Asgard
You declare it as a function which takes 1 argument, you define the extern so it takes 1 argument, and then you promptly go and call it with 3 arguments... I hadn't taken into account the possibility that TASM provides no function type checking.

Well I guess the answer is to remove the ",2,0" from the fileopen call... Then all should be right with the world.

Posted on 2002-11-04 06:45:43 by Mirno
i 've copy paste tha func filerite and just change the write by open without deleting the params....

thanks again
Posted on 2002-11-04 07:18:31 by Thor0Asgard