Skip to content

Commit

Permalink
Auto-detect the correct srgb and linear/non-color names on Blender wi…
Browse files Browse the repository at this point in the history
…th custom color profiles. (Fix #163)
  • Loading branch information
ucupumar committed Sep 20, 2024
1 parent 761f9cd commit 1bc81ee
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
3 changes: 3 additions & 0 deletions Root.py
Original file line number Diff line number Diff line change
Expand Up @@ -3753,6 +3753,9 @@ class YPaintWMProps(bpy.types.PropertyGroup):

edit_image_editor_area_index : IntProperty(default=-1)

custom_srgb_name : StringProperty(default='')
custom_noncolor_name : StringProperty(default='')

class YPaintSceneProps(bpy.types.PropertyGroup):
ori_display_device : StringProperty(default='')
ori_view_transform : StringProperty(default='')
Expand Down
28 changes: 26 additions & 2 deletions common.py
Original file line number Diff line number Diff line change
Expand Up @@ -736,19 +736,43 @@ def get_bpytypes():
def get_srgb_name():
names = bpy.types.Image.bl_rna.properties['colorspace_settings'].fixed_type.properties['name'].enum_items.keys()
if 'sRGB' not in names:

# Try 'srgb' prefix
for name in names:
if name.lower().startswith('srgb'):
return name
return names[0]

# Check srgb name by creating new 8-bit image
ypprops = bpy.context.window_manager.ypprops

if ypprops.custom_srgb_name == '':
temp_image = bpy.data.images.new('temmmmp', width=1, height=1, alpha=False, float_buffer=False)
ypprops.custom_srgb_name = temp_image.colorspace_settings.name
remove_datablock(bpy.data.images, temp_image)

return ypprops.custom_srgb_name

return 'sRGB'

def get_noncolor_name():
names = bpy.types.Image.bl_rna.properties['colorspace_settings'].fixed_type.properties['name'].enum_items.keys()
if 'Non-Color' not in names:

# Try 'raw' name
for name in names:
if name.lower() == 'raw':
return name
return names[0]

# Check non-color name by creating new float image
ypprops = bpy.context.window_manager.ypprops

if ypprops.custom_noncolor_name == '':
temp_image = bpy.data.images.new('temmmmp', width=1, height=1, alpha=False, float_buffer=True)
ypprops.custom_noncolor_name = temp_image.colorspace_settings.name
remove_datablock(bpy.data.images, temp_image)

return ypprops.custom_noncolor_name

return 'Non-Color'

def remove_datablock(blocks, block, user=None, user_prop=''):
Expand Down

0 comments on commit 1bc81ee

Please sign in to comment.