map_hsv Tcl_Obj* imageObj Tcl_Obj* hueMapImageObj Tcl_Obj* satMapImageObj Tcl_Obj* valMapImageObj /* * This operation is a generalized per-pixel transformation, mapping * pixel values to other pixel values in a completely arbitrary way. * Inversion, partial inversion, histogram equalization, etc. all are * possible through this. * * Important: For the sake of convenience the map is not provided as a * (Tcl) list (of values), or array, but as an _image_ itself, a 256x1 * (WxH) grey8. We will have constructors for such images. * * The same approach will be used by the conditional mappers where the * transformation of one channel in a multi-channel image will be * controlled by data in a second channel, this can be represented as * a 256x256 grey8 image, each row the map to be used for one of the * possible controlling values. */ crimp_image* result; crimp_image* image; crimp_image* hueMap; crimp_image* satMap; crimp_image* valMap; int x, y; crimp_input (imageObj, image, hsv); crimp_input (hueMapImageObj, hueMap, grey8); crimp_input (satMapImageObj, satMap, grey8); crimp_input (valMapImageObj, valMap, grey8); if (!crimp_require_dim (hueMap, 256, 1)) { Tcl_SetResult(interp, "bad image dimension for hue map, expected 256x1", TCL_STATIC); return TCL_ERROR; } if (!crimp_require_dim (satMap, 256, 1)) { Tcl_SetResult(interp, "bad image dimension for saturation map, expected 256x1", TCL_STATIC); return TCL_ERROR; } if (!crimp_require_dim (valMap, 256, 1)) { Tcl_SetResult(interp, "bad image dimension for value map, expected 256x1", TCL_STATIC); return TCL_ERROR; } result = crimp_new_like (image); for (y = 0; y < result->h; y++) { for (x = 0; x < result->w; x++) { /* * Run the pixel value of the input image through the map to * produce the value for the output. */ H (result, x, y) = GREY8 (hueMap, H (image, x, y), 0); S (result, x, y) = GREY8 (satMap, S (image, x, y), 0); V (result, x, y) = GREY8 (valMap, V (image, x, y), 0); } } Tcl_SetObjResult(interp, crimp_new_image_obj (result)); return TCL_OK; /* vim: set sts=4 sw=4 tw=80 et ft=c: */ /* * Local Variables: * mode: c * c-basic-offset: 4 * fill-column: 78 * End: */