* Generic function to Initalize an image object. */
| 1448 | * Generic function to Initalize an image object. |
| 1449 | */ |
| 1450 | imageObj *msImageCreate(int width, int height, outputFormatObj *format, |
| 1451 | char *imagepath, char *imageurl, double resolution, |
| 1452 | double defresolution, colorObj *bg) |
| 1453 | { |
| 1454 | imageObj *image = NULL; |
| 1455 | if(MS_RENDERER_PLUGIN(format)) { |
| 1456 | |
| 1457 | image = format->vtable->createImage(width,height,format,bg); |
| 1458 | if (image == NULL) |
| 1459 | { |
| 1460 | msSetError(MS_MEMERR, "Unable to create new image object.", "msImageCreate()"); |
| 1461 | return NULL; |
| 1462 | } |
| 1463 | |
| 1464 | image->format = format; |
| 1465 | format->refcount++; |
| 1466 | |
| 1467 | image->width = width; |
| 1468 | image->height = height; |
| 1469 | image->imagepath = NULL; |
| 1470 | image->imageurl = NULL; |
| 1471 | image->tilecache = NULL; |
| 1472 | image->ntiles = 0; |
| 1473 | image->resolution = resolution; |
| 1474 | image->resolutionfactor = resolution/defresolution; |
| 1475 | |
| 1476 | if (imagepath) |
| 1477 | image->imagepath = msStrdup(imagepath); |
| 1478 | if (imageurl) |
| 1479 | image->imageurl = msStrdup(imageurl); |
| 1480 | |
| 1481 | return image; |
| 1482 | } |
| 1483 | else if( MS_RENDERER_RAWDATA(format) ) |
| 1484 | { |
| 1485 | if( format->imagemode != MS_IMAGEMODE_INT16 |
| 1486 | && format->imagemode != MS_IMAGEMODE_FLOAT32 |
| 1487 | && format->imagemode != MS_IMAGEMODE_BYTE ) |
| 1488 | { |
| 1489 | msSetError(MS_IMGERR, |
| 1490 | "Attempt to use illegal imagemode with rawdata renderer.", |
| 1491 | "msImageCreate()" ); |
| 1492 | return NULL; |
| 1493 | } |
| 1494 | |
| 1495 | image = (imageObj *)calloc(1,sizeof(imageObj)); |
| 1496 | if (image == NULL) |
| 1497 | { |
| 1498 | msSetError(MS_MEMERR, "Unable to create new image object.", "msImageCreate()"); |
| 1499 | return NULL; |
| 1500 | } |
| 1501 | |
| 1502 | if( format->imagemode == MS_IMAGEMODE_INT16 ) |
| 1503 | image->img.raw_16bit = (short *) |
| 1504 | msSmallCalloc(sizeof(short),width*height*format->bands); |
| 1505 | else if( format->imagemode == MS_IMAGEMODE_FLOAT32 ) |
| 1506 | image->img.raw_float = (float *) |
| 1507 | msSmallCalloc(sizeof(float),width*height*format->bands); |
no test coverage detected