L3DT users' community
Large 3D terrain generator

FreeImage

Correspondence concerning plugins and scripts; development, use, bugs and ideas.

FreeImage

Postby aeyr » Tue Nov 14, 2006 11:15 pm

I noticed that L3DT uses FreeImage. It'd be great if you could include the free image header and .lib file along with the plugin api so users could just use the freeimage DLL loaded by L3DT instead of having to link against their own copy.
aeyr
New member
 
Posts: 9
Joined: Tue Nov 14, 2006 11:11 pm

Postby Aaron » Wed Nov 15, 2006 12:07 am

Hi Aeyr,

I can include the lib and header if you like, but in most cases it won't be all that necessary because you can already call the FreeImage functions indirectly using the map_LoadFile and map_SaveFile functions (included in v1.5 of the API.) These functions serve to abstract the implementation of the file handling such that a plugin developer doesn't need to know how or by which library the file is loaded/saved. Linkage to external libraries is then only the concern of the developer that writes the file I/O plugin (me, in the case of the L3DTio_FI plugin, which is the FreeImage wrapper.) Is there a reason you would want to call FreeImage directly?

Cheers,
Aaron.

Edit: Oops, in the docs I mention you should call format_GetFormatByExt or format_GetFormatByExt2 to get the hFormat argument of map_SaveFile/LoadFile. These functions won't be available until v1.6 of the API. However, you can call map_LoadFile/SaveFile with a null hFormat arg, and L3DT will guess the appropriate format based on the map type and file extension. Be sure to have the latest dev build of L3DT if you're going to try this though, as earlier versions may throw errors with null format handles.
User avatar
Aaron
Site Admin
 
Posts: 3696
Joined: Sun Nov 20, 2005 2:41 pm
Location: Melbourne, Australia

Postby aeyr » Wed Nov 15, 2006 1:51 am

Hi. Well, I'm trying write out 2^N+1 size tiles for my HF (see here: http://www.bundysoft.com/phpBB2/viewtopic.php?t=132) and figured I'd have to do this myself. However, it appears the dup borders option SHOULD do what I want, but I can't figure out how to use that either.

So now I have no idea how to go about it. :(

As for exposing FI (definitely a better option than linking directly I'd say), something like a buffer_SaveAsImageFile(buf, width, height, format, filename) and a buffer_LoadFromImageFile(filename) would be fantastic.
aeyr
New member
 
Posts: 9
Joined: Tue Nov 14, 2006 11:11 pm

Postby Aaron » Wed Nov 15, 2006 4:22 am

Hi Aeyr,

I've answered the 2N^1 issue in the other thread.

As for exposing FI (definitely a better option than linking directly I'd say), something like a buffer_SaveAsImageFile(buf, width, height, format, filename) and a buffer_LoadFromImageFile(filename) would be fantastic.


Before I launch into my answer proper, I'll just be pendantic for moment and state that L3DT and the API don't have functions for handling I/O of images specifically; they are treated as just another map file format.

Anyway, the functions you mention would either require plugin developers to write more code in the file I/O plugins (in addition to map/tile support, they would have to add buffer support), or else I would have to map the buffer_ functions via the map_SaveFile/map_LoadFile functions by copying the map data to/from the buffer and calling the plugin map load/save code. This is kind of messy, and I would think unnecessary, since the map class gives you the same functionality of the buffer class (although the map class doesn’t expose the low-level buffer handle.)

Is there a reason you want to access image data as a buffer, and not, say, via map_GetPixel/map_SetPixel? If so, would a function like LPVOID map_GetMemoryDirect(ZMAP hMap) work for you? Obviously this won't work with mosaics, as the data isn't stored in a single buffer, but to access mosaic data you have to use the GetPixel/SetPixel functions anyway (they wrap the code for handling the tile cache.)

Cheers,
Aaron.
User avatar
Aaron
Site Admin
 
Posts: 3696
Joined: Sun Nov 20, 2005 2:41 pm
Location: Melbourne, Australia

Postby aeyr » Wed Nov 15, 2006 5:26 pm

Well, I can envision a few types of uses that could benefit from being able to load and save images without the overhead of having a custom map type. For instance, a brush stroke is typically stored as a greyscale image. Obviously that's useful for anything from painting to blurring, etc. Basically just stuff that's 2d data but not necessarily associated with the map itself. Or, perhaps writing a special mini-map generating plugin or something.
aeyr
New member
 
Posts: 9
Joined: Tue Nov 14, 2006 11:11 pm

Postby Aaron » Thu Nov 16, 2006 12:05 pm

Hi Aeyr,

Here is an example of how you load a brush profile as a greysale image. This is using the next release of the API, which I should be uploading in a few hours:

Code: Select all
CzMap BrushMap;
BrushMap.LoadFile("mybrush.bmp", MAP_BYTE, NULL, false, false);


You declare an instance of a CzMap class to contain the profile, and tell it to load the file you want, specifying the map type (MAP_BYTE, as in this case we want 8-bit greyscale).

Now, I can access the pixel values at any point by doing something like this:

Code: Select all
BYTE b;
BrushMap.GetPixel(i, j, &b);


So basically, loading images or any file that is a 2D data format can be done via the map functions in the API, and there's no nastiness in having to deal directly with buffers. I hope you'll agree that there's not much 'overhead' there.

Incidentally, the 'old way' (using the current API version) is to do this:

Code: Select all
ZMAP hMap = theAPI.var_CreateTemp(VarID_map);
theAPI.map_LoadMapFile(hMap, "mybrush.bmp", MAP_BYTE, NULL, false, false);


and:

Code: Select all
BYTE b;
theAPI.map_GetPixel(hMap, i, j, &b);


Cheers,
Aaron.
User avatar
Aaron
Site Admin
 
Posts: 3696
Joined: Sun Nov 20, 2005 2:41 pm
Location: Melbourne, Australia

Postby aeyr » Thu Nov 16, 2006 4:54 pm

Yeah, that looks like it works. Kudos on the API cleanup, btw, the new form looks much nicer. ;)
aeyr
New member
 
Posts: 9
Joined: Tue Nov 14, 2006 11:11 pm


Return to Plugins and scripts

Who is online

Users browsing this forum: No registered users and 3 guests

cron