Page 1 of 1

DefineVirtualFile() and file image or sound

Posted: Mon Sep 18, 2017 6:07 pm
by sinisrus
Hello,

I do not understand too much how to do the documentation is a bit too light

I know you have to create a file that contains the files in "MyFile.dat"

and in if I put some text I do => DefineVirtualFile ("hugeresource.dat", 0, 150, "montext.txt")

but for an image or a sound I do not understand in what form or how I can put them in the .dat file ???
do I have to convert the image file to text file and copy the text into my .dat file?

if it is possible to have a complete example?

thank you

Re: DefineVirtualFile() and file image or sound

Posted: Mon Sep 18, 2017 9:44 pm
by zylesea
I think I don't really understand what you are actually asking for..?

DefineVirtualFile() is used to make a virtual file (i.e. no host DOS action involved, it's done 100% within the programs allocated RAM chunk) from a real file and use this file then just if it were a real file. Same for definevirtualfilefromstring, but here the source is not a file, but a string variable.

Here's a case from a program from me that uses virtual files to handle thumbnail views of larger jpgs. First I seek for the beginning and end of the thumbnail chunk (thumbstart$, thumbend$) within the source file (fullpath$), once I found that I copy the according part from the original file to a virtual file named "thumbnail.jpg"

Code: Select all

my_thumb = DefineVirtualFile(fullpath$, thumbstart$, thumbend$-thumbstart$, "thumbnail.jpg") 
From here you can use my_thumb as handle to the virtual file, for example
loadbrush(1,my_thumb) to load the thumbnail (of which the virtual file consists) to a brush.

It's pretty much exactly as in the manual's example.

Re: DefineVirtualFile() and file image or sound

Posted: Tue Sep 19, 2017 12:15 pm
by sinisrus
Zylesea

OK is it possible for you to show me le content of the file fullpath$ please ?

Re: DefineVirtualFile() and file image or sound

Posted: Tue Sep 19, 2017 4:38 pm
by zylesea
The files can be anything. It's a variable that get filled by a filerequester. It's just some path to some original file the virtual file gets derived from.
Here's a bit more code within some context (slightly changed from the original program), it's a routine to quickly extract embedded thumbnails off .jpgs or tiffs.

Code: Select all

         fullpath$=FileRequest("Select drawer", "jpg|jpeg|tiff",#REQ_NORMAL, mypath$) ; get a real file
         OpenFile (1,fullpath$)
         my_rawjpg$=ReadString(1,30000)
         thumbstart$=(PatternFindStrDirect(my_rawjpg$,"\255\216",100))   ;patternmatching
         thumbend$=(PatternFindStrDirect(my_rawjpg$,"\255\217",100))   
         If thumbend$ <> -1 And  thumbend$>thumbstart$
         my_thumb = DefineVirtualFile(fullpath$, thumbstart$, thumbend$-thumbstart$, "thumbnail.jpg") ;make virtual file
         ret_valx, table=IsPicture(my_thumb)            ;check whether the virtual file is actually a picture 

Re: DefineVirtualFile() and file image or sound

Posted: Wed Sep 20, 2017 8:07 am
by sinisrus
ok in the example it is written that the virtual file contains several files
but if I understand many file links instead?

Re: DefineVirtualFile() and file image or sound

Posted: Wed Sep 20, 2017 4:07 pm
by zylesea
The filename of the virtual file seems not to matter at all (except the file name extension for a type casting by Hollywood). To work with the virtual file you rather need the handle to the virtual file, just like with the example from the documentation:

vf$ = DefineVirtualFile("hugeresource.dat", 100000, 32768, "image.png")
LoadBrush(1, vf$, {LoadAlpha = True})


Accessing "image.png" instead of vf$ would probably fail, as the virtual file is not present in any file system and hence there is no path to the virtual file. Instead you need the handle (vf$) to work with the virtual file.

That's how I understood it.

Re: DefineVirtualFile() and file image or sound

Posted: Thu Sep 21, 2017 11:46 am
by sinisrus
Ok thank you

Re: DefineVirtualFile() and file image or sound

Posted: Thu Sep 21, 2017 6:35 pm
by airsoftsoftwair
zylesea wrote:Accessing "image.png" instead of vf$ would probably fail
Yes, it will just look for a normal file named "image.png" then.