From: Larry Serflaten on 7 Jul 2010 11:26 "charles" <cbabbage59(a)yahoo.com> wrote > Yes, and I also saw the following vbaccelerator code which uses a > cDibSection Class to count the colors. <...> > Is there a faster and more reliable way? Not that I know about... LFS
From: Nobody on 7 Jul 2010 12:00 "charles" <cbabbage59(a)yahoo.com> wrote in message news:8459c286-45f5-4672-ad55-07eefad2ce86(a)b35g2000yqi.googlegroups.com... > Yes, and I also saw the following vbaccelerator code which uses a > cDibSection Class to count the colors. > > http://www.vbaccelerator.com/home/vb/code/vbmedia/image_processing/Counting_Colours/Count_Colours_Sample.asp > > The problem is that it is quite slow, taking about two seconds for my > sample 1600 x 1200 pixel .bmp file. It runs a bit faster on my other > machine, about one and a half seconds, but it returns a completely > different answer for exactly the same .bmp file! Is there a faster and > more reliable way? Have you tried it in an EXE while using "Remove Array Bounds Check"?
From: charles on 7 Jul 2010 13:09 On 7 July, 17:00, "Nobody" <nob...(a)nobody.com> wrote: > Have you tried it in an EXE while using "Remove Array Bounds Check"? Yes. I ran the ready compiled exe that came with the vbaccelerator download and I also compiled my own exe from the source code using all advanced optimizations including the array bounds checks you mention. In both cases it took about two seconds on one machine and about one and a half seconds on the other to count the colors. Do you have a faster way of doing it? Also I still have not figured out why it returns a completely different number of colors on one machine than it does on the other, loading exactly the same .bmp file. Is that normal? Charles
From: Nobody on 7 Jul 2010 13:27 "charles" <cbabbage59(a)yahoo.com> wrote in message news:47917783-6326-457a-9dc2-974fd5edd24d(a)y4g2000yqy.googlegroups.com... > Do you have a > faster way of doing it? Yes, but it requires more memory. Since there is 16 Million colors max, you can use an array with 16 Million bits(2 MBytes), and when you see a certain color, mark the bit as 1. You would need to do bit manipulation for this, which is not a big deal, but if use a Byte instead of Bit, it would be a bit faster, but it would use 16 MB of RAM. > Also I still have not figured out why it returns a completely > different number of colors on one machine than it does on the other, > loading exactly the same .bmp file. Is that normal? It's probably converting the colors to what the display is using, like from 24 Bits to 16 Bits, and so on.
From: Nobody on 7 Jul 2010 13:43
"Nobody" <nobody(a)nobody.com> wrote in message news:i12deb$26b$1(a)speranza.aioe.org... > "charles" <cbabbage59(a)yahoo.com> wrote in message > news:47917783-6326-457a-9dc2-974fd5edd24d(a)y4g2000yqy.googlegroups.com... >> Do you have a >> faster way of doing it? > > Yes, but it requires more memory. Since there is 16 Million colors max, > you can use an array with 16 Million bits(2 MBytes), and when you see a > certain color, mark the bit as 1. You would need to do bit manipulation > for this, which is not a big deal, but if use a Byte instead of Bit, it > would be a bit faster, but it would use 16 MB of RAM. Here is some code from one of my projects that calculates how many ones are there in a byte. For example, there are 3 ones in 00001110. This never change, so this can be put in a 256 element array and used to quickly count the number of ones in a byte. Here is the code: Option Explicit Dim NumberOfOnes(0 To 255) As Long ' Using Long for performance Private Sub Form_Load() CalcNumberOfOnes Debug.Print NumberOfOnes(&H7) Debug.Print NumberOfOnes(&HFE) Debug.Print NumberOfOnes(&HFF) End Sub Private Sub CalcNumberOfOnes() Dim i As Long Dim B As Long Dim c As Long For B = 0 To 255 c = 0 For i = 0 To 7 If ((2 ^ i) And B) <> 0 Then c = c + 1 End If Next NumberOfOnes(B) = c Next End Sub Output: 3 7 8 |