#!/usr/bin/env python # -*- coding: utf-8 -*- ##################################################################################### ## This code is released under the GPL liscence by M-A Loyer (weirdfox--gmail.com) ## http://www.gnu.org/licenses/gpl.html ##################################################################################### ## The Gimp exporter for NDS 3D Textures ##################################################################################### ## ## File format description : ## * A3I5 and A5I3 ## char[4] file type : "a3i5" or "a5i3" ## uint32 width ## uint32 height ## u8[] image data with encodded alpha and index (8bit by pixel). ## size: width x height x 1bytes ## u16[] palette data. size: nbcolor x 2bytes ## ##################################################################################### import struct import gimp from gimpfu import * gettext.install("gimp20-python", gimp.locale_directory, unicode=True) ## Convert a rgb color to RGB15 format def rgb32toint16(rr,gg,bb): if rr+4 >255: r = 31 else: r = (rr+4) >> 3 if gg+4 >255: g = 31 else: g = (gg+4) >> 3 if bb+4 >255: b = 31 else: b = (bb+4) >> 3 color = r | (g<<5) | (b<<10) return color ## Write the palette from imageIndex to fileOut in RGB15 format def createPalette(imageIndex,nbColors,fileOut): # Write the palette to the file (nbindex,colormap) = pdb.gimp_image_get_colormap(imageIndex) for i in range(0,nbColors): try: color = rgb32toint16(colormap[i*3+0],colormap[i*3+1],colormap[i*3+2]) except IndexError: color = 0 fileOut.write(struct.pack(" 3 and pixel[3] > 128: color |= (1<<15) fileOut.write(struct.pack("