Agamnentzar / ag-psd

Javascript library for reading and writing PSD files
Other
501 stars 66 forks source link

redFloat, greenFloat, blueFloat support in DescriptorColor / parseColor #131

Open bhorsting opened 1 year ago

bhorsting commented 1 year ago

For the following file:

src.psd.zip ag-psd does not populate the effects object because parseColor fails. It gets an object of type {redFloat: 0.5, greenFloat: 0.5, blueFloat: 0.5}

I can fix this by changing parseColor to

export function parseColor(color: DescriptorColor): Color {
    if ('H   ' in color) {
        return { h: parsePercentOrAngle(color['H   ']), s: color.Strt, b: color.Brgh };
    } else if ('Rd  ' in color) {
        return { r: color['Rd  '], g: color['Grn '], b: color['Bl  '] };
    } else if ('Cyn ' in color) {
        return { c: color['Cyn '], m: color.Mgnt, y: color['Ylw '], k: color.Blck };
    } else if ('Gry ' in color) {
        return { k: color['Gry '] };
    } else if ('Lmnc' in color) {
        return {l: color.Lmnc, a: color['A   '], b: color['B   ']};
    } else if ('redFloat' in color) {
        return { r: color['redFloat'] * 255, g: color['greenFloat'] * 255, b: color['blueFloat'] * 255 };
    } else {
        throw new Error('Unsupported color descriptor');
    }
}

but this assumes the PSD is 8 bits per channel. Did you ever encounter this issue? It's new to me. I can make a PR taking bits per channel into account, just wanted to check if you knew anything about this issue.

Agamnentzar commented 1 year ago

I never encountered PSD file with {redFloat: 0.5, greenFloat: 0.5, blueFloat: 0.5} color object, I'll check it out.

Agamnentzar commented 1 year ago

Just released version 15.1.0 with fix for the color, I added new type for the float colors:

export type FRGB = { fr: number; fg: number; fb: number; }; // values from 0 to 1 (can be above 1)
bhorsting commented 1 year ago

amazing! thanks so much!

snechaev commented 6 months ago

Just for the history- it's possible to have negative values there

          KEY: Clr   TYPE: DescValueType.OBJECTTYPE  VALUE_T:RGBC  VALUE: [ActionDescriptor]
            KEY: __COUNT__  TYPE: null  VALUE: 3
            KEY: redFloat  TYPE: DescValueType.DOUBLETYPE  VALUE: 0.24089959263802
            KEY: greenFloat  TYPE: DescValueType.DOUBLETYPE  VALUE: 0.04970443621278
            KEY: blueFloat  TYPE: DescValueType.DOUBLETYPE  VALUE: -0.11133494228125