Page 1 of 1

A (hopefully) useful script

Posted: 10.02.2004, 07:48
by Toti
First of all, congratulations to all the developers and contributors of this extraordinary software
I am new to this forums. Recently I downloaded 1.3.1 final and noticed that some of my old planet maps were misaligned with the new version ones.
So I wrote this very simple Scheme Script (for the Gimp): you enter a value (it accepts angles and pixel offsets) and it performs a map rotation as needed

Code: Select all

define (script-fu-map-central_meridian img drawable inUnit inShift)
       
      (set! theImageWidth (car (gimp-drawable-width drawable)))
       (set! theImageHeight (car (gimp-drawable-height drawable)))

      ;Parameters in range?:
      (if (and    
            (or
               (and (<= inShift 360) (>= inShift -360) (= inUnit 0))
               
               (and (<= inShift theImageWidth) (>= inShift (- 0 theImageWidth)) (= inUnit 1))
            )
            (not (= inShift 0))
         )
      (begin
         (cond                                        
            ((= inUnit 0)                           ;Angle
               (set! theOrigin (* inShift (/ theImageWidth 360)))                                                      
            )
            ((= inUnit 1)                           ;Pixels                     
               (set! theOrigin inShift)               
            )
         ) ;Cond         
         
         (if (< inShift 0)                        ;Handle negative shifts
            (set! theOrigin (+ theImageWidth theOrigin))
         ) ;if
             
         (gimp-undo-push-group-start img)
      
         (set! theOriginalLayer (car (gimp-image-get-active-layer img)))      
         (set! theCopyLayer (car (gimp-layer-copy theOriginalLayer FALSE)))
         (gimp-image-add-layer img theCopyLayer 1)
         (gimp-layer-set-offsets theCopyLayer theOrigin 0)
      
         (set! theEnd (- theOrigin theImageWidth))
         (gimp-layer-set-offsets theOriginalLayer theEnd 0)
      
         (set! theOriginalLayer (car (gimp-image-merge-visible-layers img 1)))

         (gimp-selection-none img)              

             (gimp-undo-push-group-end img)

         (gimp-displays-flush)
          
      )
      (begin
         (gimp-message "parameters out of range")
      )
      ) ;if        
)


(script-fu-register
   "script-fu-map-central_meridian"
   "<Image>/Script-Fu/Map Central Meridian"   
   "Shifts a cilindrical coordinated map in order to match central meridian requirements"
   "Toti"
   "2004"
   "February 2 2004"
   "RGB* GRAY* INDEXED*"
SF-IMAGE "Image: " 0
SF-DRAWABLE "Drawable: " 0
SF-OPTION _"Unit to use" '(_"Angle" _"Pixels")
SF-VALUE "Shift amount: " "90"

)





To use it, copy and paste it in your text editor. Then save it as any_name.scm in any of your Gimp <scripts> folders.
Run the Gimp, open an image and the script should be under the <image\script-fu> menu (press right mouse button over the open image, and go to Script-Fu).
I have tested it with 16K maps and it worked fine in my P3 256Mb RAM Win98 (after paging to disk for 10 minutes) so I expect it should work fine with 32K maps in more powerful systems

Please remember to backup your file before running this script on it

Hope it is useful
:D

Re: A (hopefully) useful script

Posted: 10.02.2004, 12:48
by t00fri
Toti wrote:First of all, congratulations to all the developers and contributors of this extraordinary software
I am new to this forums. Recently I downloaded 1.3.1 final and noticed that some of my old planet maps were misaligned with the new version ones.
So I wrote this very simple Scheme Script (for the Gimp): you enter a value (it accepts angles and pixel offsets) and it performs a map rotation as needed

Hope it is useful
:D


Well, the script is certainly useful for you and other people who might want to practice Gimp (Scheme) scripting. But since you are not really doing this as a true batch operation[i.e. console level, NO X-server, no Gimp opened](which /would be useful/ for very large textures (100's of MB!), I want to point out that the /interactive Gimp command/ you have to click (with the same result as your script) is lightening fast and absolutely trivial...

If someone cares to know how the command reads, tell me;-)

Bye Fridger

Posted: 11.02.2004, 02:05
by Toti
Fridger:
Some time ago I noticed that certain small bodies textures were misaligned and used some trailing/leading hemispheres data on the Internet to correct them. Most of them only required 90/180 degree corrections so I thought it would be useful to code a script to make degree alignments.
Since it appears to be a very common issue about textures I thought it wouldn't be so easy to correct ;)
Are you telling me that there a GIMP GUI command that allows to realign textures this way? I searched for such a feature but couldn' t find it.
I tried Displace command but it is much more powerful as its behaviour is guided by a diplacement map, etc.

Edit:added a word

Posted: 11.02.2004, 02:43
by Bob Hegwood
Toti,

All you have to do is hit CTRL-SHIFT-O to invoke the offset command in Gimp.

Piece of cake. (Even for a poor, old, tired, computer-illiterate geezer like myself!)

Take care, Bob

Posted: 11.02.2004, 04:47
by Toti
Thank you, Bob
Finally I could find this feature "hidden" under the Transform menu which I have never used since most of its functions are accessible from the tools palette. Erroneously I assumed they were all the same between the menu and the palette. :oops:
But the script above can do offsets given an angle value (As I already said, I found this useful in the past, but now I don?t know if someone else will)

Posted: 11.02.2004, 06:45
by Bob Hegwood
Hey, don't give up so easily... :wink:

The script you wrote can be a valuable addition to *somebody's* collection of Celestia-related tools.

In my case, I have a limited machine which can display a maximum texture size of only 1024 x 1024, but that doesn't mean that some of the other users here can't find some use for it.

Again in my case, I just don't have the need for it. If I find a texture I like, I simply open it up with Gimp and change it post-haste.

However, some of the real developers here may find some value in a tool that can be set up to process the larger textures.

Thanks very much for the contribution, and for the effort. Most users don't even take the time to say "Hello," let alone try to offer an improvement.

Keep it up son, yer doing fine! Image

Thanks again, Bob

Posted: 11.02.2004, 09:31
by t00fri
Toti wrote:Fridger:
Some time ago I noticed that certain small bodies textures were misaligned and used some trailing/leading hemispheres data on the Internet to correct them. Most of them only required 90/180 degree corrections so I thought it would be useful to code a script to make degree alignments.
Since it appears to be a very common issue about textures I thought it wouldn't be so easy to correct ;)
Are you telling me that there a GIMP GUI command that allows to realign textures this way? I searched for such a feature but couldn' t find it.
I tried Displace command but it is much more powerful as its behaviour is guided by a diplacement map, etc.

Edit:added a word


Toti,

as Bob H. mentioned already, the required interactive command is

SHIFT CTRL O

with <width/2> entered into the x-offset.

and that's it. Really too simple for a 1 page Scheme script...

To get back to batch operations: As you must have noticed, there is a great demand for handling "monster textures" in machines with strongly limited memory!

Hence, scripts involving image manipulation commands that do NOT require a working X-server (saves 100's of MB) along with an "expensive" GUI program (e.g. a spawned GIMP) are exceedingly useful and sought for.

I have written, for example, the tiling script 'virtualtex' that is widely used in the VT generation process of monster textures.

There, one uses other tools, however: ImageMagick command line programs or the NetPbm command line tools. The scripts can indeed be operated in a minimal console environment to save memory! An essential trick is that the HD space is used instead of the (missing) RAM such that there are practically little limitations for the texture sizes being worked on!

In all these demanding tasks, the texture itself may be too large to be loaded into memory. So GUI programs are out.

Bye Fridger

Posted: 11.02.2004, 23:03
by Toti
Fridger:
Thank you for your comments.
But let me explain some points further:

1] As I said, I found that several misaligned textures can easily be corrected via 90/180 degree shifts.
2] I thought that the number of these "incorrect" textures was quite large.
3] I couldn't find the GIMP offset command ("hidden" right in front of my eyes)
4] I assumed that such command did not existed. Strange, but otherwise, been so easy, the textures would be corrected ;)
5] I think that the (relatively recent) development of body surface labels is a huge improvement to this astronomical simulation, and the existence of misaligned textures somewhat weakens these new capabilities and creates a bit of chaos (I have read several phrases of the kind "the labels are not where they should be", or "your texture must be aligned properly in order to match the surface features", etc.)
6] There are a lot of Celestia users that do not want/know how to work with consoles, command line parameters, etc; some of them are Windows users that do not obtain that great advantages with utility GUI suppression (since Windows is still there, eating RAM) and some of these users may want to have their textures correctly aligned.
7] It's simpler to work with angle offsets than with pixel offsets since the former are independent of the texture width
8] Even knowing that they need to rotate certain texture x degrees, some users may find uncomfortable/difficult/dubious calculating the angle/pixel offset conversion (a trivial equation)

Given those facts I decided to code the above script. And I found it useful with my textures (below 8K). I tested it with larger textures (up to 16K) and it worked fine, too.

But you are right: the offset command exist and it is fast and reliable. It makes the above script too long and ingenuous ;). To end this job, I will post a new version that is much shorter (a simple shell with conversion formula for the offset command)

And I have used your Imagemagick virtualtex script under Cygwin to build some VT sets. I had to make slight modifications to it, mainly because the non printable characters issue under Windows (the promised removal of these characters by a Unix native text editor didn?t work). Virtualtex did its job very well. It has always been clear to me that this is the only advantageous approach for repetitive, boring and/or RAM ultra consuming tasks!


Bob, thank you again for your encouragement.

Bob Hegwood wrote:In my case, I have a limited machine which can display a maximum texture size of only 1024 x 1024, but that doesn't mean that some of the other users here can't find some use for it.

But can?t you use virtual textures of 1024 x 1024 size each tile, in jpg format? Perhaps you can download a bigger texture, let?s say 4K and make that kind of virtual texture with it.

Edit: spelling

Posted: 11.02.2004, 23:17
by Bob Hegwood
Toti wrote:But can?t you use virtual textures of 1024 x 1024 size each tile, in jpg format? Perhaps you can download a bigger texture, let?s say 4K and make that kind of virtual texture with it.


Beats the hell out of me, Toti...

I haven't tried that yet. You mean to tell me that that is what virtual textures are for? :oops:

Well I'll be damned! I guess I'll have to investigate VT's, yes?

Will see what happens. (If I ever get finished writing a script I'm working on.)

Thanks very much for the advice.

Posted: 12.02.2004, 01:38
by Toti
The new script as it should have been from the beginning:


Code: Select all

(define (script-fu-map-central-meridian img drawable inUnit inShift)
       
      (set! theImageWidth (car (gimp-drawable-width drawable)))
       (set! theImageHeight (car (gimp-drawable-height drawable)))

      ;Parameters in range?:
      (if (and    
            (or
               (and (<= inShift 360) (>= inShift -360) (= inUnit 0))
               
               (and (<= inShift theImageWidth) (>= inShift (- 0 theImageWidth)) (= inUnit 1))
            )
            (not (= inShift 0))
         )
      (begin
         (cond                                        
            ((= inUnit 0)                              ;Angle               
                  (set! theOrigin (* inShift (/ theImageWidth 360)))
                  (if (< inShift 0)                     ;Handle negative shifts
                     (set! theOrigin (+ theImageWidth theOrigin))
                  ) ;if                     
            )
            ((= inUnit 1)                              ;Pixels         
               (set! theOrigin inShift)               
            )
         ) ;Cond         
                               
         (gimp-undo-push-group-start img)
      
         (gimp-channel-ops-offset drawable TRUE 0 theOrigin 0)   

       (gimp-undo-push-group-end img)

         (gimp-displays-flush)
          
      )
      (begin
         (gimp-message "parameters out of range")
      )
      ) ;if        
)


(script-fu-register
   "script-fu-map-central-meridian"
   "<Image>/Script-Fu/Map Central Meridian"   
   "Shifts a cilindrical coordinated map in order to match central meridian requirements"
   "Toti"
   "2004"
   "February 11 2004"
   "RGB* GRAY* INDEXED*"
SF-IMAGE "Image: " 0
SF-DRAWABLE "Drawable: " 0
SF-OPTION _"Unit to use" '(_"Angle" _"Pixels")
SF-VALUE "Shift amount: " "90"

)



Again, to use it, copy and paste it in your text editor. Then save it as any_name.scm in any of your Gimp <scripts> folders.
Run the Gimp, open an image and the script should be under the <image\script-fu> menu (press right mouse button over the open image, and go to Script-Fu).
If you already downloaded the first version, i suggest you to delete and replace it with this new one.

Note1: as there is a built-in round function included (to convert from Real to Integer numbers) when using the angle input, the successive use of the script on a texture may produce a remnant shift: for example, running 4 90 degrees shift on a 250 pixels wide texture will not restore the texture look to the original one (it will be slighty shifted). This is normal.
But 90/180/270 degree shifts will NOT produce that effect with the kind of textures Celestia uses. Keep all this in mind.

Note2: as I already said, ALWAYS backup your texture before running this script on it, that way if you later notice something wrong with the texture, you will have your backup copy to restore it.

Now I?m moving onto another subject...
:)