2

I've been using Boost.GIL to perform some basic image processing routine. In Boost.GIL, colorspace conversion between pixels of different type is realized by template specialization of a generic convert_pixel( ) function. However, I would love to override these implementation with something based on LCMS, for instance.

Is there any way to override the specialization of the template so that whichever internal call to convert_pixel() will use the newly LCMS-based convert_pixel()?

Final aswer

digging into the GIL design manual (much more interesting than the tutorial), I've found how Adobe suggest to solve this problem. For those we are interested, this link provides the answer: http://www.boost.org/doc/libs/1_49_0/libs/gil/doc/html/gildesignguide.html#NewColorConversionDG

davideanastasia
  • 366
  • 1
  • 13

2 Answers2

0

I'm not familiar with GIL, and I found only a similar function in the documentation. However, it may be not needed to answer the question.

Hijacking the original calls, you should be able to override the conversion. Function precedence should come to save the day: normal functions are always preferred to template ones. Assuming the original template specialization is

template<> 
GIL_FORCEINLINE void boost::gil::copy_and_convert_pixels (const V1 &src, const V2 &dst, CC cc) { original_code; }

You can override this defining your custom nontemplate function

GIL_FORCEINLINE void boost::gil::copy_and_convert_pixels (const V1 &src, const V2 &dst, CC cc) { overridden_code; }

You should take special care to define the function into the same namespace with the same name, and also include it before the first call is made.

Zólyomi István
  • 2,401
  • 17
  • 28
  • Unfortunately, while in general your idea works well, in this particular case it doesn't. In fact color conversion relies on the class default_color_converter defined in boost/gil/color_convert.hpp. The "trick" is there, but I have to figure it out how to replace it yet. It's good to have new challenges though. – davideanastasia May 19 '12 at 16:15
0

FWIW, see this answer for an example of overriding boost::gil::color_convert for the purposes of extending boost::gil::copy_and_convert_pixels behaviour with a conversion not already provided by GIL.

I think you'll have problems trying to replace existing conversions defined in GIL's color_convert.hpp though; probably the route you want/need to go down is defining a new color base c.f rgb_t, cmyk_t (e.g an lcms_t ?) and then defining things like default_color_converter_impl<rgb_t,lcms_t> to interoperate with it.

Community
  • 1
  • 1
timday
  • 24,582
  • 12
  • 83
  • 135