Basic4ppc - Windows Mobile Development  

Go Back   Basic4ppc - Windows Mobile Development > Main Category > Questions & Help Needed
Home Register FAQ Members List Search Today's Posts Mark Forums Read

Questions & Help Needed Post any question regarding Basic4ppc.


Fastest way to get pixel colour value?


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-22-2007, 08:23 PM
Newbie
 
Join Date: May 2007
Location: Vancouver, CANADA
Posts: 7
Default Fastest way to get pixel colour value?

I want to selectively get the Red, Green, or Blue value for a pixel. Ideally, I would like 3 functions: GetPixelRed(), GetPixelGreen(), and GetPixelBlue(). Each function would return a value from 0..255. This would better complement the existing SetPixel() function which takes 3 integers as arguments.

The existing GetPixel() function just returns a 32-bit value that I assume/suspect consists of the following byte fields
Byte 3 = 0xFF
Byte 2 = Red Value (0..255)
Byte 1 = Green Value (0..255)
Byte 0 = Blue Value (0..255)

I could extract the particular R, G, or B value from this 32-bit value using some bitwise manipulation, but am concerned that the compiler wouldn't optimize it fast enough for my needs.

Any ideas of what the fastest way to get a Red, Green, or Blue colour value from a pixel would be?

Thanks,
__________________
Dell X50v WM2003
Wintec 100WBT GPS
Great device... Dell should not have cancelled it!!!
Reply With Quote
  #2 (permalink)  
Old 08-22-2007, 08:39 PM
Cableguy's Avatar
Basic4ppc Expert
 
Join Date: Apr 2007
Location: N 41º11'30.30" W 8º39'46.60"
Posts: 1,314
Default

Try the following

ad three varables to the globals:
R,G,B -This will be the color components

The in the whatever sub
try :

RGB(R,G,B)=getpixel(x,y)
msgbox("Your color is mador Red("&R&"), Green("&G&"), and Blue("&B&")")

Please note that this is un-tested code...but i Think it will do what you want...
__________________
Paulo Gomes
Porto, Portugal

PC: Dual-Core 1,8Ghz, 2GB RAM, 80GB HD
PPC: Qtek9000, 1GB SD

DLL Version Listing
Reply With Quote
  #3 (permalink)  
Old 08-22-2007, 09:14 PM
specci48's Avatar
Basic4ppc Expert
 
Join Date: Apr 2007
Location: Germany
Posts: 636
Default

I don't know if this is the fastet way but it works:

Code:
Sub Globals
	red = 0
	green = 0
	blue = 0	
End Sub

Sub App_Start
	...
	Color2RGB(bitmap1.GetPixel1(w,h))
	...		
End Sub

Sub Color2RGB(color)
	colorNum = color + 16777216
	red = Int(colorNum / 65536)		
	green = Int((colorNum - red * 65536) / 256)	
	blue = colorNum - red * 65536 - green * 256
End Sub

specci48
Reply With Quote
  #4 (permalink)  
Old 08-22-2007, 09:49 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 3,132
Default

specci48 method is the right way to do it.
Next version will include a GetRGB method that will return the three components of a color.
Reply With Quote
  #5 (permalink)  
Old 08-23-2007, 04:54 AM
Junior Member
 
Join Date: Jul 2007
Location: Hong Kong
Posts: 42
Send a message via MSN to hung Send a message via Yahoo to hung Send a message via Skype™ to hung
Default

I got something similar in one of my program.

vC = form1.GetPixel(x, y) + 16777216
vR = Int(vC / 65536)
vG = Int((vC Mod 65536) / 256)
vB = vC Mod 256

But that assumes the PPC is using 65535 colors, other color pallet will not work.
__________________
Yours,

Dopod D810 WM6 GPS HSDPA 3G Wifi Bluetooth
Reply With Quote
  #6 (permalink)  
Old 09-02-2007, 06:38 AM
Newbie
 
Join Date: May 2007
Location: Vancouver, CANADA
Posts: 7
Default

Quote:
Originally Posted by Erel View Post
Next version will include a GetRGB method that will return the three components of a color.
That's great! Hopefully it'll run faster than the work arounds. When do you think this next release will be?
  1. days?
  2. weeks?
  3. months?
  4. All of the above?
  5. None of the above?

Thanks for your work at improving an impressive product.
__________________
Dell X50v WM2003
Wintec 100WBT GPS
Great device... Dell should not have cancelled it!!!
Reply With Quote
  #7 (permalink)  
Old 09-02-2007, 07:40 AM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 3,132
Default

I guess it will be option number 3.
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Forelayer text colour and weight! agraham Bug Reports 4 10-09-2008 12:39 PM
Colour Values Zenerdiode Questions & Help Needed 2 05-20-2008 06:01 AM
ploting just one pixel colin9876 Questions & Help Needed 1 11-30-2007 07:38 PM
fastest way to search in database Put Claude Questions & Help Needed 14 10-10-2007 09:53 PM
2 pixel displacement specci48 Questions & Help Needed 2 08-29-2007 07:04 PM


All times are GMT. The time now is 01:37 PM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.1.0