|
; GIMP - The GNU Image Manipulation Program |
|
; Copyright (C) 1995 Spencer Kimball and Peter Mattis |
|
; |
|
; This program is free software; you can redistribute it and/or modify |
|
; it under the terms of the GNU General Public License as published by |
|
; the Free Software Foundation; either version 2 of the License, or |
|
; (at your option) any later version. |
|
; |
|
; This program is distributed in the hope that it will be useful, |
|
; but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
; GNU General Public License for more details. |
|
; |
|
; You should have received a copy of the GNU General Public License |
|
; along with this program; if not, write to the Free Software |
|
; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
|
; |
|
; Copyright (C) 2011 Xaffron Software skwong@consultant.com |
|
; |
|
; This script |
|
; 1)adds alpha channel to active layer, |
|
; 2)splits active layer into RGBA, |
|
; 3)converts each layer to 1-, 4-, 5- or 6- bit grayscale w/ FS dither, then |
|
; 4)recomposes it. |
|
; The end effect is that images are "Dithered" to either: |
|
; 12-bit color + 4-bit transparency (ARGB4444/4096colors), |
|
; 16-bit color + no transparency (RGB565/4096colors), or |
|
; 15-bit color + 1-bit transparency (ARGB1555/4096colors). |
|
; |
|
; The higher-depth dither is especially useful for mobile developers who need to pre-dither |
|
; assets for 12- or 16-bit screens. |
|
; |
|
; Version 0.1 Initial Version - No frills, barely works. |
|
; Version 0.2 Renamed to dither16bit.scm - Added RGB565 and ARGB1555. |
|
; |
|
; Version 0.2.1 fork dither16bit.scm - Added ARGB4444 (no dither), ARGB3333 (no dither). |
|
; |
|
; INSTALL: |
|
; Copy the dither16bit.scm file to your scripts dir. |
|
; Extract the separate 1Bit, 4Bit, 5Bit and 6BitGrayscale.gpl files from the zipfile |
|
; and copy to your palettes dir. |
|
; Copy the 3BitGrayscale.gpl file to your palettes dir. |
|
; To run, start up GIMP, go to |
|
;Image->Mode->Dither to ARGB4444 |
|
;Image->Mode->Dither to RGB565 |
|
;Image->Mode->Dither to ARGB1555 |
|
;Image->Mode->to ARGB xxxx |
|
; |
|
; Please email me for any issues... I'm pretty swamped, but I'll try to address! |
|
; |
|
|
|
(define (script-fu-12bit-not-dither aimg adraw ckind dither dithera) |
|
(let* ((img (car (gimp-drawable-get-image adraw))) |
|
(draw (car (gimp-image-get-active-layer img))) |
|
(owidth (car (gimp-image-width img))) |
|
(oheight (car (gimp-image-height img))) |
|
(paltbl |
|
(cond |
|
((= ckind 0) '("4-Bit Grayscale" "4-Bit Grayscale" "4-Bit Grayscale" "4-Bit Grayscale")) |
|
((= ckind 1) '("5-Bit Grayscale" "5-Bit Grayscale" "5-Bit Grayscale" "1-Bit Grayscale")) |
|
((= ckind 2) '("5-Bit Grayscale" "6-Bit Grayscale" "5-Bit Grayscale" "")) |
|
((= ckind 3) '("3-Bit Grayscale" "3-Bit Grayscale" "3-Bit Grayscale" "3-Bit Grayscale")) |
|
((= ckind 4) '("3-Bit Grayscale" "3-Bit Grayscale" "3-Bit Grayscale" "1-Bit Grayscale")) |
|
)) |
|
(palr (car paltbl)) |
|
(palg (cadr paltbl)) |
|
(palb (caddr paltbl)) |
|
(pala (cadddr paltbl))) |
|
|
|
(gimp-context-push) |
|
(gimp-image-undo-group-start img) |
|
(if (equal? pala "") #f (gimp-layer-add-alpha draw)) |
|
|
|
(let* ((layers (if (equal? pala "") |
|
(plug-in-decompose 1 img draw "RGB" 0) |
|
(plug-in-decompose 1 img draw "RGBA" 0))) |
|
(red (car layers)) |
|
(green (cadr layers)) |
|
(blue (caddr layers)) |
|
(alpha (if (equal? pala "") #f (cadddr layers)))) |
|
|
|
(gimp-image-convert-rgb red) |
|
(gimp-image-convert-indexed red dither 4 4096 FALSE FALSE palr) |
|
(gimp-image-convert-grayscale red) |
|
(gimp-image-convert-rgb green) |
|
(gimp-image-convert-indexed green dither 4 4096 FALSE FALSE palg) |
|
(gimp-image-convert-grayscale green) |
|
(gimp-image-convert-rgb blue) |
|
(gimp-image-convert-indexed blue dither 4 4096 FALSE FALSE palb) |
|
(gimp-image-convert-grayscale blue) |
|
(if (equal? pala "") |
|
(gimp-display-new (car (plug-in-compose 1 red 0 green blue 0 "RGB"))) |
|
(begin |
|
(gimp-image-convert-rgb alpha) |
|
(gimp-image-convert-indexed alpha dithera 4 4096 FALSE FALSE pala) |
|
(gimp-image-convert-grayscale alpha) |
|
(gimp-display-new (car (plug-in-compose 1 red 0 green blue alpha "RGBA"))))) |
|
(gimp-image-delete red) |
|
(gimp-image-delete green) |
|
(gimp-image-delete blue) |
|
(if (equal? pala "") #f (gimp-image-delete alpha))) |
|
|
|
(gimp-selection-none img) |
|
(gimp-image-undo-group-end img) |
|
(gimp-displays-flush) |
|
(gimp-context-pop) |
|
)) |
|
|
|
(define (script-fu-12bit-dither aimg adraw) |
|
(script-fu-12bit-not-dither aimg adraw 0 1 1)) |
|
|
|
(define (script-fu-argb1555-dither aimg adraw) |
|
(script-fu-12bit-not-dither aimg adraw 1 1 1)) |
|
|
|
(define (script-fu-rgb565-dither aimg adraw) |
|
(script-fu-12bit-not-dither aimg adraw 2 1 1)) |
|
|
|
(script-fu-register |
|
"script-fu-12bit-dither" |
|
_"Dither to ARGB_4444..." |
|
_"Dither to ARGB4444 (4096) colors. Useful for mobile applications." |
|
"Sunny Kwong <skwong@consultant.com>" |
|
"Sunny Kwong" |
|
"4/27/2011" |
|
"*" |
|
SF-IMAGE "Input image" 0 |
|
SF-DRAWABLE "Input drawable" 0 |
|
) |
|
|
|
(script-fu-register |
|
"script-fu-rgb565-dither" |
|
_"Dither to RGB_565..." |
|
_"Dither to RGB565 (4096) colors. Useful for mobile applications." |
|
"Sunny Kwong <skwong@consultant.com>" |
|
"Sunny Kwong" |
|
"10/23/2012" |
|
"*" |
|
SF-IMAGE "Input image" 0 |
|
SF-DRAWABLE "Input drawable" 0 |
|
) |
|
|
|
(script-fu-register |
|
"script-fu-argb1555-dither" |
|
_"Dither to ARGB_1555..." |
|
_"Dither to ARGB1555 (4096) colors. Useful for mobile applications." |
|
"Sunny Kwong <skwong@consultant.com>" |
|
"Sunny Kwong" |
|
"10/23/2012" |
|
"*" |
|
SF-IMAGE "Input image" 0 |
|
SF-DRAWABLE "Input drawable" 0 |
|
) |
|
|
|
(script-fu-register |
|
"script-fu-12bit-not-dither" |
|
_"to ARGB_xxxx..." |
|
_"to ARGB4444 (4096) or ARGB3333 (512) colors." |
|
"Sunny Kwong <skwong@consultant.com>, mieki256" |
|
"Sunny Kwong, mieki256" |
|
"03/03/2015" |
|
"*" |
|
SF-IMAGE "Input image" 0 |
|
SF-DRAWABLE "Input drawable" 0 |
|
SF-OPTION "Color" '("ARGB4444" "ARGB1555" "RGB565" "ARGB3333" "ARGB1333") |
|
SF-OPTION "RGB Dither" '("none" "fs-dither" "fslowbleed-dither" "fixed-dither") |
|
SF-OPTION "Alpha Dither" '("none" "fs-dither" "fslowbleed-dither" "fixed-dither") |
|
) |
|
|
|
(script-fu-menu-register "script-fu-12bit-dither" "<Image>/Image/Mode") |
|
(script-fu-menu-register "script-fu-rgb565-dither" "<Image>/Image/Mode") |
|
(script-fu-menu-register "script-fu-argb1555-dither" "<Image>/Image/Mode") |
|
(script-fu-menu-register "script-fu-12bit-not-dither" "<Image>/Image/Mode") |