Working with images using memblocks by Dostej12th Mar 2004 9:07
|
---|
Summary It offers this functions for memblock and image function cutmemimage(mem1, mem2, xo, yo, xu, yu) function mem2img(memnr, imgnr, md) function file2mem(img as string, memnr) functio Description Here are some functions to deal with images using memblocks. I try to increase the speed. And I think it did. But the possibilities are and the amount of work are not so good for me, so I dont work on this any more. (I did it with a DLL) Code ` This code was downloaded from The Game Creators ` It is reproduced here with full permission ` http://www.thegamecreators.com rem load image "c:\darkbasic\temp\test1.bmp", 5 remstart load image "c:\galinc core\pics\mainscreen.jpg", 5 create bitmap 30,1024, 768 paste image 5, 0, 0 remend t1 = timer() rem load bitmap "c:\galinc core\pics\mainscreen.jpg", 30 rem make memblock from bitmap 1, 30 rem delete bitmap 30 rem load image "c:\galinc core\pics\mainscreen.bmp", 6 file2mem("c:\galinc core\pics\mainscreen.bmp", 1) t2 = timer() rem get image 5, 0, 0, 1023, 767, 1 cutmemimage(1, 2, 0, 0, 1023, 767) t3 = timer() set current bitmap 0 mem2img(2, 5, 1) paste image 5, 0, 0 t4 = timer() print "time bm-mem1: ";t2-t1 print "imgcut: ";t3-t2 print "memimg: ";t4-t3 print "time ges: ";t4-t1 do sync loop end `Diese function läd ein Bild in einen Memblock und löscht das Bild, wenn md = 1 function img2mem(imgnr, memnr, md) make memblock from image memnr, imgnr if md = 1 then delete image imgnr endfunction `Diese function läd ein Bild in einen Memblock und löscht das Bild, wenn md = 1 function file2mem(img as string, memnr) load bitmap img, 1 make memblock from bitmap memnr, 1 delete bitmap 1 endfunction `Diese Funktion macht aus einem Memblock ein Bild und löscjt den Memblock, wenn md = 1 function mem2img(memnr, imgnr, md) make image from memblock imgnr, memnr if md = 1 then delete memblock memnr endfunction `This function cut an image from another using memblocks `The borders are part of the new image function cutmemimage(mem1, mem2, xo, yo, xu, yu) if memblock exist(mem1) rem make memblock from image mem1, imgnr1 t1 = get memblock size(mem1) sw = memblock dword(mem1, 0) : `width sh = memblock dword(mem1, 4) : `height `Check borders if xo < 0 then xo = 0 if yo < 0 then yo = 0 if xu > sw then xu = sw if yu > sh then yu = sh sw2 = xu - xo+1 sh2 = yu - yo+1 `Make new memblock make memblock mem2, 12 + sw * sh * 4 write memblock dword mem2, 0, sw2 : `überträgt breite write memblock dword mem2, 4, sh2 : `überträgt höhe write memblock dword mem2, 8, memblock dword(mem1, 8) : `überträgt farbtiefe `übertragen der Farbwerte - mit copy memory gleich schnell wie copy memblock p1 = get memblock ptr(mem1) p2 = get memblock ptr(mem2) for a = yo to yu copy memory p2 + 12 + (a-yo) * sw2 * 4, p1 + 12 + xo * 4 + a * sw* 4, sw2 * 4 next a endif endfunction |