[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [1248] branches/ io_import_gimp_to_3d_layers.py: GIMPto3DLayers: WIP commit of .xjt support (GIMP compressed image)
Daniel Salazar
zanqdo at gmail.com
Tue Dec 7 20:20:12 CET 2010
Revision: 1248
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-extensions&revision=1248
Author: zanqdo
Date: 2010-12-07 20:20:12 +0100 (Tue, 07 Dec 2010)
Log Message:
-----------
GIMPto3DLayers: WIP commit of .xjt support (GIMP compressed image)
Modified Paths:
--------------
branches/io_import_gimp_to_3d_layers.py
Modified: branches/io_import_gimp_to_3d_layers.py
===================================================================
--- branches/io_import_gimp_to_3d_layers.py 2010-12-07 18:14:05 UTC (rev 1247)
+++ branches/io_import_gimp_to_3d_layers.py 2010-12-07 19:20:12 UTC (rev 1248)
@@ -17,14 +17,14 @@
# ##### END GPL LICENSE BLOCK #####
bl_addon_info = {
- "name": "Import GIMP Files as 3D Layers (.xcf)",
+ "name": "Import GIMP Files as 3D Layers (.xcf, .xjt)",
"author": "Daniel Salazar (ZanQdo)",
- "version": (1,0,2),
+ "version": (1,1,0),
"blender": (2, 5, 5),
"api": 33419,
- "location": "File > Import > GIMP Images as 3D Layers(XCF)",
+ "location": "File > Import > GIMP Images as 3D Layers(.xcf, .xjt)",
"description": "Imports GIMP multilayer image files into 3D Layers",
- "warning": "Requires xcftools installed",
+ "warning": "XCF import requires xcftools installed",
"wiki_url": "http://wiki.blender.org/index.php/Extensions:2.5/Py/"\
"Scripts/File_I-O/GIMPto3DLayers",
"tracker_url": ""\
@@ -32,21 +32,17 @@
"category": "Import/Export"}
"""
-This script imports GIMP layered image files into 3D Layers.
+This script imports GIMP layered image files into 3D Layers (.xcf, .xjt)
"""
def main(File, Path, LayerViewers, MixerViewers, LayerOffset,\
LayerScale, OpacityMode, PremulAlpha, ShadelessMats,\
- SetCamera, SetupCompo, GroupUntagged):
+ SetCamera, SetupCompo, GroupUntagged, Ext):
#-------------------------------------------------
- # CONFIG
- XCFInfo = 'xcfinfo'
- XCF2PNG = 'xcf2png'
- #-------------------------------------------------
- #Folder = '['+File.rstrip('.xcf')+']'+'_images/'
- Folder = 'images_'+'['+File.rstrip('.xcf')+']/'
+ #Folder = '['+File.rstrip(Ext)+']'+'_images/'
+ Folder = 'images_'+'['+File.rstrip(Ext)+']/'
if bpy.data.is_dirty:
PathSaveRaw = Path+Folder
@@ -61,71 +57,151 @@
try: os.mkdir(PathSaveRaw)
except: pass
PathSaveRaw = bpy.path.relpath(PathSaveRaw)+'/'
+
+ PathRaw = Path
+ Path = Path.replace(' ', '\ ')
+ if Ext == '.xjt':
+ ExtSave = '.jpg'
+ #-------------------------------------------------
+ # EXTRACT XJT
+ import tarfile
- Path = Path.replace(' ', '\ ')
- #-------------------------------------------------
- # INFO
+ IMG = tarfile.open ('%s%s' % (PathRaw, File))
+ PRP = IMG.extractfile('PRP')
+
+ Members = IMG.getmembers()
+
+ for Member in Members:
+ Name = Member.name
+ if Name.startswith('l') and Name.endswith('.jpg') and not Name.startswith('la'): #only color JPGs for now!
+ IMG.extract(Name, path=PathSaveRaw)
+
+ #-------------------------------------------------
+ # INFO XJT
+ IMGs = []
+ for Line in PRP.readlines():
+ Line = str(Line)
+ if Line.startswith("b'GIMP_XJ_IMAGE"):
+ for Segment in Line.split():
+ if Segment.startswith('w/h:'):
+ ResX, ResY = map (int, Segment[4:].split(','))
+ print (ResX, ResY)
+ if Line.startswith("b'L") or Line.startswith("b'l"):
+ md = None
+ op = 1
+
+ for Segment in Line.split():
+ if Segment.startswith("b'"):
+ imageFile = 'l' + Segment[3:] + '.jpg'
+
+ # Get Widht and Height from images
+ data = open(PathSaveRaw+imageFile, "rb").read()
+
+ hexList = []
+ for ch in data:
+ byt = "%02X" % ch
+ hexList.append(byt)
+
+ for k in range(len(hexList)-1):
+ if hexList[k] == 'FF' and (hexList[k+1] == 'C0' or hexList[k+1] == 'C2'):
+ ow = int(hexList[k+7],16)*256 + int(hexList[k+8],16)
+ oh = int(hexList[k+5],16)*256 + int(hexList[k+6],16)
+
+ if Segment.startswith('md:'): # mode
+ md = Segment[3:]
+
+ elif Segment.startswith('op:'): # opacity
+ op = float(Segment[3:])*.01
+
+ elif Segment.startswith('o:'): # origin
+ o = Segment[2:].split(',')
+ ox, oy = int(o[0]), int(o[1])
+
+ elif Segment.startswith('n:'): # name
+ n = Segment[3:-4]
+ OpenBracket = n.find ('[')
+ CloseBracket = n.find (']')
+
+ if OpenBracket != -1 and CloseBracket != -1:
+ RenderLayer = n[OpenBracket+1:CloseBracket]
+ NameShort = n[:OpenBracket]
+
+ else:
+ RenderLayer = n
+ NameShort = n
+
+ IMGs.append({'LayerMode':md, 'LayerOpacity':op,\
+ 'LayerName':n, 'LayerNameShort':NameShort,\
+ 'RenderLayer':RenderLayer, 'LayerCoords':[ow, oh, ox, oy]})
+
+ print (IMGs)
- CMD = '%s %s%s' % (XCFInfo, Path, File)
-
- Info = os.popen(CMD)
-
- PNGs = []
-
- for Line in Info.readlines():
- if Line.startswith ('+'):
-
- Line = Line.split(' ', 4)
-
- RenderLayer = Line[4]
-
- OpenBracket = RenderLayer.find ('[')
- CloseBracket = RenderLayer.find (']')
-
- if OpenBracket != -1 and CloseBracket != -1:
- RenderLayer = RenderLayer[OpenBracket+1:CloseBracket]
- NameShort = Line[4][:OpenBracket]
- else:
- NameShort = Line[4].rstrip()
- if GroupUntagged:
- RenderLayer = '__Undefined__'
+ else: # Ext == '.xcf':
+ ExtSave = '.png'
+ #-------------------------------------------------
+ # CONFIG
+ XCFInfo = 'xcfinfo'
+ XCF2PNG = 'xcf2png'
+ #-------------------------------------------------
+ # INFO XCF
+
+ CMD = '%s %s%s' % (XCFInfo, Path, File)
+
+ Info = os.popen(CMD)
+
+ IMGs = []
+ for Line in Info.readlines():
+ if Line.startswith ('+'):
+
+ Line = Line.split(' ', 4)
+
+ RenderLayer = Line[4]
+
+ OpenBracket = RenderLayer.find ('[')
+ CloseBracket = RenderLayer.find (']')
+
+ if OpenBracket != -1 and CloseBracket != -1:
+ RenderLayer = RenderLayer[OpenBracket+1:CloseBracket]
+ NameShort = Line[4][:OpenBracket]
else:
- RenderLayer = NameShort
-
- LineThree = Line[3]
- Slash = LineThree.find('/')
- if Slash == -1:
- Mode = LineThree
- Opacity = 1
- else:
- Mode = LineThree[:Slash]
- Opacity = float(LineThree[Slash+1:LineThree.find('%')])*.01
-
- PNGs.append ({\
- 'ColorMode':Line[2],\
- 'LayerMode':Mode,\
- 'LayerOpacity':Opacity,\
- 'LayerName':Line[4].rstrip(),\
- 'LayerNameShort':NameShort,\
- 'LayerCoords':Line[1].replace('x', ' ').replace('+', ' +').replace('-', ' -').split(),\
- 'RenderLayer':RenderLayer,\
- })
- elif Line.startswith('Version'):
- ResX, ResY = map (int, Line.split()[2].split('x'))
+ NameShort = Line[4].rstrip()
+ if GroupUntagged:
+ RenderLayer = '__Undefined__'
+ else:
+ RenderLayer = NameShort
+
+ LineThree = Line[3]
+ Slash = LineThree.find('/')
+ if Slash == -1:
+ Mode = LineThree
+ Opacity = 1
+ else:
+ Mode = LineThree[:Slash]
+ Opacity = float(LineThree[Slash+1:LineThree.find('%')])*.01
+
+ IMGs.append ({\
+ 'LayerMode':Mode,\
+ 'LayerOpacity':Opacity,\
+ 'LayerName':Line[4].rstrip(),\
+ 'LayerNameShort':NameShort,\
+ 'LayerCoords':list(map(int, Line[1].replace('x', ' ').replace('+', ' +').replace('-', ' -').split())),\
+ 'RenderLayer':RenderLayer,\
+ })
+ elif Line.startswith('Version'):
+ ResX, ResY = map (int, Line.split()[2].split('x'))
+
+ #-------------------------------------------------
+ # EXTRACT XCF
+ if OpacityMode == 'BAKE':
+ Opacity = ''
+ else:
+ Opacity = ' --percent 100'
+ for Layer in IMGs:
+ CMD = '%s -C %s%s -o %s%s.png "%s"%s' %\
+ (XCF2PNG, Path, File, PathSave, Layer['LayerName'].replace(' ', '_'), Layer['LayerName'], Opacity)
+ os.system(CMD)
-
#-------------------------------------------------
- # EXTRACT
- if OpacityMode == 'BAKE':
- Opacity = ''
- else:
- Opacity = ' --percent 100'
- for Layer in PNGs:
- CMD = '%s -C %s%s -o %s%s.png "%s"%s' %\
- (XCF2PNG, Path, File, PathSave, Layer['LayerName'].replace(' ', '_'), Layer['LayerName'], Opacity)
- os.system(CMD)
-
- #-------------------------------------------------
Scene = bpy.context.scene
#-------------------------------------------------
# CAMERA
@@ -254,7 +330,7 @@
Img = bpy.data.images.new(NameShort)
Img.source = 'FILE'
if PremulAlpha: Img.use_premultiply = True
- Img.filepath = '%s%s.png' % (PathSaveRaw, Name)
+ Img.filepath = '%s%s%s' % (PathSaveRaw, Name, ExtSave)
Tex.image = Img
@@ -278,7 +354,7 @@
LayerFlags = {}
LayerList = []
- for Layer in PNGs:
+ for Layer in IMGs:
Make3DLayer(\
Layer['LayerName'].replace(' ', '_'),\
Layer['LayerNameShort'].replace(' ', '_'),\
@@ -332,35 +408,34 @@
Mode = LayerList[Offset][1] # has to go one step further
LayerOpacity = LayerList[Offset][2]
- if Mode != 'Normal':
+ if not Mode in ('Normal', '-1'):
Node = Tree.nodes.new('MIX_RGB')
if OpacityMode == 'COMPO': Node.inputs['Fac'].default_value[0] = LayerOpacity
else: Node.inputs['Fac'].default_value[0] = 1
Node.use_alpha = True
- if Mode == 'Addition': Node.blend_type = 'ADD'
- elif Mode == 'Subtract': Node.blend_type = 'SUBTRACT'
- elif Mode == 'Multiply': Node.blend_type = 'MULTIPLY'
- elif Mode == 'DarkenOnly': Node.blend_type = 'DARKEN'
- elif Mode == 'Dodge': Node.blend_type = 'DODGE'
- elif Mode == 'LightenOnly': Node.blend_type = 'LIGHTEN'
- elif Mode == 'Difference': Node.blend_type = 'DIFFERENCE'
- elif Mode == 'Divide': Node.blend_type = 'DIVIDE'
- elif Mode == 'Overlay': Node.blend_type = 'OVERLAY'
- elif Mode == 'Screen': Node.blend_type = 'SCREEN'
- elif Mode == 'Burn': Node.blend_type = 'BURN'
- elif Mode == 'Color': Node.blend_type = 'COLOR'
- elif Mode == 'Value': Node.blend_type = 'VALUE'
- elif Mode == 'Saturation': Node.blend_type = 'SATURATION'
- elif Mode == 'Hue': Node.blend_type = 'HUE'
- elif Mode == 'Softlight': Node.blend_type = 'SOFT_LIGHT'
+ if Mode in ('Addition', '7'): Node.blend_type = 'ADD'
+ elif Mode in ('Subtract', '8'): Node.blend_type = 'SUBTRACT'
+ elif Mode in ('Multiply', '3'): Node.blend_type = 'MULTIPLY'
+ elif Mode in ('DarkenOnly', '9'): Node.blend_type = 'DARKEN'
+ elif Mode in ('Dodge', '16'): Node.blend_type = 'DODGE'
+ elif Mode in ('LightenOnly', '10'): Node.blend_type = 'LIGHTEN'
+ elif Mode in ('Difference', '6'): Node.blend_type = 'DIFFERENCE'
+ elif Mode in ('Divide', '15'): Node.blend_type = 'DIVIDE'
+ elif Mode in ('Overlay', '5'): Node.blend_type = 'OVERLAY'
+ elif Mode in ('Screen', '4'): Node.blend_type = 'SCREEN'
+ elif Mode in ('Burn', '17'): Node.blend_type = 'BURN'
+ elif Mode in ('Color', '13'): Node.blend_type = 'COLOR'
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list