134
152
/* and then dumped into the SWF or the PDF file. */
135
153
/* -------------------------------------------------------------------- */
137
/* if( MS_RENDERER_GD(map->outputformat) ) */
138
if( MS_RENDERER_GD(image->format) )
140
gdImg = image->img.gd;
142
truecolor = gdImageTrueColor( gdImg );
143
if( CSLFetchNameValue( layer->processing,
144
"COLOR_MATCH_THRESHOLD" ) != NULL )
146
cmt = MAX(0,atoi(CSLFetchNameValue( layer->processing,
147
"COLOR_MATCH_THRESHOLD" )));
151
else if( MS_RENDERER_AGG(image->format) )
153
gdImg = image->img.gd;
155
truecolor = gdImageTrueColor( gdImg );
156
if( CSLFetchNameValue( layer->processing,
157
"COLOR_MATCH_THRESHOLD" ) != NULL )
159
cmt = MAX(0,atoi(CSLFetchNameValue( layer->processing,
160
"COLOR_MATCH_THRESHOLD" )));
164
src_xsize = GDALGetRasterXSize( hDS );
165
src_ysize = GDALGetRasterYSize( hDS );
168
* If the RAW_WINDOW attribute is set, use that to establish what to
169
* load. This is normally just set by the mapresample.c module to avoid
170
* problems with rotated maps.
173
if( CSLFetchNameValue( layer->processing, "RAW_WINDOW" ) != NULL )
177
CSLFetchNameValue( layer->processing, "RAW_WINDOW" ) );
180
msDebug( "msDrawGDAL(%s): using RAW_WINDOW=%s, dst=0,0,%d,%d\n",
182
CSLFetchNameValue( layer->processing, "RAW_WINDOW" ),
183
image->width, image->height );
185
if( CSLCount(papszTokens) != 4 )
187
CSLDestroy( papszTokens );
188
msSetError( MS_IMGERR, "RAW_WINDOW PROCESSING directive corrupt.",
193
src_xoff = atoi(papszTokens[0]);
194
src_yoff = atoi(papszTokens[1]);
195
src_xsize = atoi(papszTokens[2]);
196
src_ysize = atoi(papszTokens[3]);
200
dst_xsize = image->width;
201
dst_ysize = image->height;
203
CSLDestroy( papszTokens );
207
* Compute the georeferenced window of overlap, and do nothing if there
208
* is no overlap between the map extents, and the file we are operating on.
210
else if( layer->transform )
212
int dst_lrx, dst_lry;
214
msGetGDALGeoTransform( hDS, map, layer, adfGeoTransform );
215
InvGeoTransform( adfGeoTransform, adfInvGeoTransform );
217
mapRect = map->extent;
219
mapRect.minx -= map->cellsize*0.5;
220
mapRect.maxx += map->cellsize*0.5;
221
mapRect.miny -= map->cellsize*0.5;
222
mapRect.maxy += map->cellsize*0.5;
226
if( copyRect.minx < GEO_TRANS(adfGeoTransform,0,src_ysize) )
227
copyRect.minx = GEO_TRANS(adfGeoTransform,0,src_ysize);
228
if( copyRect.maxx > GEO_TRANS(adfGeoTransform,src_xsize,0) )
229
copyRect.maxx = GEO_TRANS(adfGeoTransform,src_xsize,0);
231
if( copyRect.miny < GEO_TRANS(adfGeoTransform+3,0,src_ysize) )
232
copyRect.miny = GEO_TRANS(adfGeoTransform+3,0,src_ysize);
233
if( copyRect.maxy > GEO_TRANS(adfGeoTransform+3,src_xsize,0) )
234
copyRect.maxy = GEO_TRANS(adfGeoTransform+3,src_xsize,0);
236
if( copyRect.minx >= copyRect.maxx || copyRect.miny >= copyRect.maxy )
240
* Copy the source and destination raster coordinates.
242
llx = GEO_TRANS(adfInvGeoTransform+0,copyRect.minx,copyRect.miny);
243
lly = GEO_TRANS(adfInvGeoTransform+3,copyRect.minx,copyRect.miny);
244
urx = GEO_TRANS(adfInvGeoTransform+0,copyRect.maxx,copyRect.maxy);
245
ury = GEO_TRANS(adfInvGeoTransform+3,copyRect.maxx,copyRect.maxy);
247
src_xoff = MAX(0,(int) floor(llx+0.5));
248
src_yoff = MAX(0,(int) floor(ury+0.5));
249
src_xsize = MIN(MAX(0,(int) (urx - llx + 0.5)),
250
GDALGetRasterXSize(hDS) - src_xoff);
251
src_ysize = MIN(MAX(0,(int) (lly - ury + 0.5)),
252
GDALGetRasterYSize(hDS) - src_yoff);
254
if( src_xsize == 0 || src_ysize == 0 )
257
msDebug( "msDrawGDAL(): no apparent overlap between map view and this window(1).\n" );
261
dst_xoff = (int) ((copyRect.minx - mapRect.minx) / map->cellsize);
262
dst_yoff = (int) ((mapRect.maxy - copyRect.maxy) / map->cellsize);
264
dst_lrx = (int) ((copyRect.maxx - mapRect.minx) / map->cellsize + 0.5);
265
dst_lry = (int) ((mapRect.maxy - copyRect.miny) / map->cellsize + 0.5);
266
dst_lrx = MAX(0,MIN(image->width,dst_lrx));
267
dst_lry = MAX(0,MIN(image->height,dst_lry));
269
dst_xsize = MAX(0,MIN(image->width,dst_lrx - dst_xoff));
270
dst_ysize = MAX(0,MIN(image->height,dst_lry - dst_yoff));
272
if( dst_xsize == 0 || dst_ysize == 0 )
275
msDebug( "msDrawGDAL(): no apparent overlap between map view and this window(2).\n" );
280
msDebug( "msDrawGDAL(): src=%d,%d,%d,%d, dst=%d,%d,%d,%d\n",
281
src_xoff, src_yoff, src_xsize, src_ysize,
282
dst_xoff, dst_yoff, dst_xsize, dst_ysize );
156
src_xsize = GDALGetRasterXSize( hDS );
157
src_ysize = GDALGetRasterYSize( hDS );
160
* If the RAW_WINDOW attribute is set, use that to establish what to
161
* load. This is normally just set by the mapresample.c module to avoid
162
* problems with rotated maps.
165
if( CSLFetchNameValue( layer->processing, "RAW_WINDOW" ) != NULL )
169
CSLFetchNameValue( layer->processing, "RAW_WINDOW" ) );
172
msDebug( "msDrawGDAL(%s): using RAW_WINDOW=%s, dst=0,0,%d,%d\n",
174
CSLFetchNameValue( layer->processing, "RAW_WINDOW" ),
175
image->width, image->height );
177
if( CSLCount(papszTokens) != 4 )
179
CSLDestroy( papszTokens );
180
msSetError( MS_IMGERR, "RAW_WINDOW PROCESSING directive corrupt.",
185
src_xoff = atoi(papszTokens[0]);
186
src_yoff = atoi(papszTokens[1]);
187
src_xsize = atoi(papszTokens[2]);
188
src_ysize = atoi(papszTokens[3]);
192
dst_xsize = image->width;
193
dst_ysize = image->height;
195
CSLDestroy( papszTokens );
199
* Compute the georeferenced window of overlap, and do nothing if there
200
* is no overlap between the map extents, and the file we are operating on.
202
else if( layer->transform )
204
int dst_lrx, dst_lry;
207
msDebug( "msDrawRasterLayerGDAL(): Entering transform.\n" );
209
msGetGDALGeoTransform( hDS, map, layer, adfGeoTransform );
210
InvGeoTransform( adfGeoTransform, adfInvGeoTransform );
212
mapRect = map->extent;
214
mapRect.minx -= map->cellsize*0.5;
215
mapRect.maxx += map->cellsize*0.5;
216
mapRect.miny -= map->cellsize*0.5;
217
mapRect.maxy += map->cellsize*0.5;
221
if( copyRect.minx < GEO_TRANS(adfGeoTransform,0,src_ysize) )
222
copyRect.minx = GEO_TRANS(adfGeoTransform,0,src_ysize);
223
if( copyRect.maxx > GEO_TRANS(adfGeoTransform,src_xsize,0) )
224
copyRect.maxx = GEO_TRANS(adfGeoTransform,src_xsize,0);
226
if( copyRect.miny < GEO_TRANS(adfGeoTransform+3,0,src_ysize) )
227
copyRect.miny = GEO_TRANS(adfGeoTransform+3,0,src_ysize);
228
if( copyRect.maxy > GEO_TRANS(adfGeoTransform+3,src_xsize,0) )
229
copyRect.maxy = GEO_TRANS(adfGeoTransform+3,src_xsize,0);
231
if( copyRect.minx >= copyRect.maxx || copyRect.miny >= copyRect.maxy )
234
msDebug( "msDrawRasterLayerGDAL(): Error in overlap calculation.\n" );
239
* Copy the source and destination raster coordinates.
241
llx = GEO_TRANS(adfInvGeoTransform+0,copyRect.minx,copyRect.miny);
242
lly = GEO_TRANS(adfInvGeoTransform+3,copyRect.minx,copyRect.miny);
243
urx = GEO_TRANS(adfInvGeoTransform+0,copyRect.maxx,copyRect.maxy);
244
ury = GEO_TRANS(adfInvGeoTransform+3,copyRect.maxx,copyRect.maxy);
246
src_xoff = MAX(0,(int) floor(llx+0.5));
247
src_yoff = MAX(0,(int) floor(ury+0.5));
248
src_xsize = MIN(MAX(0,(int) (urx - llx + 0.5)),
249
GDALGetRasterXSize(hDS) - src_xoff);
250
src_ysize = MIN(MAX(0,(int) (lly - ury + 0.5)),
251
GDALGetRasterYSize(hDS) - src_yoff);
253
if( src_xsize == 0 || src_ysize == 0 )
256
msDebug( "msDrawRasterLayerGDAL(): no apparent overlap between map view and this window(1).\n" );
260
if (map->cellsize == 0)
263
msDebug( "msDrawRasterLayerGDAL(): Cellsize can't be 0.\n" );
267
dst_xoff = (int) ((copyRect.minx - mapRect.minx) / map->cellsize);
268
dst_yoff = (int) ((mapRect.maxy - copyRect.maxy) / map->cellsize);
270
dst_lrx = (int) ((copyRect.maxx - mapRect.minx) / map->cellsize + 0.5);
271
dst_lry = (int) ((mapRect.maxy - copyRect.miny) / map->cellsize + 0.5);
272
dst_lrx = MAX(0,MIN(image->width,dst_lrx));
273
dst_lry = MAX(0,MIN(image->height,dst_lry));
275
dst_xsize = MAX(0,MIN(image->width,dst_lrx - dst_xoff));
276
dst_ysize = MAX(0,MIN(image->height,dst_lry - dst_yoff));
278
if( dst_xsize == 0 || dst_ysize == 0 )
281
msDebug( "msDrawRasterLayerGDAL(): no apparent overlap between map view and this window(2).\n" );
286
msDebug( "msDrawRasterLayerGDAL(): src=%d,%d,%d,%d, dst=%d,%d,%d,%d\n",
287
src_xoff, src_yoff, src_xsize, src_ysize,
288
dst_xoff, dst_yoff, dst_xsize, dst_ysize );
286
double d_src_xoff, d_src_yoff, geo_x, geo_y;
288
geo_x = mapRect.minx + dst_xoff * map->cellsize;
289
geo_y = mapRect.maxy - dst_yoff * map->cellsize;
291
d_src_xoff = (geo_x - adfGeoTransform[0]) / adfGeoTransform[1];
292
d_src_yoff = (geo_y - adfGeoTransform[3]) / adfGeoTransform[5];
292
double d_src_xoff, d_src_yoff, geo_x, geo_y;
294
geo_x = mapRect.minx + dst_xoff * map->cellsize;
295
geo_y = mapRect.maxy - dst_yoff * map->cellsize;
297
d_src_xoff = (geo_x - adfGeoTransform[0]) / adfGeoTransform[1];
298
d_src_yoff = (geo_y - adfGeoTransform[3]) / adfGeoTransform[5];
294
msDebug( "source raster PL (%.3f,%.3f) for dst PL (%d,%d).\n",
295
d_src_xoff, d_src_yoff,
296
dst_xoff, dst_yoff );
300
msDebug( "msDrawRasterLayerGDAL(): source raster PL (%.3f,%.3f) for dst PL (%d,%d).\n",
301
d_src_xoff, d_src_yoff,
302
dst_xoff, dst_yoff );
302
* If layer transforms are turned off, just map 1:1.
306
dst_xoff = src_xoff = 0;
307
dst_yoff = src_yoff = 0;
308
dst_xsize = src_xsize = MIN(image->width,src_xsize);
309
dst_ysize = src_ysize = MIN(image->height,src_ysize);
313
* In RAWDATA mode we don't fool with colors. Do the raw processing,
314
* and return from the function early.
318
assert( MS_RENDERER_RAWDATA( image->format ) );
320
return msDrawRasterLayerGDAL_RawMode(
321
map, layer, image, hDS,
322
src_xoff, src_yoff, src_xsize, src_ysize,
323
dst_xoff, dst_yoff, dst_xsize, dst_ysize );
327
* Is this image classified? We consider it classified if there are
328
* classes with an expression string *or* a color range. We don't want
329
* to treat the raster as classified if there is just a bogus class here
330
* to force inclusion in the legend.
332
for( i = 0; i < layer->numclasses; i++ )
336
/* change colour based on colour range? */
337
for(s=0; s<layer->class[i]->numstyles; s++)
339
if( MS_VALID_COLOR(layer->class[i]->styles[s]->mincolor)
340
&& MS_VALID_COLOR(layer->class[i]->styles[s]->maxcolor) )
347
if( layer->class[i]->expression.string != NULL )
355
* Set up the band selection. We look for a BANDS directive in the
356
* the PROCESSING options. If not found we default to red=1 or
357
* red=1,green=2,blue=3 or red=1,green=2,blue=3,alpha=4.
360
if( CSLFetchNameValue( layer->processing, "BANDS" ) == NULL )
364
if( GDALGetRasterCount( hDS ) >= 4
365
&& GDALGetRasterColorInterpretation(
366
GDALGetRasterBand( hDS, 4 ) ) == GCI_AlphaBand )
369
if( GDALGetRasterCount( hDS ) >= 3 )
375
if( GDALGetRasterCount( hDS ) == 2
376
&& GDALGetRasterColorInterpretation(
377
GDALGetRasterBand( hDS, 2 ) ) == GCI_AlphaBand )
380
hBand1 = GDALGetRasterBand( hDS, red_band );
382
|| GDALGetRasterColorTable( hBand1 ) != NULL )
393
band_list = msGetGDALBandList( layer, hDS, 4, &band_count );
394
if( band_list == NULL )
398
red_band = band_list[0];
403
green_band = band_list[1];
404
blue_band = band_list[2];
413
alpha_band = band_list[3];
420
band_numbers[0] = red_band;
421
band_numbers[1] = green_band;
422
band_numbers[2] = blue_band;
425
if( blue_band != 0 && alpha_band != 0 )
427
band_numbers[3] = alpha_band;
430
else if( blue_band != 0 && alpha_band == 0 )
432
else if( alpha_band != 0 )
434
band_numbers[1] = alpha_band;
440
if( layer->debug > 1 || (layer->debug > 0 && green_band != 0) )
442
msDebug( "msDrawGDAL(): red,green,blue,alpha bands = %d,%d,%d,%d\n",
443
red_band, green_band, blue_band, alpha_band );
447
* Get band handles for PC256, RGB or RGBA cases.
449
hBand1 = GDALGetRasterBand( hDS, red_band );
453
hBand2 = hBand3 = hBandAlpha = NULL;
455
if( green_band != 0 )
457
hBand1 = GDALGetRasterBand( hDS, red_band );
458
hBand2 = GDALGetRasterBand( hDS, green_band );
459
hBand3 = GDALGetRasterBand( hDS, blue_band );
460
if( hBand1 == NULL || hBand2 == NULL || hBand3 == NULL )
464
if( alpha_band != 0 )
465
hBandAlpha = GDALGetRasterBand( hDS, alpha_band );
468
* Wipe pen indicators for all our layer class colors if they exist.
469
* Sometimes temporary gdImg'es are used in which case previously allocated
470
* pens won't generally apply. See Bug 504.
472
if( gdImg && !truecolor )
476
for( iClass = 0; iClass < layer->numclasses; iClass++ )
478
for (iStyle=0; iStyle<layer->class[iClass]->numstyles; iStyle++)
479
layer->class[iClass]->styles[iStyle]->color.pen = MS_PEN_UNSET;
484
* The logic for a classification rendering of non-8bit raster bands
485
* is sufficiently different than the normal mechanism of loading
486
* into an 8bit buffer, that we isolate it into it's own subfunction.
488
if( classified && gdImg
489
&& hBand1 != NULL && GDALGetRasterDataType( hBand1 ) != GDT_Byte )
491
return msDrawRasterLayerGDAL_16BitClassification(
492
map, layer, image, hDS, hBand1,
493
src_xoff, src_yoff, src_xsize, src_ysize,
494
dst_xoff, dst_yoff, dst_xsize, dst_ysize );
498
* Get colormap for this image. If there isn't one, and we have only
499
* one band create a greyscale colormap.
505
hColorMap = GDALGetRasterColorTable( hBand1 );
506
if( hColorMap != NULL )
507
hColorMap = GDALCloneColorTable( hColorMap );
508
else if( hBand2 == NULL )
510
hColorMap = GDALCreateColorTable( GPI_RGB );
308
* If layer transforms are turned off, just map 1:1.
312
dst_xoff = src_xoff = 0;
313
dst_yoff = src_yoff = 0;
314
dst_xsize = src_xsize = MIN(image->width,src_xsize);
315
dst_ysize = src_ysize = MIN(image->height,src_ysize);
319
* In RAWDATA mode we don't fool with colors. Do the raw processing,
320
* and return from the function early.
322
if( MS_RENDERER_RAWDATA( image->format ) )
324
return msDrawRasterLayerGDAL_RawMode(
325
map, layer, image, hDS,
326
src_xoff, src_yoff, src_xsize, src_ysize,
327
dst_xoff, dst_yoff, dst_xsize, dst_ysize );
331
* Is this image classified? We consider it classified if there are
332
* classes with an expression string *or* a color range. We don't want
333
* to treat the raster as classified if there is just a bogus class here
334
* to force inclusion in the legend.
336
for( i = 0; i < layer->numclasses; i++ )
340
/* change colour based on colour range? */
341
for(s=0; s<layer->class[i]->numstyles; s++)
343
if( MS_VALID_COLOR(layer->class[i]->styles[s]->mincolor)
344
&& MS_VALID_COLOR(layer->class[i]->styles[s]->maxcolor) )
351
if( layer->class[i]->expression.string != NULL )
359
* Set up the band selection. We look for a BANDS directive in the
360
* the PROCESSING options. If not found we default to red=1 or
361
* red=1,green=2,blue=3 or red=1,green=2,blue=3,alpha=4.
364
if( CSLFetchNameValue( layer->processing, "BANDS" ) == NULL )
368
if( GDALGetRasterCount( hDS ) >= 4
369
&& GDALGetRasterColorInterpretation(
370
GDALGetRasterBand( hDS, 4 ) ) == GCI_AlphaBand )
373
if( GDALGetRasterCount( hDS ) >= 3 )
379
if( GDALGetRasterCount( hDS ) == 2
380
&& GDALGetRasterColorInterpretation(
381
GDALGetRasterBand( hDS, 2 ) ) == GCI_AlphaBand )
384
hBand1 = GDALGetRasterBand( hDS, red_band );
386
|| GDALGetRasterColorTable( hBand1 ) != NULL )
397
band_list = msGetGDALBandList( layer, hDS, 4, &band_count );
398
if( band_list == NULL )
402
red_band = band_list[0];
407
green_band = band_list[1];
408
blue_band = band_list[2];
417
alpha_band = band_list[3];
424
band_numbers[0] = red_band;
425
band_numbers[1] = green_band;
426
band_numbers[2] = blue_band;
429
if( blue_band != 0 && alpha_band != 0 )
431
band_numbers[3] = alpha_band;
434
else if( blue_band != 0 && alpha_band == 0 )
436
else if( alpha_band != 0 )
438
band_numbers[1] = alpha_band;
444
if( layer->debug > 1 || (layer->debug > 0 && green_band != 0) )
446
msDebug( "msDrawRasterLayerGDAL(): red,green,blue,alpha bands = %d,%d,%d,%d\n",
447
red_band, green_band, blue_band, alpha_band );
451
* Get band handles for PC256, RGB or RGBA cases.
453
hBand1 = GDALGetRasterBand( hDS, red_band );
457
hBand2 = hBand3 = hBandAlpha = NULL;
459
if( green_band != 0 )
461
hBand1 = GDALGetRasterBand( hDS, red_band );
462
hBand2 = GDALGetRasterBand( hDS, green_band );
463
hBand3 = GDALGetRasterBand( hDS, blue_band );
464
if( hBand1 == NULL || hBand2 == NULL || hBand3 == NULL )
468
if( alpha_band != 0 )
469
hBandAlpha = GDALGetRasterBand( hDS, alpha_band );
472
* Wipe pen indicators for all our layer class colors if they exist.
473
* Sometimes temporary gdImg'es are used in which case previously allocated
474
* pens won't generally apply. See Bug 504.
476
if( rb->type == MS_BUFFER_GD )
480
for( iClass = 0; iClass < layer->numclasses; iClass++ )
482
for (iStyle=0; iStyle<layer->class[iClass]->numstyles; iStyle++)
483
layer->class[iClass]->styles[iStyle]->color.pen = MS_PEN_UNSET;
488
* The logic for a classification rendering of non-8bit raster bands
489
* is sufficiently different than the normal mechanism of loading
490
* into an 8bit buffer, that we isolate it into it's own subfunction.
493
&& hBand1 != NULL && GDALGetRasterDataType( hBand1 ) != GDT_Byte )
495
return msDrawRasterLayerGDAL_16BitClassification(
496
map, layer, rb, hDS, hBand1,
497
src_xoff, src_yoff, src_xsize, src_ysize,
498
dst_xoff, dst_yoff, dst_xsize, dst_ysize );
502
* Get colormap for this image. If there isn't one, and we have only
503
* one band create a greyscale colormap.
509
hColorMap = GDALGetRasterColorTable( hBand1 );
510
if( hColorMap != NULL )
511
hColorMap = GDALCloneColorTable( hColorMap );
512
else if( hBand2 == NULL )
514
hColorMap = GDALCreateColorTable( GPI_RGB );
512
for( i = 0; i < 256; i++ )
515
GDALColorEntry sEntry;
516
for( i = 0; i < 256; i++ )
519
GDALColorEntry sEntry;
522
if(MS_COMPARE_COLORS(pixel, layer->offsite))
527
sEntry.c4 = 0; /* alpha set to zero */
539
** This special calculation is intended to use only 128
540
** unique colors for greyscale in non-truecolor mode.
526
if(MS_COMPARE_COLORS(pixel, layer->offsite))
531
sEntry.c4 = 0; /* alpha set to zero */
533
else if( rb->type != MS_BUFFER_GD )
543
** This special calculation is intended to use only 128
544
** unique colors for greyscale in non-truecolor mode.
549
GDALSetColorEntry( hColorMap, i, &sEntry );
554
** If we have a known NODATA value, mark it now as transparent.
558
double dfNoDataValue = msGetGDALNoDataValue( layer, hBand1,
561
if( bGotNoData && dfNoDataValue >= 0
562
&& dfNoDataValue < GDALGetColorEntryCount( hColorMap ) )
564
GDALColorEntry sEntry;
553
GDALSetColorEntry( hColorMap, i, &sEntry );
558
** If we have a known NODATA value, mark it now as transparent.
562
double dfNoDataValue = msGetGDALNoDataValue( layer, hBand1,
565
if( bGotNoData && dfNoDataValue >= 0
566
&& dfNoDataValue < GDALGetColorEntryCount( hColorMap ) )
568
GDALColorEntry sEntry;
567
GDALGetColorEntry( hColorMap, (int) dfNoDataValue ),
568
sizeof(GDALColorEntry) );
571
GDALSetColorEntry( hColorMap, (int) dfNoDataValue, &sEntry );
577
* Setup the mapping between source eightbit pixel values, and the
578
* output images color table. There are two general cases, where the
579
* class colors are provided by the MAP file, or where we use the native
582
if( classified && gdImg ) {
587
if( hColorMap == NULL )
590
"Attempt to classify 24bit image, this is unsupported.",
571
GDALGetColorEntry( hColorMap, (int) dfNoDataValue ),
572
sizeof(GDALColorEntry) );
575
GDALSetColorEntry( hColorMap, (int) dfNoDataValue, &sEntry );
595
color_count = MIN(256,GDALGetColorEntryCount(hColorMap));
596
for(i=0; i < color_count; i++) {
598
GDALColorEntry sEntry;
600
GDALGetColorEntryAsRGB( hColorMap, i, &sEntry );
581
* Setup the mapping between source eight bit pixel values, and the
582
* output images color table. There are two general cases, where the
583
* class colors are provided by the MAP file, or where we use the native
591
if( hColorMap == NULL )
594
"Attempt to classify 24bit image, this is unsupported.",
599
color_count = MIN(256,GDALGetColorEntryCount(hColorMap));
600
for(i=0; i < color_count; i++) {
602
GDALColorEntry sEntry;
604
GDALGetColorEntryAsRGB( hColorMap, i, &sEntry );
602
pixel.red = sEntry.c1;
603
pixel.green = sEntry.c2;
604
pixel.blue = sEntry.c3;
606
pixel.red = sEntry.c1;
607
pixel.green = sEntry.c2;
608
pixel.blue = sEntry.c3;
607
if(!MS_COMPARE_COLORS(pixel, layer->offsite))
609
c = msGetClass(layer, &pixel);
611
if(!MS_COMPARE_COLORS(pixel, layer->offsite))
613
c = msGetClass(layer, &pixel);
611
if(c == -1)/* doesn't belong to any class, so handle like offsite*/
615
if(c == -1)/* doesn't belong to any class, so handle like offsite*/
617
if( rb->type == MS_BUFFER_GD )
617
/* change colour based on colour range? Currently we
618
only address the greyscale case properly. */
620
for(s=0; s<layer->class[c]->numstyles; s++)
622
if( MS_VALID_COLOR(layer->class[c]->styles[s]->mincolor)
623
&& MS_VALID_COLOR(layer->class[c]->styles[s]->maxcolor) )
624
msValueToRange(layer->class[c]->styles[s],
624
/* change colour based on colour range? Currently we
625
only address the greyscale case properly. */
627
for(s=0; s<layer->class[c]->numstyles; s++)
629
if( MS_VALID_COLOR(layer->class[c]->styles[s]->mincolor)
630
&& MS_VALID_COLOR(layer->class[c]->styles[s]->maxcolor) )
631
msValueToRange(layer->class[c]->styles[s],
635
if( rb->type == MS_BUFFER_GD )
637
RESOLVE_PEN_GD(rb->data.gd_img, layer->class[c]->styles[0]->color);
638
if( MS_TRANSPARENT_COLOR(layer->class[c]->styles[0]->color) )
640
else if( MS_VALID_COLOR(layer->class[c]->styles[0]->color))
642
/* use class color */
643
cmap[i] = layer->class[c]->styles[0]->color.pen;
645
else /* Use raster color */
646
cmap[i] = msAddColorGD(map, rb->data.gd_img, cmt,
647
pixel.red, pixel.green, pixel.blue);
649
else if( rb->type == MS_BUFFER_BYTE_RGBA )
651
if( MS_TRANSPARENT_COLOR(layer->class[c]->styles[0]->color))
652
/* leave it transparent */;
654
else if( MS_VALID_COLOR(layer->class[c]->styles[0]->color))
656
rb_cmap[0][i] = layer->class[c]->styles[0]->color.red;
657
rb_cmap[1][i] = layer->class[c]->styles[0]->color.green;
658
rb_cmap[2][i] = layer->class[c]->styles[0]->color.blue;
659
rb_cmap[3][i] = (255*layer->class[c]->styles[0]->opacity / 100);
662
else /* Use raster color */
664
rb_cmap[0][i] = pixel.red;
665
rb_cmap[1][i] = pixel.green;
666
rb_cmap[2][i] = pixel.blue;
628
RESOLVE_PEN_GD(gdImg, layer->class[c]->styles[0]->color);
629
if( MS_TRANSPARENT_COLOR(layer->class[c]->styles[0]->color) )
672
if( rb->type == MS_BUFFER_GD )
631
else if( MS_VALID_COLOR(layer->class[c]->styles[0]->color))
633
/* use class color */
634
cmap[i] = layer->class[c]->styles[0]->color.pen;
636
else /* Use raster color */
637
cmap[i] = msAddColorGD(map, gdImg, cmt,
638
pixel.red, pixel.green, pixel.blue);
643
} else if( hColorMap != NULL && !truecolor && gdImg ) {
647
color_count = MIN(256,GDALGetColorEntryCount(hColorMap));
649
for(i=0; i < color_count; i++) {
650
GDALColorEntry sEntry;
652
GDALGetColorEntryAsRGB( hColorMap, i, &sEntry );
655
&& (!MS_VALID_COLOR( layer->offsite )
656
|| layer->offsite.red != sEntry.c1
657
|| layer->offsite.green != sEntry.c2
658
|| layer->offsite.blue != sEntry.c3 ) )
659
cmap[i] = msAddColorGD(map, gdImg, cmt,
660
sEntry.c1, sEntry.c2, sEntry.c3);
676
} else if( hColorMap != NULL && rb->type == MS_BUFFER_GD ) {
680
color_count = MIN(256,GDALGetColorEntryCount(hColorMap));
682
for(i=0; i < color_count; i++) {
683
GDALColorEntry sEntry;
685
GDALGetColorEntryAsRGB( hColorMap, i, &sEntry );
688
&& (!MS_VALID_COLOR( layer->offsite )
689
|| layer->offsite.red != sEntry.c1
690
|| layer->offsite.green != sEntry.c2
691
|| layer->offsite.blue != sEntry.c3 ) )
692
cmap[i] = msAddColorGD(map, rb->data.gd_img, cmt,
693
sEntry.c1, sEntry.c2, sEntry.c3);
698
else if( hBand2 == NULL && hColorMap != NULL && rb->type == MS_BUFFER_BYTE_RGBA )
703
color_count = MIN(256,GDALGetColorEntryCount(hColorMap));
705
for(i=0; i < color_count; i++) {
706
GDALColorEntry sEntry;
708
GDALGetColorEntryAsRGB( hColorMap, i, &sEntry );
711
&& (!MS_VALID_COLOR( layer->offsite )
712
|| layer->offsite.red != sEntry.c1
713
|| layer->offsite.green != sEntry.c2
714
|| layer->offsite.blue != sEntry.c3 ) )
716
rb_cmap[0][i] = sEntry.c1;
717
rb_cmap[1][i] = sEntry.c2;
718
rb_cmap[2][i] = sEntry.c3;
719
rb_cmap[3][i] = sEntry.c4;
723
else if( rb->type == MS_BUFFER_GD )
725
allocColorCube( map, rb->data.gd_img, anColorCube );
729
* Allocate imagery buffers.
731
pabyRaw1 = (unsigned char *) malloc(dst_xsize * dst_ysize * band_count);
732
if( pabyRaw1 == NULL )
734
msSetError(MS_MEMERR, "Allocating work image of size %dx%dx%d failed.",
735
"msDrawRasterLayerGDAL()", dst_xsize, dst_ysize, band_count );
739
if( hBand2 != NULL && hBand3 != NULL )
741
pabyRaw2 = pabyRaw1 + dst_xsize * dst_ysize * 1;
742
pabyRaw3 = pabyRaw1 + dst_xsize * dst_ysize * 2;
745
if( hBandAlpha != NULL )
748
pabyRawAlpha = pabyRaw1 + dst_xsize * dst_ysize * 3;
665
else if( hBand2 == NULL && hColorMap != NULL )
670
color_count = MIN(256,GDALGetColorEntryCount(hColorMap));
672
for(i=0; i < color_count; i++) {
673
GDALColorEntry sEntry;
675
GDALGetColorEntryAsRGB( hColorMap, i, &sEntry );
678
&& (!MS_VALID_COLOR( layer->offsite )
679
|| layer->offsite.red != sEntry.c1
680
|| layer->offsite.green != sEntry.c2
681
|| layer->offsite.blue != sEntry.c3 ) )
682
cmap[i] = gdTrueColorAlpha(sEntry.c1, sEntry.c2, sEntry.c3,
683
127 - (sEntry.c4 >> 1) );
688
else if( !truecolor && gdImg )
690
allocColorCube( map, gdImg, anColorCube );
692
else if( !truecolor )
695
"Unsupported configuration for raster layer read via GDAL.",
701
* Allocate imagery buffers.
703
pabyRaw1 = (unsigned char *) malloc(dst_xsize * dst_ysize * band_count);
704
if( pabyRaw1 == NULL )
706
msSetError(MS_MEMERR, "Allocating work image of size %dx%dx%d failed.",
707
"msDrawRasterLayerGDAL()", dst_xsize, dst_ysize, band_count );
711
if( hBand2 != NULL && hBand3 != NULL )
713
pabyRaw2 = pabyRaw1 + dst_xsize * dst_ysize * 1;
714
pabyRaw3 = pabyRaw1 + dst_xsize * dst_ysize * 2;
717
if( hBandAlpha != NULL )
720
pabyRawAlpha = pabyRaw1 + dst_xsize * dst_ysize * 3;
722
pabyRawAlpha = pabyRaw1 + dst_xsize * dst_ysize * 1;
726
* Load image data into buffers with scaling, etc.
728
if( LoadGDALImages( hDS, band_numbers, band_count, layer,
729
src_xoff, src_yoff, src_xsize, src_ysize,
730
pabyRaw1, dst_xsize, dst_ysize ) == -1 )
750
pabyRawAlpha = pabyRaw1 + dst_xsize * dst_ysize * 1;
754
* Load image data into buffers with scaling, etc.
756
if( LoadGDALImages( hDS, band_numbers, band_count, layer,
757
src_xoff, src_yoff, src_xsize, src_ysize,
758
pabyRaw1, dst_xsize, dst_ysize,
760
&nNoData1, &nNoData2, &nNoData3 ) == -1 )
766
if( bHaveRGBNoData && layer->debug )
767
msDebug( "msDrawGDAL(): using RGB nodata values from GDAL dataset.\n" );
769
/* -------------------------------------------------------------------- */
770
/* If there was no alpha band, but we have a dataset level mask */
771
/* load it as massage it so it will function as our alpha for */
772
/* transparency purposes. */
773
/* -------------------------------------------------------------------- */
774
#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1500
775
if( hBandAlpha == NULL )
777
int nMaskFlags = GDALGetMaskFlags(hBand1);
779
if( (CSLFetchNameValue( layer->processing, "BANDS" ) == NULL ) &&
780
(nMaskFlags & GMF_PER_DATASET) != 0 &&
781
(nMaskFlags & (GMF_NODATA|GMF_ALL_VALID)) == 0 )
786
msDebug( "msDrawGDAL(): using GDAL mask band for alpha.\n" );
790
pabyRaw1 = (unsigned char *)
791
realloc(pabyRaw1,dst_xsize * dst_ysize * band_count);
793
if( pabyRaw1 == NULL )
795
msSetError(MS_MEMERR,
796
"Allocating work image of size %dx%dx%d failed.",
797
"msDrawRasterLayerGDAL()",
798
dst_xsize, dst_ysize, band_count );
804
pabyRaw2 = pabyRaw1 + dst_xsize * dst_ysize * 1;
805
pabyRaw3 = pabyRaw1 + dst_xsize * dst_ysize * 2;
806
pabyRawAlpha = pabyRaw1 + dst_xsize * dst_ysize * 3;
810
pabyRawAlpha = pabyRaw1 + dst_xsize * dst_ysize * 1;
813
hBandAlpha = GDALGetMaskBand(hBand1);
815
eErr = GDALRasterIO( hBandAlpha, GF_Read,
816
src_xoff, src_yoff, src_xsize, src_ysize,
817
pabyRawAlpha, dst_xsize, dst_ysize, GDT_Byte, 0,0);
819
if( eErr != CE_None )
821
msSetError( MS_IOERR, "GDALRasterIO() failed: %s",
822
"drawGDAL()", CPLGetLastErrorMsg() );
827
/* In case the mask is not an alpha channel, expand values of 1 to 255, */
828
/* so we can deal as it was an alpha band afterwards */
829
if ((nMaskFlags & GMF_ALPHA) == 0)
831
for(i=0;i<dst_xsize * dst_ysize;i++)
833
pabyRawAlpha[i] = 255;
837
#endif /* defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1500 */
736
839
/* -------------------------------------------------------------------- */
737
840
/* Single band plus colormap with alpha blending to 8bit. */
738
841
/* -------------------------------------------------------------------- */
739
if( hBand2 == NULL && !truecolor && gdImg && hBandAlpha != NULL )
842
if( hBand2 == NULL && rb->type == MS_BUFFER_GD && hBandAlpha != NULL )
744
for( i = dst_yoff; i < dst_yoff + dst_ysize; i++ )
847
for( i = dst_yoff; i < dst_yoff + dst_ysize; i++ )
748
for( j = dst_xoff; j < dst_xoff + dst_xsize; j++ )
750
alpha = pabyRawAlpha[k];
752
result = cmap[pabyRaw1[k++]];
755
** We don't do alpha blending in non-truecolor mode, just
756
** threshold the point on/off at alpha=128.
759
if( result != -1 && alpha >= 128 )
760
gdImg->pixels[i][j] = result;
764
assert( k == dst_xsize * dst_ysize );
851
for( j = dst_xoff; j < dst_xoff + dst_xsize; j++ )
853
alpha = pabyRawAlpha[k];
855
result = cmap[pabyRaw1[k++]];
858
** We don't do alpha blending in non-truecolor mode, just
859
** threshold the point on/off at alpha=128.
862
if( result != -1 && alpha >= 128 )
863
rb->data.gd_img->pixels[i][j] = result;
867
assert( k == dst_xsize * dst_ysize );
767
870
/* -------------------------------------------------------------------- */
768
871
/* Single band plus colormap (no alpha) to 8bit. */
769
872
/* -------------------------------------------------------------------- */
770
else if( hBand2 == NULL && !truecolor && gdImg )
775
for( i = dst_yoff; i < dst_yoff + dst_ysize; i++ )
779
for( j = dst_xoff; j < dst_xoff + dst_xsize; j++ )
781
result = cmap[pabyRaw1[k++]];
784
gdImg->pixels[i][j] = result;
789
assert( k == dst_xsize * dst_ysize );
792
/* -------------------------------------------------------------------- */
793
/* Single band plus colormap and alpha to truecolor. */
794
/* -------------------------------------------------------------------- */
795
else if( hBand2 == NULL && truecolor && gdImg && hBandAlpha != NULL )
800
for( i = dst_yoff; i < dst_yoff + dst_ysize; i++ )
804
for( j = dst_xoff; j < dst_xoff + dst_xsize; j++ )
806
alpha = pabyRawAlpha[k];
807
result = cmap[pabyRaw1[k++]];
809
if( result == -1 || alpha < 2 )
810
/* do nothing - transparent */;
811
else if( alpha > 253 )
812
gdImg->tpixels[i][j] = result;
815
/* mix alpha into "result" */
816
result += (127 - (alpha >> 1)) << 24;
817
gdImg->tpixels[i][j] =
818
msAlphaBlend( gdImg->tpixels[i][j], result );
824
/* -------------------------------------------------------------------- */
825
/* Single band plus colormap (no alpha) to truecolor */
826
/* -------------------------------------------------------------------- */
827
else if( hBand2 == NULL && truecolor && gdImg )
832
for( i = dst_yoff; i < dst_yoff + dst_ysize; i++ )
836
for( j = dst_xoff; j < dst_xoff + dst_xsize; j++ )
838
result = cmap[pabyRaw1[k++]];
840
gdImg->tpixels[i][j] = result;
845
/* -------------------------------------------------------------------- */
846
/* Input is 3 band RGB. Alpha blending is mixed into the loop */
847
/* since this case is less commonly used and has lots of other */
849
/* -------------------------------------------------------------------- */
850
else if( hBand3 != NULL && gdImg )
852
/* Dithered 24bit to 8bit conversion */
853
if( !truecolor && CSLFetchBoolean( layer->processing, "DITHER", FALSE ) )
873
else if( hBand2 == NULL && rb->type == MS_BUFFER_GD )
878
for( i = dst_yoff; i < dst_yoff + dst_ysize; i++ )
882
for( j = dst_xoff; j < dst_xoff + dst_xsize; j++ )
884
result = cmap[pabyRaw1[k++]];
887
rb->data.gd_img->pixels[i][j] = result;
892
assert( k == dst_xsize * dst_ysize );
895
/* -------------------------------------------------------------------- */
896
/* Single band plus colormap and alpha to truecolor. (RB) */
897
/* -------------------------------------------------------------------- */
898
else if( hBand2 == NULL && rb->type == MS_BUFFER_BYTE_RGBA && hBandAlpha != NULL )
903
for( i = dst_yoff; i < dst_yoff + dst_ysize; i++ )
905
for( j = dst_xoff; j < dst_xoff + dst_xsize; j++ )
907
int src_pixel, src_alpha, cmap_alpha, merged_alpha;
909
src_pixel = pabyRaw1[k];
910
src_alpha = pabyRawAlpha[k];
911
cmap_alpha = rb_cmap[3][src_pixel];
913
merged_alpha = (src_alpha * cmap_alpha) / 255;
915
if( merged_alpha < 2 )
916
/* do nothing - transparent */;
917
else if( merged_alpha > 253 )
919
RB_SET_PIXEL( rb, j, i,
920
rb_cmap[0][src_pixel],
921
rb_cmap[1][src_pixel],
922
rb_cmap[2][src_pixel],
927
RB_MIX_PIXEL( rb, j, i,
928
rb_cmap[0][src_pixel],
929
rb_cmap[1][src_pixel],
930
rb_cmap[2][src_pixel],
938
/* -------------------------------------------------------------------- */
939
/* Single band plus colormap (no alpha) to truecolor (RB) */
940
/* -------------------------------------------------------------------- */
941
else if( hBand2 == NULL && rb->type == MS_BUFFER_BYTE_RGBA )
946
for( i = dst_yoff; i < dst_yoff + dst_ysize; i++ )
948
for( j = dst_xoff; j < dst_xoff + dst_xsize; j++ )
950
int src_pixel = pabyRaw1[k++];
952
if( rb_cmap[3][src_pixel] > 253 )
954
RB_SET_PIXEL( rb, j, i,
955
rb_cmap[0][src_pixel],
956
rb_cmap[1][src_pixel],
957
rb_cmap[2][src_pixel],
958
rb_cmap[3][src_pixel] );
960
else if( rb_cmap[3][src_pixel] > 1 )
962
RB_MIX_PIXEL( rb, j, i,
963
rb_cmap[0][src_pixel],
964
rb_cmap[1][src_pixel],
965
rb_cmap[2][src_pixel],
966
rb_cmap[3][src_pixel] );
972
/* -------------------------------------------------------------------- */
973
/* Input is 3 band RGB. Alpha blending is mixed into the loop */
974
/* since this case is less commonly used and has lots of other */
976
/* -------------------------------------------------------------------- */
977
else if( hBand3 != NULL && rb->type == MS_BUFFER_BYTE_RGBA )
980
for( i = dst_yoff; i < dst_yoff + dst_ysize; i++ )
982
for( j = dst_xoff; j < dst_xoff + dst_xsize; j++, k++ )
984
if( MS_VALID_COLOR( layer->offsite )
985
&& pabyRaw1[k] == layer->offsite.red
986
&& pabyRaw2[k] == layer->offsite.green
987
&& pabyRaw3[k] == layer->offsite.blue )
991
&& pabyRaw1[k] == nNoData1
992
&& pabyRaw2[k] == nNoData2
993
&& pabyRaw3[k] == nNoData3 )
996
if( pabyRawAlpha == NULL || pabyRawAlpha[k] == 255 )
998
RB_SET_PIXEL( rb, j, i,
1004
else if( pabyRawAlpha[k] != 0 )
1006
RB_MIX_PIXEL( rb, j, i,
1016
/* -------------------------------------------------------------------- */
1017
/* Input is 3 band RGB. Alpha blending is mixed into the loop */
1018
/* since this case is less commonly used and has lots of other */
1019
/* overhead. (GD) */
1020
/* -------------------------------------------------------------------- */
1021
else if( hBand3 != NULL && rb->type == MS_BUFFER_GD )
1023
/* Dithered 24bit to 8bit conversion */
1024
if( CSLFetchBoolean( layer->processing, "DITHER", FALSE ) )
855
1026
#ifdef ENABLE_DITHER
856
unsigned char *pabyDithered;
858
pabyDithered = (unsigned char *) malloc(dst_xsize * dst_ysize);
859
if( pabyDithered == NULL )
861
msSetError(MS_MEMERR, "Allocating work image of size %dx%d failed.",
862
"msDrawRasterLayerGDAL()", dst_xsize, dst_ysize );
866
Dither24to8( pabyRaw1, pabyRaw2, pabyRaw3, pabyDithered,
867
dst_xsize, dst_ysize, image->format->transparent,
868
map->imagecolor, gdImg );
871
for( i = dst_yoff; i < dst_yoff + dst_ysize; i++ )
873
for( j = dst_xoff; j < dst_xoff + dst_xsize; j++, k++ )
875
if( MS_VALID_COLOR( layer->offsite )
876
&& pabyRaw1[k] == layer->offsite.red
877
&& pabyRaw2[k] == layer->offsite.green
878
&& pabyRaw3[k] == layer->offsite.blue )
881
if( pabyRawAlpha != NULL && pabyRawAlpha[k] == 0 )
884
gdImg->pixels[i][j] = pabyDithered[k];
888
free( pabyDithered );
1027
unsigned char *pabyDithered;
1029
pabyDithered = (unsigned char *) malloc(dst_xsize * dst_ysize);
1030
if( pabyDithered == NULL )
1032
msSetError(MS_MEMERR, "Allocating work image of size %dx%d failed.",
1033
"msDrawRasterLayerGDAL()", dst_xsize, dst_ysize );
1037
Dither24to8( pabyRaw1, pabyRaw2, pabyRaw3, pabyDithered,
1038
dst_xsize, dst_ysize, image->format->transparent,
1039
map->imagecolor, rb->data.gd_img );
1042
for( i = dst_yoff; i < dst_yoff + dst_ysize; i++ )
1044
for( j = dst_xoff; j < dst_xoff + dst_xsize; j++, k++ )
1046
if( MS_VALID_COLOR( layer->offsite )
1047
&& pabyRaw1[k] == layer->offsite.red
1048
&& pabyRaw2[k] == layer->offsite.green
1049
&& pabyRaw3[k] == layer->offsite.blue )
1053
&& pabyRaw1[k] == nNoData1
1054
&& pabyRaw2[k] == nNoData2
1055
&& pabyRaw3[k] == nNoData3 )
1058
if( pabyRawAlpha != NULL && pabyRawAlpha[k] == 0 )
1061
rb->data.gd_img->pixels[i][j] = pabyDithered[k];
1065
free( pabyDithered );
890
msSetError( MS_IMGERR,
891
"DITHER not supported in this build. Update to latest GDAL, and define the ENABLE_DITHER macro.", "drawGDAL()" );
1067
msSetError( MS_IMGERR,
1068
"DITHER not supported in this build. Update to latest GDAL, and define the ENABLE_DITHER macro.", "drawGDAL()" );
896
/* Color cubed 24bit to 8bit conversion. */
897
else if( !truecolor )
900
for( i = dst_yoff; i < dst_yoff + dst_ysize; i++ )
902
for( j = dst_xoff; j < dst_xoff + dst_xsize; j++, k++ )
906
if( MS_VALID_COLOR( layer->offsite )
907
&& pabyRaw1[k] == layer->offsite.red
908
&& pabyRaw2[k] == layer->offsite.green
909
&& pabyRaw3[k] == layer->offsite.blue )
912
if( pabyRawAlpha != NULL && pabyRawAlpha[k] == 0 )
915
cc_index= RGB_INDEX(pabyRaw1[k],pabyRaw2[k],pabyRaw3[k]);
916
gdImg->pixels[i][j] = anColorCube[cc_index];
923
for( i = dst_yoff; i < dst_yoff + dst_ysize; i++ )
925
for( j = dst_xoff; j < dst_xoff + dst_xsize; j++, k++ )
927
if( MS_VALID_COLOR( layer->offsite )
928
&& pabyRaw1[k] == layer->offsite.red
929
&& pabyRaw2[k] == layer->offsite.green
930
&& pabyRaw3[k] == layer->offsite.blue )
933
if( pabyRawAlpha == NULL || pabyRawAlpha[k] == 255 )
935
gdImg->tpixels[i][j] =
936
gdTrueColor(pabyRaw1[k], pabyRaw2[k], pabyRaw3[k]);
938
else if( pabyRawAlpha[k] != 0 )
941
int gd_alpha = 127 - (pabyRawAlpha[k] >> 1);
943
gd_color = gdTrueColorAlpha(
944
pabyRaw1[k], pabyRaw2[k], pabyRaw3[k], gd_alpha );
946
/* NOTE: GD versions prior to 2.0.12 didn't take
947
the source alpha into account at all */
949
gdImg->tpixels[i][j] =
950
msAlphaBlend( gdImg->tpixels[i][j], gd_color );
963
if( hColorMap != NULL )
964
GDALDestroyColorTable( hColorMap );
1073
/* Color cubed 24bit to 8bit conversion. */
1074
else if( rb->type == MS_BUFFER_GD )
1077
for( i = dst_yoff; i < dst_yoff + dst_ysize; i++ )
1079
for( j = dst_xoff; j < dst_xoff + dst_xsize; j++, k++ )
1083
if( MS_VALID_COLOR( layer->offsite )
1084
&& pabyRaw1[k] == layer->offsite.red
1085
&& pabyRaw2[k] == layer->offsite.green
1086
&& pabyRaw3[k] == layer->offsite.blue )
1090
&& pabyRaw1[k] == nNoData1
1091
&& pabyRaw2[k] == nNoData2
1092
&& pabyRaw3[k] == nNoData3 )
1095
if( pabyRawAlpha != NULL && pabyRawAlpha[k] == 0 )
1098
cc_index= RGB_INDEX(pabyRaw1[k],pabyRaw2[k],pabyRaw3[k]);
1099
rb->data.gd_img->pixels[i][j] = anColorCube[cc_index];
1104
msSetError(MS_MISCERR,"Unsupported raster configuration","msDrawRasterLayerGDAL()");
1115
if( hColorMap != NULL )
1116
GDALDestroyColorTable( hColorMap );
969
1121
/************************************************************************/