PDF color conversion: How do I convert ColorSpaces on Shading objects?

Q: I am using the PDFTron SDK to do some edits to my PDF files. At
the moment I am mainly focusing on colorspace conversion. I am
relying on the code sample from the ElementEditTest project to loop
through all of the elements and convert them from one colorspace to
anothers. For example, I'll receive a PDF, and want to convert it
from CMYK colorspace to RGB, so I'll loop through all the text
elements and do the conversions. This is working as I get the proper
resultant colorspace in my output file. One problem I am having is
converting Shading elements. Firstly, can is there away to edit the
function dictionaries that make up this shade in order to change the
C0 and C1 values? In particular I have a Axial circle shade that was
created using C/M/Y/K channels. It is a gradient from one channel to
the next, so the stitching function has 3 functions of it's own, that
draw the 3 different portions. I need to be able to change the color
values of these. I would like to be able to edit it inline as I loop
through the elements in the file and do my other conversions. Is
there any way to accomplish this?
Thanks for any advice! I am eagerly looking forward to your reply.
-------------------------

A: Basically you would need to read the existing shading object
(pdftron.PDF.Shading) access its Function (pdftron.PDF.Function) and
all the parameters. Then you would need to create a new shading object
(e.g. see PatternTest sample project for how to create a new shading
object from scratch). The new shading object may have a different
Function.

Thinking about this further, I guess you could simply replace some
parameters in the existing shading object (e.g. replace Function with
a Function array, modify the color space, range entries, etc).

In case of the axial shading the code may look as follows:

switch(shading.GetType()) {
case Shading::e_axial_shading:
    AxialShadingConvert(shading, "DeviceRGB");
    break;
case Shading::e_radial_shading:
     RadialShadingConvert(shading, ...);
     break;
case Shading::e_function_shading:
     ...
    break;
    ...
}

void AxialShadingConvert(Shading sh, string cs) {
    Obj sh_obj = sh.GetSDFObj();
    Obj funct_obj = sh_obj.FindObj("Function");
    Obj new_funct = ConvertFunction(funct_obj,
sh.GetBaseColorSpace());
    sh_obj.Put("Function", new_funct);
    sh_obj.PutName("ColorSpace", cs.c_str());
}

Obj FunctionConvert(Obj f, ColorSpace cs) {
    Function fun = Function(f);
    switch(fuc.GetType()) {
  case Function::e_sampled:
     return ConvertType0Funct(fun, cs);
  case Function::e_exponential:
     return ConvertType2Funct(fun, cs);
             ....
     }
}

....

Please keep in mind that full implementation would requires in-depth
understanding of PDF shading objects and the implementation is
probably trickier than it seems. For more complex shadings (e.g.
Gouraud, Tensor) you may need to re-write the shading object. For
these shading types pdftron.Filters.BitStreamReader/Writer would be
useful.

In case you would require assistance with the implementation we could
help you as part of custom engineering project or a consulting service
(http://www.pdftron.com/support/professionalservices.html).