@@ -175,12 +175,13 @@ float4 pp_parse_float(const char * str);
175175int pp_parse_int (char * str );
176176Oid pp_parse_cstype (const ColorspaceType t );
177177void pp_parse_color (const char * str , PPColor * color );
178- // image (GraphicsMagick) building and destroying
178+ // To deal easily with GraphicsMagick objects
179179Image * gm_image_from_lob (Oid loid );
180180Image * gm_image_from_bytea (bytea * imgdata );
181181char * gm_image_getattr (Image * img , const char * attr );
182182void * gm_image_to_blob (Image * timg , size_t * blen , ExceptionInfo * ex );
183183void gm_image_destroy (Image * );
184+ PixelPacket * gm_ppacket_from_color (const PPColor * color );
184185// large objects processing
185186void * lo_readblob (Oid loid , int * len );
186187int lo_size (int32 fd );
@@ -470,6 +471,7 @@ PG_FUNCTION_INFO_V1(image_draw_text);
470471Datum image_draw_text (PG_FUNCTION_ARGS )
471472{
472473 PPImage * img , * res ;
474+ PPColor * color = NULL ;
473475 Image * gimg ;
474476 DrawContext ctx ;
475477 VarChar * label , * f_family = NULL ;
@@ -481,6 +483,9 @@ Datum image_draw_text(PG_FUNCTION_ARGS)
481483 img = PG_GETARG_IMAGE (0 );
482484 label = PG_GETARG_VARCHAR_P (1 );
483485 switch (na ) {
486+ case 7 : //color
487+ color = (PPColor * ) PG_GETARG_POINTER (6 );
488+ /* fallthrough */
484489 case 6 : //font family and size
485490 f_family = PG_GETARG_VARCHAR_P (4 );
486491 f_size = PG_GETARG_INT32 (5 );
@@ -492,10 +497,11 @@ Datum image_draw_text(PG_FUNCTION_ARGS)
492497 gimg = gm_image_from_bytea (& img -> imgdata );
493498
494499 ctx = DrawAllocateContext ((DrawInfo * )NULL , gimg );
495- if (na = =6 ) {
500+ if (na > =6 ) {
496501 str = pp_varchar2str (f_family );
497502 DrawSetFontFamily (ctx , str );
498503 DrawSetFontSize (ctx , f_size );
504+ if (na >=7 ) DrawSetFillColor (ctx , gm_ppacket_from_color (color ));
499505 }
500506 str = pp_varchar2str (label );
501507 DrawAnnotation (ctx , x , y , (unsigned char * ) str );
@@ -735,6 +741,19 @@ char * gm_image_getattr(Image * img, const char * attr)
735741 return pstrdup (attrs -> value );
736742}
737743
744+ PixelPacket * gm_ppacket_from_color (const PPColor * color )
745+ {
746+ PixelPacket * pp = (PixelPacket * )palloc (sizeof (PixelPacket ));
747+ unsigned int data = ntohl (color -> cd );
748+
749+ if ((color -> cs == CS_RGB .oid ) || (color -> cs == CS_sRGB .oid )) data = (data << 8 );
750+ pp -> red = (data >> 24 ) & 0xFF ;
751+ pp -> green = (data >> 16 ) & 0xFF ;
752+ pp -> blue = (data >> 8 ) & 0xFF ;
753+ pp -> opacity = data & 0xFF ;
754+ return pp ;
755+ }
756+
738757int pp_substr2int (char * str , int off , int len )
739758{
740759 str [off + len ] = 0 ;
0 commit comments