L3DT users' community
Large 3D terrain generator

Splitting images

Got a problem or need advice?

Splitting images

Postby Q-dad » Mon Jun 04, 2007 8:31 am

(not spitting images) :wink:

Does anyone know about a free tool which can split an image into smaller images, the size of those smaller images decided by input from the user..? I'd like to have an easy way of splitting 64x16384 images into 64x64 tiles. I need to do this for both TGA and PCX files. I have searched the net for days without finding anything useful...

Or maybe it can be done inside for instance Paintshop Pro...?

Or maybe even inside L3DT, directly or by adding a script...?
TXP (Terrain Xpansion Pack) for DF2: txp.df2.org

Image
User avatar
Q-dad
Luminary
 
Posts: 97
Joined: Tue Nov 22, 2005 11:54 pm
Location: Jessheim, Norway

Postby Aaron » Mon Jun 04, 2007 1:31 pm

Hi Q-dad,

L3DT can do this with the mosaic export option. The problem is that L3DT doesn't have an UI option for importing colour maps. I'll have a tinker with some scripts and see what I can cope up with.

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

Postby Q-dad » Mon Jun 04, 2007 2:55 pm

Hi Aaron,

aaron wrote:The problem is that L3DT doesn't have an UI option for importing colour maps. I'll have a tinker with some scripts and see what I can cope up with.


Yes, I tried that first, thinking that since L3DT had the option to import a heightmap, it also would have the option to import a color map. I guess the reason that isn't so, is that the color map is one of the end result files, while the heightmap is one of the input files, i.e. being used for a lot of the algorithms in L3DT...? Adding an option to import a color map to replace the calculated one, maybe that wouldn't make any sense at all...?
TXP (Terrain Xpansion Pack) for DF2: txp.df2.org

Image
User avatar
Q-dad
Luminary
 
Posts: 97
Joined: Tue Nov 22, 2005 11:54 pm
Location: Jessheim, Norway

Postby Aaron » Wed Jun 06, 2007 2:45 am

Hi Q-dad,

I've worked out a script to import a TGA as a texture map so that you can split it into tiles.

Firstly, you have to create a dummy project (e.g. fractal, blank HF, etc.) Then, select the 'Extensions->ZeoScript->Run script' menu option and enter the following code:

Code: Select all
ExtAPI.map.LoadFile <m:TX> <z:file.OpenDlg "tga" NULL "TGA images (*.tga)|*.tga"> 3 <f:TX 3 "tga"> false true


(this code must be on one line)

This code assumes that the TGA is 24-bit. If you have a 32-bit TGA (i.e. RGBA), you may need to change the <f:TX 3 "tga"> bit to <f:NULL 4 "tga">

After you've run the script, and assuming it works, use 'view->show map->texture map' to view the texture, then 'file->export->active map' to export it as a tile set.

Let me know how it goes.

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

Postby Q-dad » Wed Jun 06, 2007 11:25 am

Hi Aaron,

Thx for the script! :-)

It works for 24-bit TGA, but for some reason it starts at the bottom of the file, i.e. tile 0 is the 64x64 tile from the bottom of the original 64x16384 file, and tile 255 is the 64x64 tile from the top of the original 64x16384 file. It's not a huge problem, though.

Code: Select all
ExtAPI.map.LoadFile <m:TX> <z:file.OpenDlg "tga" NULL "TGA images (*.tga)|*.tga"> 3 <f:NULL 4 "tga"> false true


Running the above script on a 32-bit TGA (RGBA) doesn't work, though. I've PM'ed you my log file...

I guess a similar script for PCX won't make sense, in that one cannot save mosaics to PCX files...?
TXP (Terrain Xpansion Pack) for DF2: txp.df2.org

Image
User avatar
Q-dad
Luminary
 
Posts: 97
Joined: Tue Nov 22, 2005 11:54 pm
Location: Jessheim, Norway

Postby Aaron » Thu Jun 07, 2007 12:40 am

Hi Q-dad,

You can force L3DT to flip the y-axis of the image by going to 'File->Format preferences', then 'Project maps->Texture map->TGA', then 'Options', and set 'InvertY' to true.

Regarding RGBA, I made a mistake. Try the following code:

Code: Select all
ExtAPI.map.LoadFile <m:TX> <z:file.OpenDlg "tga" NULL "TGA images (*.tga)|*.tga"> 4 <f:NULL 4 "tga"> false true


(changed a 3 to a 4)

Oh, by the way, to flip the y-axis in the RGBA TGA files, the format option is 'Generic maps->DWORD->TGA'.

I'll put mosaic PCX on the to-do list.

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

Postby Q-dad » Thu Jun 07, 2007 6:57 am

aaron wrote:You can force L3DT to flip the y-axis of the image by going to 'File->Format preferences', then 'Project maps->Texture map->TGA', then 'Options', and set 'InvertY' to true.

Oh, by the way, to flip the y-axis in the RGBA TGA files, the format option is 'Generic maps->DWORD->TGA'.

Working excellent - Thx! :-) I didn't change anything there, though, but instead temporary in the TGA options in the mosaic output dialog.

The only thing left to ask for here, is if it's possible to change the name format of the generated mosaic tiles...? In my case, the "_x0y0" to "_x0y255" endings to the file names makes it hard to sort the tile files properly afterwards. If one could set for instance that all the numerical values should use 3 digits, it would solve my specific problem, i.e. "_x000y000" to "_x000y255"...

aaron wrote:(changed a 3 to a 4)

That did the trick. Thx again!

aaron wrote:I'll put mosaic PCX on the to-do list.

Thx!
TXP (Terrain Xpansion Pack) for DF2: txp.df2.org

Image
User avatar
Q-dad
Luminary
 
Posts: 97
Joined: Tue Nov 22, 2005 11:54 pm
Location: Jessheim, Norway

Postby Aaron » Fri Jun 08, 2007 12:59 am

Hi Q-dad,

I've added mosaic PCX export support to the latest dev build*.

Regarding the changing of the mosaic tile naming scheme, this is on the to-do list but probably won't happen very soon. To support all the different options that have already been requested, I'll need to add support either for regular expression parsing, or else have plugin functions set the tile names (I'm leaning towards the latter, as it can implement the former anyway).

Cheers,
Aaron.

* ...which is actually the final release L3DT v2.5a, but I haven't moved the links yet.
User avatar
Aaron
Site Admin
 
Posts: 3691
Joined: Sun Nov 20, 2005 2:41 pm
Location: Melbourne, Australia

Postby Q-dad » Sun Jun 10, 2007 10:07 pm

Hi Aaron,

Thx for the added mosaic PCX export support. It works, so in theory I could have used it for splitting my 64x16384 PCX files up into 256 64x64 mosaic tiles... However, I can't import that file into L3DT as a heightmap, since only JPG heightmap files are supported, it seems. I also tried changing the script used for loading RGBA TGA files, so that it could load PCX files instead, but I can't figure out from the documentation how that script should look like. Here's what I tried...:

Code: Select all
ExtAPI.map.LoadFile <m:TX> <z:file.OpenDlg "pcx" NULL "PCX images (*.pcx)|*.pcx"> 20 <f:TX 20 "pcx"> false true


I believe TX should be changed to something else, but I don't know what. A heightmap should be ID number 20 as far as I can tell from the documentation (http://www.bundysoft.com/docs/doku.php?id=zeolite:mapid), but it seems the TX value also represents the ID number... Any suggestions...?
TXP (Terrain Xpansion Pack) for DF2: txp.df2.org

Image
User avatar
Q-dad
Luminary
 
Posts: 97
Joined: Tue Nov 22, 2005 11:54 pm
Location: Jessheim, Norway

Postby Aaron » Mon Jun 11, 2007 1:41 am

Hi Q-dad,

This might work:

Code: Select all
ExtAPI.map.LoadFile <m:HF> <z:file.OpenDlg "pcx" NULL "PCX images (*.pcx)|*.pcx"> 20 <f:HF 20 "pcx"> false true


The PCX format is only supported for heightfield formats, so you need to use the "HF" string when looking for the format (in <f:HF ...>). It's probably also a good idea to store the map in the heightfield, thus <m:HF>. I haven't quite finished the script documentation, but the <m:..> and <f:...> syntax in the scripts is explained [url=http://www.bundysoft.com/wiki/doku.php?id=plugins:general:zeoscript:syntax#using_maps]on this page[/url], under 'using maps' and 'using formats', respectively.

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

Postby Q-dad » Mon Jun 11, 2007 6:29 am

Hi Aaron,

Thx, that worked :-) I had tried with HM, not HF... :oops:

I see that there is no InvertY field available for PCX files, though.
TXP (Terrain Xpansion Pack) for DF2: txp.df2.org

Image
User avatar
Q-dad
Luminary
 
Posts: 97
Joined: Tue Nov 22, 2005 11:54 pm
Location: Jessheim, Norway

Postby Aaron » Mon Jun 11, 2007 10:42 am

Hi Q-dad,

I've added the InvertY option to the PCX plugin, which you can download from here:

http://www.bundysoft.com/L3DT/downloads/plugins/bin/L3DTio_PCX-bin.zip

To use this, you'll need to first uninstall the current plugin before loading the update (using the extension manager). This forces L3DT to nuke the PCX settings so that the new plugin can set the InvertY flag appropriately.

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

Postby Q-dad » Mon Jun 11, 2007 10:16 pm

Hi Aaron,

Thx for your great effort! I followed your instructions above (remove current plugin --> restart L3DT --> load new plugin --> restart L3DT), but the InvertY option doesn't seem to work for PCX files, neither when setting it to true in the Format Preferences (Project or Generic Maps) nor in the mosaic export options. I'm not getting any errors when exporting the PCX mosaic tiles. The similar InvertY option for TGA files still works. I thought I'd compare the .zeo files to see if I could spot anything wrong, but I of course found out that they're binary...
TXP (Terrain Xpansion Pack) for DF2: txp.df2.org

Image
User avatar
Q-dad
Luminary
 
Posts: 97
Joined: Tue Nov 22, 2005 11:54 pm
Location: Jessheim, Norway

Postby Aaron » Tue Jun 12, 2007 1:13 am

Hi Q-dad,

Hmm...maybe I missed something in testing. I did check that it flipped the export, but maybe I messed up the import. Did you have the InvertY flag enabled for both import and export?

Cheers,
Aaron.

PS: With the above script, the format being used is 'Project maps->heightfield->PCX', not the generic map one. <f:HF 0 pcx> is the project map format (the number is ignored), and <f:NULL 20 pcx> is the generic map format.

PPS: ZEO files are just renamed DLLs.
User avatar
Aaron
Site Admin
 
Posts: 3691
Joined: Sun Nov 20, 2005 2:41 pm
Location: Melbourne, Australia

Postby Aaron » Sun Jun 17, 2007 10:18 am

Hi Q-dad,

Just a quick note: In the latest dev build, you can import the heightfield from PCX files using the 'file->import->heightfield' option, so you don't need to use the script trick any more.

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


Return to Help and support

Who is online

Users browsing this forum: No registered users and 4 guests

cron