libvips / nip2

A spreadsheet-like GUI for libvips.
https://libvips.github.io/libvips/
GNU General Public License v2.0
360 stars 13 forks source link

Embedding new conversion (HSV<->RGB) in nip2-logics #51

Open Jondeen opened 9 years ago

Jondeen commented 9 years ago

Hi,

I'm trying to throw in the new HSV2sRGB & sRGB2HSV from libvips in the menus of nip2 ( see https://github.com/jcupitt/nip2/compare/master...Jondeen:add-hsv ) but struggling a bit with understanding the format of the _convert.def conversion paths...

Could you give me a pointer as to what is missing?

jcupitt commented 9 years ago

Hi, it's not easy, you need to use vips_call to call vips8 operations, then write a HSV2sRGB wrapper, then add it to the conversion table. I'll make you can example tomorrow.

Jondeen commented 9 years ago

Not to worry -- I'll figure it out. Your code makes interresting bed time read!

But I think if it requires a lot of work I won't go into it and rather do the debug au naturel.

jcupitt commented 9 years ago

Oh dear, I hope you fell asleep quickly.

You call vips8 operations from nip2 with vips_call. For examplem, load an image as A1 and try:

vips_call "sRGB2scRGB" [A1.value] []

The two lists are required and optional parameters. You need to give it a VipsImage*, hence the .value. It returns a list of the output values, so a single-element list containing a VipsImage*in this case.

nip2 is all set up for vips7 inside (this needs fixing), so the simplest thing is to make a vips7-like wrapper. Try adding this to _convert.def:

im_sRGB2HSV x = (vips_call "sRGB2HSV" [x] [])?0;

Now add that to _colour_conversion_table. You'll need a set of things like:

    [YXY, HSV, im_sRGB2HSV @ im_XYZ2sRGB @ im_Yxy2XYZ @ im_clip2f],

@ is function composition, so you read that right to left. You'll need to add the code for HSV as well, is it 29? I forget.

This nip2 stuff is all out of date now, of course. The colourspace conversion has been pushed down into vips as vips_colourspace(), so all this nip2 stuff can go. I'll remove it for nip3.

Finally, add HSV to Image_type and add a menu item for the conversion to Colour_convert_item.

Jondeen commented 9 years ago

Oh ok.

Was just a matter of putting this in then im_sRGB2HSV x = (vips_call "sRGB2HSV" [x] [])?0;! You said it was not easy :D

Thanks.

What language are the .def-files written in by the way?

Also, do you have any nifty commands for efficiently repackaging nip after making small changes in one or two of the modules? Or do I have to rebuild the whole shebang?

**BTW: Updates to the .def-files I do in-place @ install path on win-box, which seems to work fine.

jcupitt commented 9 years ago

If you do Toolkits / Edit to get the Program window, then click File / Reload All Toolkits, it'll scan the path and reload all the .def files. You can edit .def files in the program window too, of course. There's a simple debugger too.

The language is one I made up, it's a dynamically-typed Haskell with classes.

You can save .def files to your startup folder (File / Save Toolkit As) and they'll override the system ones.

Jondeen commented 9 years ago

Nifty!

I do get some sudden deaths upon save and HSV->sRGB, so think some bugtracking is needed. Where in the code is the colourspace ID set? When running the functional sRGB->HSV I get an "unknown colourspace".

The language is one I made up

OK, if I at any point in the future get people to use one of my made up languages I can die a peaceful death however which way it turns out to be.

jcupitt commented 9 years ago

Did you add HSV to Image_type? https://github.com/jcupitt/nip2/blob/master/share/nip2/start/_types.def#L801 it's the nip2 analogue of VipsInterpretation.

Jondeen commented 9 years ago

Yes:

/* Type field.
 */
Image_type = class {
    MULTIBAND = 0;
    B_W = 1;
    HISTOGRAM = 10;
    XYZ = 12;
    LAB = 13;
    CMYK = 15;
    LABQ = 16;
    RGB = 17;
    UCS = 18;
    LCH = 19;
    LABS = 21;
    sRGB = 22;
    YXY = 23;
    FOURIER = 24;
    RGB16 = 25;
    GREY16 = 26;
    ARRAY = 27;
    HSV = 29;

    /* Table to get names <-> numbers.
     */
    type_names = Enum [
        $MULTIBAND => MULTIBAND,
        $B_W => B_W,
        $HISTOGRAM => HISTOGRAM,
        $XYZ => XYZ,
        $LAB => LAB,
        $CMYK => CMYK,
        $LABQ => LABQ,
        $RGB => RGB,
        $UCS => UCS,
        $LCH => LCH,
        $LABS => LABS,
        $sRGB => sRGB,
        $YXY => YXY,
        $FOURIER => FOURIER,
        $RGB16 => RGB16,
        $GREY16 => GREY16,
        $ARRAY => ARRAY,
        $HSV => $HSV
    ];

    /* Table relating nip's colour space names and VIPS's Type numbers.
     * Options generated from this, so match the order to the order in the
     * Colour menu.
     */
    colour_spaces = Enum [
        $sRGB => sRGB,
        $Lab => LAB,
        $LCh => LCH,
        $XYZ => XYZ,
        $Yxy => YXY,
        $UCS => UCS
    ];

    /* A slightly larger table ... the types of colorimetric image we can
     * have. Add mono, and the S and Q forms of LAB.
     */
    image_colour_spaces = Enum [
        $Mono => B_W,
        $sRGB => sRGB,
        $RGB16 => RGB16,
        $GREY16 => GREY16,
        $Lab => LAB,
        $LabQ => LABQ,
        $LabS => LABS,
        $LCh => LCH,
        $XYZ => XYZ,
        $Yxy => YXY,
        $UCS => UCS,
        $HSV => HSV
    ];
}
jcupitt commented 9 years ago

The text at the bottom of thumbnails and in the image display window comes from here:

https://github.com/Jondeen/nip2/blob/master/src/util.c#L1241

I guess that needs HSV as well. Again, that's a vips7 problem, vips8 has a proper system for handling this. nip2 needs to become nip3 :(

Jondeen commented 9 years ago

Ah ok. No worries, I'll fiddle about.

I'm assuming nip2->nip3 is the equivalent of vips7->vips8?

jcupitt commented 9 years ago

Yes, move nip2 to the gtk3 toolkit and vips8 library, plus some cleaning up. There's a nipp3 branch, but it doesn't work yet :( it's going to take ages.