Remove deprecated 2D_/3D_ prefix
[blender-addons.git] / io_import_palette / import_krita.py
blob9992082bca2762deb1085dea73268b20461363ef
1 # SPDX-License-Identifier: GPL-2.0-or-later
4 """
5 This script imports a Krita/Gimp Palette to Blender.
7 Usage:
8 Run this script from "File->Import" menu and then load the desired KPL file.
9 """
11 import bpy
12 import os
13 import struct
16 def load(context, filepath):
17 (path, filename) = os.path.split(filepath)
19 pal = None
20 valid = False
21 finput = open(filepath)
22 line = finput.readline()
24 while line:
25 if valid:
26 # Create Palette
27 if pal is None:
28 pal = bpy.data.palettes.new(name=filename)
30 # Create Color
31 values = line.split()
32 col = [0, 0, 0]
33 col[0] = int(values[0]) / 255.0
34 col[1] = int(values[1]) / 255.0
35 col[2] = int(values[2]) / 255.0
37 palcol = pal.colors.new()
38 palcol.color[0] = col[0]
39 palcol.color[1] = col[1]
40 palcol.color[2] = col[2]
42 if line[0] == '#':
43 valid = True
45 line = finput.readline()
47 finput.close()
49 return {'FINISHED'}