how to implement colortone with magick++ (code)

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
qztt
Posts: 1
Joined: 2012-04-25T02:35:57-07:00
Authentication code: 13

how to implement colortone with magick++ (code)

Post by qztt »

hi ~
i want implement colortone method .
and test command with command line tool . is ok!
but my code is faild. help me plz !!

convert source.jpg ( -clone 0 -fill "#330000" -colorize 100% )
( -clone 0 -colorspace gray -negate ) -compose blend -define compose:args=100,0
-composite dest.jpg


my code

Code: Select all


void ImageFilterHelper::colortone( Magick::Image * image_obj , const Magick::Color & color , int level, int type )
{
    if( !image_obj )
        return ;

    MagickCore::ExceptionInfo exceptinfo;
    MagickCore::Image * clone_1 = MagickCore::CloneImage( image_obj->image() , 0 , 0 , MagickCore::MagickTrue ,  &exceptinfo );
    MagickCore::Image * clone_2 = MagickCore::CloneImage( image_obj->image() , 0 , 0 , MagickCore::MagickTrue ,  &exceptinfo );

    Magick::Image  image_bk( clone_1 );
    Magick::Image  image_bk2( clone_2 );

    image_bk.fillColor( color );
    image_bk.colorize( 100 ,color );

    image_bk2.quantizeColorSpace( GRAYColorspace );
    image_bk2.quantize( );

    /*
    MagickCore::Image * image_core = image_bk2.image();
    TransformImageColorspace( image_core , MagickCore::GRAYColorspace);
    */

    if( type == 0 )
    {
        image_bk2.negate();
    }

    char define_args[256];
    _snprintf( define_args , sizeof(define_args) , "%d,%d" ,  level , 100 - level ); 

    image_obj->compose( BlendCompositeOp );
    image_bk.compose( BlendCompositeOp );
    image_bk2.compose( BlendCompositeOp );


    image_obj->defineValue("compose" , "args" , define_args );
    image_bk.defineValue("compose" , "args" , define_args );
    image_bk2.defineValue("compose" , "args" , define_args );

    image_obj->write("debug_result.jpg");
}

Post Reply