| 208 | /************************************************************************/ |
| 209 | |
| 210 | int msAddColorGD(mapObj *map, gdImagePtr img, int cmt, int r, int g, int b) |
| 211 | { |
| 212 | int c; |
| 213 | int ct = -1; |
| 214 | int op = -1; |
| 215 | long rd, gd, bd, dist; |
| 216 | long mindist = 3*255*255; /* init to max poss dist */ |
| 217 | |
| 218 | if( gdImageTrueColor( img ) ) |
| 219 | return gdTrueColor( r, g, b ); |
| 220 | |
| 221 | /* |
| 222 | ** We want to avoid using a color that matches a transparent background |
| 223 | ** color exactly. If this is the case, we will permute the value slightly. |
| 224 | ** When perterbing greyscale images we try to keep them greyscale, otherwise |
| 225 | ** we just perterb the red component. |
| 226 | */ |
| 227 | if( map->outputformat && map->outputformat->transparent |
| 228 | && map->imagecolor.red == r |
| 229 | && map->imagecolor.green == g |
| 230 | && map->imagecolor.blue == b ) |
| 231 | { |
| 232 | if( r == 0 && g == 0 && b == 0 ) |
| 233 | { |
| 234 | r = g = b = 1; |
| 235 | } |
| 236 | else if( r == g && r == b ) |
| 237 | { |
| 238 | r = g = b = r-1; |
| 239 | } |
| 240 | else if( r == 0 ) |
| 241 | { |
| 242 | r = 1; |
| 243 | } |
| 244 | else |
| 245 | { |
| 246 | r = r-1; |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | /* |
| 251 | ** Find the nearest color in the color table. If we get an exact match |
| 252 | ** return it right away. |
| 253 | */ |
| 254 | for (c = 0; c < img->colorsTotal; c++) { |
| 255 | |
| 256 | if (img->open[c]) { |
| 257 | op = c; /* Save open slot */ |
| 258 | continue; /* Color not in use */ |
| 259 | } |
| 260 | |
| 261 | /* don't try to use the transparent color */ |
| 262 | if (map->outputformat && map->outputformat->transparent |
| 263 | && img->red [c] == map->imagecolor.red |
| 264 | && img->green[c] == map->imagecolor.green |
| 265 | && img->blue [c] == map->imagecolor.blue ) |
| 266 | continue; |
| 267 |
no outgoing calls
no test coverage detected