You are here

script-fu and image bmp save procedure advanced options??

Hi there,

I was asked to make a plugin for GIMP that can handle saving multiple layers at once while setting the bit-depth of each saved file to a predefined value.

I already made something very similar but this works only for up to 256 color indexed files for I used "gimp-image-convert-indexed"

The progem should work the same way as the standard bmp save, but that seems not to be the same procedure like "file-bmp-save".

If saving a bmp gimp usually asks about the way it should be saved, the comression mode and about the color depth 16-bit, 24-bit, 32-bit.

I was wondering if there is a way to save it using this procedure. What name it has, or if it is coded into GIMP how to call it and give it the values needed to loop the saving procedure.

Please can somebody help?!


I believe the file format is basically determined by the image mode. I am not positive of the details (I have never had the desire to use a BMP file) but I think if the image is RGB with an alpha channel then the file is written in 32-bit; a flattened RGB results in a 24-bit file, as also will an indexed image with more than 16 colors; while an indexed image with fewer than 16 colors results in a 16-bit file.

I want to call the function that is used when you usually save a single bmp but I can't find it. This has nothing to do with alpha channels. Sure if you have a 24-bit image without alpha and then add an alpha channel, you add at least 1 bit and the next step to save is 32-bit.

But I want to cut the color depth at a predefined value (for example 16 bit) and interpolate the missing colors (or stretch it to 16-bit).
This seems already be done by the default save-option of gimp for single bmp-files. But there I can't find a function in the script-fu that works this way.

Is there a way to call that default fuction to use it for the loop?

I am not seeing the behavior you describe; i.e., when there are fewer than 32,767 colors, I do not see the RGB image being saved limited to 32 levels per color channel. Maybe it's happening, but that is not how it appears to me (and I am not particularly motivated to investigate the BMP format).

Nonetheless, to my knowledge the only way you can control the format a BMP file is saved as from plug-ins is by controlling the state of the image being saved (i.e., is RGB, Grayscale, or Indexed; whether it has an alpha channel; and how many colors exist in the image's color table if Indexed).

This demands that -- to whatever extent the BMP format can be controlled -- your script must create a new image from the active drawable, convert that image to the appropriate format, save the image, and then delete it. This is not as onerous as it may sound because creating images is not very resource intensive (creating new "views" for an image, however, is).

Well sorry, I now see if I export I get an advanced choice but it seems not to have effect on the color depth in that way I thought.

I could swear it had but I don't know if it was another version of GIMP or maybe I am simply.

But I' ll try to make the script the way you discribed this seems to be a way that could work. Thank you!

If you you wish to simulate a particular bit-depth then you can apply a stairstep curve to layer, with the number steps being equal to the number of levels for that bit-depth (e.g., 2 bits == 4 levels, 5 bits == 32).

This is not entirely unlike what the Posterize filter does, but for some reason I don't understand, Posterize does not always choose the closest match from the colors that are available.

Here is some code that demonstrates how to simulate given bit depths. The 'simulate-bit-depth' procedure accepts two arguments: the drawable to be modified and the desired bit-depth. The bit-depth can be either a single number or a list of three depths (corresponding to the red, green, and blue channels).

For example, you could pass '(5 6 5) to obtain the result of a 16-bit color mode (with the green channel having one bit more of depth). Note that this will not result in a 16-bit BMP file. It will only simulate how such a file would appear.

(define (make-step-curve number-of-steps)
    (let loop ((result '())
               (count 0) )
      (if (>= count 256)
        (loop (append result 
                      (let clone-loop ((clone-result '())
                                       (number-of-copies (/ 256 number-of-steps)) )
                        (if (zero? number-of-copies)
                          (reverse clone-result)
                          (clone-loop (cons count clone-result) (- number-of-copies 1)) )))
              (+ count (/ (* (/ 256 number-of-steps) 255) (- 256 (/ 256 number-of-steps)))) )))))
(define (simulate-bit-depth drawable bit-depth)
  (let* ((red-depth (if (pair? bit-depth)
                      (car bit-depth)
                      bit-depth ))
         (green-depth (if (pair? bit-depth)
                        (cadr bit-depth)
                        bit-depth ))
         (blue-depth (if (pair? bit-depth)
                       (caddr bit-depth)
                       bit-depth ))
         (step-curve (make-step-curve (expt 2 red-depth))) )
    (gimp-curves-explicit drawable HISTOGRAM-RED   256 step-curve)
    (set! step-curve (make-step-curve (expt 2 green-depth)))
    (gimp-curves-explicit drawable HISTOGRAM-GREEN 256 step-curve)    
    (set! step-curve (make-step-curve (expt 2 blue-depth)))
    (gimp-curves-explicit drawable HISTOGRAM-BLUE  256 step-curve)
    step-curve ))

Thats look promising. I' ll try that too, thank you for your work. Unfortunately I always have a lack of time. But I focus on that soon.

Thank you again!

Subscribe to Comments for "script-fu and image bmp save procedure advanced options??"