Page 2 of 2

Re: Slow down compression in purebasic?

Posted: Wed Jun 01, 2011 11:21 pm
by oakvalley
[quote="graph100"]Well, well,
[url]http://www.purebasic.fr/english/viewtop ... 12&t=38606[/url]

In this topic you can find a compression algoryhme, so maybe, you can use it, and slow this as you want (I think this is the simpliest way) :mrgreen:[/quote]

That is soooo over my head :-)

Re: Slow down compression in purebasic?

Posted: Wed Jun 01, 2011 11:49 pm
by Thorium
oakvalley wrote: along with the need for point command which in the loop is hard to slow down at least with standard purebasic commands and in which end even using other smart ways of doing the point command in API way
There is no need for point and also no need for a even slower API point.
The fast way would be to use DrawingBuffer() to get the pointer to the image data and access it directly.
oakvalley wrote: still would to be run in a loop where I cannot slow down the loop beyond the minimum of 1 ms during each run. Is there time and space for requesting a nanosecond delay in the next version of Purebasic?
No, there is nothing like that. At least not on windows. The trick is to put a counter in and delay only every 10. or 100. or 1000. or so iteration.

But again we speak about 2% CPU load. It's acualy a lot of work for realy nothing what you try to do. That 2% does not mean another process does not have that 2%.

Re: Slow down compression in purebasic?

Posted: Thu Jun 02, 2011 12:34 am
by graph100
Thorium wrote:There is no need for point and also no need for a even slower API point.
The fast way would be to use DrawingBuffer() to get the pointer to the image data and access it directly.
I totally agree with these 2 points :mrgreen: The fact is, I've broken my computer, so it's not usable and I had to code this quikly, without thinking through it all. I've made my point in using the point function and all the rest, it's ugly :x
Thorium wrote:The trick is to put a counter in and delay only every 10. or 100. or 1000. or so iteration.
I agree to this one too. In my code, I have just tryed to design some quick compression algorythme without even doing some research on the web... My point was : to create a code doing the job requested (compresse an image) to make the opportunity to slow this code down.

First you design the code to run the fastest way it's possible, and then you can slow it down. With this thinking, you can reduce the unecessary operation to a minimum.
Thorium wrote:But again we speak about 2% CPU load. It's acualy a lot of work for realy nothing what you try to do. That 2% does not mean another process does not have that 2%.
I agree that a use of 2% when the computer is doing nothing, only mean that window allow the code to run faster because IT can.
But, I also like this challenge, because it's an unusual way of thinking :D and it might be fun to code this :)

Re: Slow down compression in purebasic?

Posted: Thu Jun 02, 2011 10:08 am
by Thorium
graph100 wrote:
Thorium wrote:But again we speak about 2% CPU load. It's acualy a lot of work for realy nothing what you try to do. That 2% does not mean another process does not have that 2%.
I agree that a use of 2% when the computer is doing nothing, only mean that window allow the code to run faster because IT can.
But, I also like this challenge, because it's an unusual way of thinking :D and it might be fun to code this :)
There is nothing wrong with a good challenge. :)

Re: Slow down compression in purebasic?

Posted: Thu Jun 02, 2011 10:57 am
by Foz
This is also a useful exercise for myself, when using an 11 year old laptop where speed, cores, memory, weight and screen size were a thing of the future. :)

It makes multitasking a serious challenge!

Re: Slow down compression in purebasic?

Posted: Fri Jun 03, 2011 11:23 am
by oakvalley
[quote="Foz"]This is also a useful exercise for myself, when using an 11 year old laptop where speed, cores, memory, weight and screen size were a thing of the future. :)

It makes multitasking a serious challenge![/quote]

Yes, I agree! Working with old computers just up's the stakes to a reasonable challenge. Like my Billboard, I want it to work from Win95 to Win7. Basically, because I have some Win95/ME running from time to time in small computer nerdy projects using embedded pc's and such coolness.

I'm not sure when my Billboard software is done, but I'll let you know.

Re: Slow down compression in purebasic?

Posted: Sun Jun 05, 2011 4:03 pm
by graph100
as somebody answered in an old topic, here a code of maestro to convert bmp file to 256 colors, the code is easy to use and you can change it to a 16colors convertion.
http://www.purebasic.fr/english/viewtop ... 12&t=35627

I dunno if it work on win95, because it use some api, but I think it might work pretty well. The code does not eat a lot of cpu time, (there's nothing on my cpu load viewer, with an old computer)

You should put an eye onto this :)
Here a piece of code that work with the code of maestro.

Code: Select all

#dist_max = 442

IncludeFile "_librairie_code_saveimageto8bitcolor_netmaestro.pbi"

Procedure DesktopSnapShot(img, coef.l = 6)
	Ecran_Largeur = GetSystemMetrics_(#SM_CXSCREEN)
	Ecran_Hauteur = GetSystemMetrics_(#SM_CYSCREEN)
	
	DC = GetDC_(0)
	
	CreateImage(img, Ecran_Largeur, Ecran_Hauteur)
	
	Dessin = StartDrawing(ImageOutput(img))
	
	If Dessin
		BitBlt_(Dessin, 0, 0, Ecran_Largeur, Ecran_Hauteur, DC, 0, 0, #SRCPAINT | $40000000)
		
		StopDrawing()
	EndIf
	
	ReleaseDC_(0, DC)
	
	ResizeImage(img, Ecran_Largeur / coef, Ecran_Hauteur / coef, #PB_Image_Raw)
	
	ProcedureReturn img
EndProcedure


If OpenWindow(0, 0, 0, 500, 500, "", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
	ImageGadget(0, 0, 0, WindowWidth(0), WindowHeight(0), 0)
	
EndIf

snap = 1

DesktopSnapShot(snap)


i = ImageTo8bit(ImageID(snap), 2) 


SetGadgetState(0, i)


Save8bitImage(i, "test.bmp") 


Repeat
	event = WaitWindowEvent()
Until event = #PB_Event_CloseWindow

End
I use the #PB_Image_Raw in the resizeimage function, quicker than before :)