55 * This compilation unit provides functionality to render a bitmap struct to a
66 * PNG image (stored in a buffer).
77 *
8+ * NOTE: PNG output support may have not been enabled in the compiled version
9+ * of libsaxbospiral that you have. If support is not enabled, the library
10+ * boolean constant SXBP_PNG_SUPPORT will be set to false and the one public
11+ * function defined in this library will return SXBP_NOT_IMPLEMENTED.
12+ *
813 *
914 *
1015 * Copyright (C) 2016, Joshua Saxby [email protected] 2227 * along with this program. If not, see <http://www.gnu.org/licenses/>.
2328 */
2429#include <assert.h>
30+ // only include these extra dependencies if support for PNG output was enabled
31+ #ifdef SAXBOSPIRAL_PNG_SUPPORT
2532#include <stdlib.h>
2633#include <string.h>
34+ #endif
2735
36+ // only include libpng if support for it was enabled
37+ #ifdef SAXBOSPIRAL_PNG_SUPPORT
2838#include <png.h>
39+ #endif
2940
3041#include "../saxbospiral.h"
3142#include "../render.h"
3647extern "C" {
3748#endif
3849
50+ // only define the following private functions if libpng support was enabled
51+ #ifdef SAXBOSPIRAL_PNG_SUPPORT
3952// private custom libPNG buffer write function
4053static void buffer_write_data (
4154 png_structp png_ptr , png_bytep data , png_size_t length
@@ -80,11 +93,13 @@ static void cleanup_png_lib(
8093 free (row );
8194 }
8295}
96+ #endif // SAXBOSPIRAL_PNG_SUPPORT
8397
8498/*
8599 * given a bitmap_t struct and a pointer to a blank buffer_t, write the bitmap
86100 * data as a PNG image to the buffer, using libpng.
87- * returns a status struct containing error information, if any
101+ * returns a status struct containing error information
102+ * returns SXBP_NOT_IMPLEMENTED if PNG support was not enabled
88103 *
89104 * Asserts:
90105 * - That bitmap.pixels is not NULL
@@ -96,6 +111,11 @@ sxbp_status_t sxbp_render_backend_png(
96111 // preconditional assertsions
97112 assert (bitmap .pixels != NULL );
98113 assert (buffer -> bytes == NULL );
114+ // only do PNG operations if support is enabled
115+ #ifndef SAXBOSPIRAL_PNG_SUPPORT
116+ // return SXBP_NOT_IMPLEMENTED
117+ return SXBP_NOT_IMPLEMENTED ;
118+ #else
99119 // result status
100120 sxbp_status_t result ;
101121 // init buffer
@@ -186,6 +206,7 @@ sxbp_status_t sxbp_render_backend_png(
186206 // status ok
187207 result = SXBP_OPERATION_OK ;
188208 return result ;
209+ #endif // SAXBOSPIRAL_PNG_SUPPORT
189210}
190211
191212#ifdef __cplusplus
0 commit comments