| 851 | } |
| 852 | |
| 853 | int saveGdImageBuffer(gdImagePtr ip, bufferObj *buffer, outputFormatObj *format) { |
| 854 | gdIOCtx *ctx; |
| 855 | int tmp_size; |
| 856 | |
| 857 | ctx = gdNewDynamicCtx (2048, NULL); |
| 858 | |
| 859 | if( format->imagemode == MS_IMAGEMODE_RGBA ) |
| 860 | gdImageSaveAlpha( ip, 1 ); |
| 861 | else if( format->imagemode == MS_IMAGEMODE_RGB ) |
| 862 | gdImageSaveAlpha( ip, 0 ); |
| 863 | |
| 864 | if(strcasecmp("ON", msGetOutputFormatOption(format, "INTERLACE", "ON")) == 0) |
| 865 | gdImageInterlace(ip, 1); |
| 866 | |
| 867 | if(format->transparent) |
| 868 | gdImageColorTransparent(ip, 0); |
| 869 | |
| 870 | if(strcasestr(format->driver, "/gif")) { |
| 871 | #ifdef USE_GD_GIF |
| 872 | gdImageGifCtx( ip, ctx ); |
| 873 | #else |
| 874 | msSetError(MS_MISCERR, "GIF output is not available.", "saveImageGD()"); |
| 875 | ctx->gd_free(ctx); |
| 876 | return(MS_FAILURE); |
| 877 | #endif |
| 878 | } else if(strcasestr(format->driver, "/png")) { |
| 879 | #ifdef USE_GD_PNG |
| 880 | gdImagePngCtx(ip, ctx); |
| 881 | #else |
| 882 | msSetError(MS_MISCERR, "PNG output is not available.", "saveImageGD()"); |
| 883 | ctx->gd_free(ctx); |
| 884 | return(MS_FAILURE); |
| 885 | #endif |
| 886 | } else if(strcasestr(format->driver, "/jpeg")) { |
| 887 | #ifdef USE_GD_JPEG |
| 888 | gdImageJpegCtx(ip, ctx, atoi(msGetOutputFormatOption( format, "QUALITY", "75"))); |
| 889 | #else |
| 890 | msSetError(MS_MISCERR, "JPEG output is not available.", "saveImageGD()"); |
| 891 | ctx->gd_free(ctx); |
| 892 | return(MS_FAILURE); |
| 893 | #endif |
| 894 | } else { |
| 895 | msSetError(MS_MISCERR, "Unknown or unsupported format.", "saveImageGD()"); |
| 896 | ctx->gd_free(ctx); |
| 897 | return(MS_FAILURE); |
| 898 | } |
| 899 | |
| 900 | /* gdDPExtractData expects a int*, but bufferObj::size is a size_t */ |
| 901 | /* so use a temp variable to hold it */ |
| 902 | buffer->data = gdDPExtractData (ctx, &tmp_size); |
| 903 | buffer->size = tmp_size; |
| 904 | |
| 905 | ctx->gd_free(ctx); |
| 906 | return MS_SUCCESS; |
| 907 | } |
| 908 | |
| 909 | int msSaveRasterBuffer(mapObj *map, rasterBufferObj *rb, FILE *stream, |
| 910 | outputFormatObj *format) { |
no test coverage detected