It is currently Sun May 19, 2013 4:15 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Image reduce colors
PostPosted: Sun Dec 25, 2011 5:26 pm 
Offline
Enthusiast
Enthusiast

Joined: Mon Feb 16, 2009 10:42 am
Posts: 531
Location: sweden
Hi all.
There must be a easier way than this.
This is what I am trying to achieve:
* Take a image from webcam
* Reduce image to 2 or 4 bitplanes
(next step is to take out everything within a span to find a specific marker, like a red circle or something like that)

Right now I have to save as PNG with 4 bitplanes and then load the image again... that is slooooow..
Code:
OpenWindow(0,0,0,640,480,"",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
AddWindowTimer(0,0, 50)
UsePNGImageDecoder()
UsePNGImageEncoder()
Repeat
  Event = WindowEvent()
  If Event = #PB_Event_Timer
    MX_Release(Image)
    image = MXSnapshot_TakeSnapshot(640)
    tempimage=CreateImage(#PB_Any,640,480)
    StartDrawing(ImageOutput(tempimage))
    DrawImage(image,0,0,320,240)
    StopDrawing()
    SaveImage(tempimage,GetTemporaryDirectory()+"temp.png",#PB_ImagePlugin_PNG,0,2)
    FreeImage(tempimage)
    StartDrawing(WindowOutput(0))
    DrawAlphaImage(ImageID(LoadImage(#PB_Any,GetTemporaryDirectory()+"temp.png")),0,0)
    StopDrawing()
  EndIf
Until Event=#PB_Event_CloseWindow
MXSnapshot_StopSession()


Top
 Profile  
 
 Post subject: Re: Image reduce colors
PostPosted: Sun Dec 25, 2011 6:34 pm 
Offline
Addict
Addict

Joined: Sun Aug 08, 2004 5:21 am
Posts: 1084
Location: Netherlands
You can try manipulating the drawing buffer
Code:
Procedure Reduce4bpp(buffer, numPixels); reduce to 4bpp (4096 colors)
  EnableASM
  MOV ecx, numPixels
  MOV edx, buffer
  !push ebx
  !reduce4bpp_loop:
  !mov eax, [edx]
  !and eax, 0xf0f0f0f0
  !mov ebx, eax
  !shr ebx, 4
  !or eax, ebx
  !mov [edx], eax
  !add edx, 4
  !dec ecx
  !jnz reduce4bpp_loop
  !pop ebx
  DisableASM
EndProcedure

Procedure Reduce2bpp(buffer, numPixels); reduce to 2bpp (64 colors)
  EnableASM
  MOV ecx, numPixels
  MOV edx, buffer
  !push ebx
  !mov ebx, edx
  !reduce2bpp_loop:
  !mov eax, [ebx]
  !shr eax, 6
  !and eax, 0x03030303
  !imul eax, 0x55
  !mov [ebx], eax
  !add ebx, 4
  !dec ecx
  !jnz reduce2bpp_loop
  !pop ebx
  DisableASM
EndProcedure

OpenWindow(0,0,0,640,480,"",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
AddWindowTimer(0,0, 50)
UsePNGImageDecoder()
UsePNGImageEncoder()
Repeat
  Event = WindowEvent()
  If Event = #PB_Event_Timer
    MX_Release(Image)
    image = MXSnapshot_TakeSnapshot(640)
    tempimage=CreateImage(#PB_Any,640,480)
    StartDrawing(ImageOutput(tempimage))
    DrawImage(image,0,0,320,240)
    Reduce2bpp(DrawingBuffer(), 640 * 480)
    StopDrawing()
    StartDrawing(WindowOutput(0))
    DrawAlphaImage(ImageID(tempimage),0,0)
    StopDrawing()
    FreeImage(tempimage)
  EndIf
Until Event=#PB_Event_CloseWindow
MXSnapshot_StopSession()


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye