copy bitmap using memcopy[solved]

Linux specific questions.
Post Reply
honeydatax
Posts: 26
Joined: Jul 11, 2021 11:55

copy bitmap using memcopy[solved]

Post by honeydatax »

im try to copy a bitmap to other using memcopy to be fast very fast
,but the pointer is not correct?
thanks

Code: Select all


#inclib "mems"
extern "C"
	declare function memcopy cdecl(byref dst as any,byref src as any,byval bytes as uinteger)as any ptr
end extern 
screenres 300,200,8
dim y as integer
dim x as integer
dim row as byte ptr
dim row2 as byte ptr
dim image as any ptr = imageCreate(64,64)
dim image2 as any ptr = imageCreate(64,64)
dim picth as long
dim picth2 as long
dim pixels as any ptr
dim pixels2 as any ptr
'goto ends
	line(0,0)-(300,200),7,bf
	if 0<>imageinfo(image,,,,picth,pixels)then 
		end 
	end if
	if 0<>imageinfo(image2,,,,picth2,pixels2)then 
		end 
	end if
	for y=0 to 63
		row=pixels+y*picth
		for x=0 to 63
			row[x]=x
		next
	next
	row=pixels
	row2=pixels2
	memcopy(row2,row,64*64)
put(10,10),image
put(10,100),image2
imagedestroy(image)
imagedestroy(image2)
ends:
sleep





Code: Select all

#include <string.h>

char *memcopy(void *dst,void *src,int size){
	memcpy(dst,src,(size_t)size);
}

Last edited by honeydatax on Mar 30, 2022 9:01, edited 1 time in total.
badidea
Posts: 2586
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: copy bitmap using memcopy

Post by badidea »

Are you sure that your memcopy is correct?
With the memcpy from the C Standard Library Functions as defined in "crt/string.bi" it seems to work fine here (32 & 64 bit).
Also, you do not use pitch, but for 64 bytes row length that should should not matter.

Code: Select all

#include "crt/string.bi"
#define memcopy memcpy

screenres 300,200,8
dim y as integer
dim x as integer
dim row as byte ptr
dim row2 as byte ptr
dim image as any ptr = imageCreate(64,64)
dim image2 as any ptr = imageCreate(64,64)
dim picth as long
dim picth2 as long
dim pixels as any ptr
dim pixels2 as any ptr
'goto ends
	line(0,0)-(300,200),7,bf
	if 0<>imageinfo(image,,,,picth,pixels)then 
		end 
	end if
	if 0<>imageinfo(image2,,,,picth2,pixels2)then 
		end 
	end if
	for y=0 to 63
		row=pixels+y*picth
		for x=0 to 63
			row[x]=x
		next
	next
	'row=pixels
	'row2=pixels2
	'memcopy(row2,row,64*64)
	if picth <> picth2 then
		end
	else
		memcopy(pixels2,pixels,64*picth)
	end if
put(10,10),image
put(10,100),image2
imagedestroy(image)
imagedestroy(image2)
ends:
sleep
honeydatax
Posts: 26
Joined: Jul 11, 2021 11:55

Re: copy bitmap using memcopy

Post by honeydatax »

not sure ; but im dont have crt/string.bi in my raspbery version
paul doe
Moderator
Posts: 1730
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: copy bitmap using memcopy

Post by paul doe »

Code: Select all

#include once "fbgfx.bi" '' For Fb.Image buffers
#include once "crt.bi"   '' For memcpy

function clone( img as Fb.Image ptr ) as Fb.Image ptr
  var res = imageCreate( img->width, img->height )
  
  memcpy( _
    cast( ubyte ptr, res ) + sizeof( Fb.Image ), _
    cast( ubyte ptr, img ) + sizeof( Fb.Image ), _
    img->pitch * img->height )
  
  return( res )
end function
honeydatax
Posts: 26
Joined: Jul 11, 2021 11:55

Re: copy bitmap using memcopy

Post by honeydatax »

sory but my version of raspberry pi dont have:
crt/string.bi
or
crt.bi

only
string.bi
but string.bi dont have memcpy or fb_,memcpy :(
sory :(
TJF
Posts: 3809
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Re: copy bitmap using memcopy

Post by TJF »

Either use inbuild

Code: Select all

VAR res = FB_MEMCOPY(Source, Dest, Bytes)
or C lib like

Code: Select all

EXTERN "C"
  DECLARE FUNCTION memcopy CDECL ALIAS "memcpy"(BYVAL AS ANY PTR, BYVAL AS ANY PTR, BYVAL AS ULONG /'size_t'/) AS ANY PTR
END EXTERN
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: copy bitmap using memcopy

Post by dodicat »

If all fails, then make your own memcopy.

Code: Select all



Sub memcopy(dest As Any Ptr,src As Any Ptr,count As Long)
    Dim As Ubyte Ptr newdst=dest
    Dim As Ubyte Ptr newsrc=src
    For n As Long=0 To count
        newdst[n]=newsrc[n]
    Next n
End Sub

Function Dead_Ringer( img As Any Ptr ) As Any Ptr
    Dim As Long x,y,bypp,pitch
    Imageinfo img,x,y,bypp,pitch
    static as any ptr res:res = Imagecreate(x,y)
    memcopy(res,img,x*pitch+(32))
    Return( res )
End Function

#macro test1
Screen 19,32
Dim As Any Ptr i=Imagecreate(200,200,Rgb(170,0,0))
Circle i,(100,100),50,Rgb(0,0,170),,,,f
Line i,(0,0)-(199,199),Rgb(255,255,255),b
Put(30,30),i,Pset
Put(300,300),Dead_Ringer(i),Pset
#endmacro

#macro test2
Screen 19
Dim As Any Ptr i=Imagecreate(200,200,4)
Circle i,(100,100),50,1,,,,f
Line i,(0,0)-(199,199),15,b
Put(30,30),i,Pset
Put(300,300),Dead_Ringer(i),Pset
#endmacro

test1  ',---------- do test1 then test2

print "Press any key . . ."
Sleep
Imagedestroy i


 
fxm
Moderator
Posts: 12082
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: copy bitmap using memcopy

Post by fxm »

Why not use the FreeBASIC FB_MemCopy built-in function ?
Warning: The first two arguments passed must be references or dereferenced pointers or by specifying the ByVal keyword in front of the pointer names (not just pointers).
honeydatax
Posts: 26
Joined: Jul 11, 2021 11:55

Re: copy bitmap using memcopy

Post by honeydatax »

thanks all by the help but im need the fb_memcopy to build my small xfe to run in command line out of X
:)

like im make on c code :)
so must be real fast




https://github.com/linesky/DXwindow

honeydatax
Posts: 26
Joined: Jul 11, 2021 11:55

Re: copy bitmap using memcopy

Post by honeydatax »

afther im try to compile my code from a c lib im give the error missing functions shm_open and shm_,unlink from sys/mman.h
wat argument im must use to compile in c to include this file thanks




https://github.com/linesky/basWindow
Post Reply