From 036334437905d151163968845e7bc9962e26c3fb Mon Sep 17 00:00:00 2001 From: blastframe Date: Sun, 12 Feb 2023 10:08:44 -0800 Subject: [PATCH 1/2] Fix 104660: Import .ase files with swatch groups The previous version of Import Palettes threw a KeyError when importing .ase files that had swatch groups in them. This patch accounts for these. --- io_import_palette/import_ase.py | 60 ++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 24 deletions(-) diff --git a/io_import_palette/import_ase.py b/io_import_palette/import_ase.py index 8f9b55731..460624e22 100644 --- a/io_import_palette/import_ase.py +++ b/io_import_palette/import_ase.py @@ -99,6 +99,31 @@ def parse(filename): return [c for c in parse_chunk(data)] +def create_color(data): + + valid = False + color = [0, 0, 0] + val = data['values'] + + if data['mode'] == 'RGB': + valid = True + color[0] = val[0] + color[1] = val[1] + color[2] = val[2] + elif data['mode'] == 'Gray': + valid = True + color[0] = val[0] + color[1] = val[0] + color[2] = val[0] + elif data['mode'] == 'CMYK': + valid = True + color[0] = (1.0 - val[0]) * (1.0 - val[3]) + color[1] = (1.0 - val[1]) * (1.0 - val[3]) + color[2] = (1.0 - val[2]) * (1.0 - val[3]) + + if valid: + return color + def load(context, filepath): output = parse(filepath) @@ -107,33 +132,20 @@ def load(context, filepath): pal = None for elm in output: - valid = False - data = elm['data'] - color = [0, 0, 0] - val = data['values'] + colors = [] - if data['mode'] == 'RGB': - valid = True - color[0] = val[0] - color[1] = val[1] - color[2] = val[2] - elif data['mode'] == 'Gray': - valid = True - color[0] = val[0] - color[1] = val[0] - color[2] = val[0] - elif data['mode'] == 'CMYK': - valid = True - color[0] = (1.0 - val[0]) * (1.0 - val[3]) - color[1] = (1.0 - val[1]) * (1.0 - val[3]) - color[2] = (1.0 - val[2]) * (1.0 - val[3]) + if "data" in elm: + colors.append(create_color(elm['data'])) - # Create palette color - if valid: - # Create Palette - if pal is None: - pal = bpy.data.palettes.new(name=filename) + if "swatches" in elm: + for swatch in elm['swatches']: + colors.append(create_color(swatch["data"])) + # Create Palette + if pal is None: + pal = bpy.data.palettes.new(name=filename) + + for color in colors: # Create Color col = pal.colors.new() col.color[0] = color[0] -- 2.30.2 From c60eeb07f5abb434292de0dce3fc5f7429acaa7f Mon Sep 17 00:00:00 2001 From: blastframe Date: Sun, 12 Feb 2023 12:26:17 -0800 Subject: [PATCH 2/2] Added credit and updated Add-on version --- io_import_palette/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/io_import_palette/__init__.py b/io_import_palette/__init__.py index d3531efaa..ab71272d8 100644 --- a/io_import_palette/__init__.py +++ b/io_import_palette/__init__.py @@ -2,8 +2,8 @@ bl_info = { "name": "Import Palettes", - "author": "Antonio Vazquez", - "version": (1, 0, 0), + "author": "Antonio Vazquez, Kevin C. Burke (@blastframe)", + "version": (1, 0, 1), "blender": (2, 81, 6), "location": "File > Import", "description": "Import Palettes", -- 2.30.2