Add writer_png module
This commit is contained in:
parent
b72a9c8718
commit
1f2e7c97d6
3 changed files with 100 additions and 0 deletions
|
@ -9,6 +9,7 @@ files = Split("""
|
|||
camera.c
|
||||
charles.c
|
||||
scene.c
|
||||
writer_png.c
|
||||
""")
|
||||
|
||||
prog = env.Program('charles', files)
|
||||
|
|
80
src/writer_png.c
Normal file
80
src/writer_png.c
Normal file
|
@ -0,0 +1,80 @@
|
|||
/* writer_png.c
|
||||
*
|
||||
* Definition of the PNG writer.
|
||||
*
|
||||
* Eryn Wells <eryn@erynwells.me>
|
||||
*/
|
||||
|
||||
|
||||
#include <setjmp.h>
|
||||
|
||||
#include <png.h>
|
||||
|
||||
#include "writer_png.h"
|
||||
|
||||
|
||||
static void png_user_error(png_structp png, png_const_charp msg);
|
||||
static void png_user_warning(png_structp png, png_const_charp msg);
|
||||
|
||||
|
||||
/*
|
||||
* write_scene_png --
|
||||
*
|
||||
* Write the given scene to file in PNG format.
|
||||
*/
|
||||
int
|
||||
write_scene_png(Scene *scene, FILE *file)
|
||||
{
|
||||
if (!file) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Set up the PNG data structures. libpng requires two: a PNG object and an info object.
|
||||
png_structp png = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, png_user_error, png_user_warning);
|
||||
if (!png) {
|
||||
return -2;
|
||||
}
|
||||
|
||||
png_infop png_info = png_create_info_struct(png);
|
||||
if (!png_info) {
|
||||
return -3;
|
||||
}
|
||||
|
||||
// Set up libpng error handling. If an error occurs, libpng will longjmp back here... (Wat.)
|
||||
if (setjmp(png_jmpbuf(png))) {
|
||||
png_destroy_write_struct(&png, &png_info);
|
||||
return -4;
|
||||
}
|
||||
|
||||
// Set up output.
|
||||
png_init_io(png, file);
|
||||
|
||||
// TODO: Return number of bytes written.
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* png_user_error --
|
||||
*
|
||||
* Called by libpng when it encounters an error.
|
||||
*/
|
||||
/* static */ void
|
||||
png_user_error(png_structp png,
|
||||
png_const_charp msg)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* png_user_warning --
|
||||
*
|
||||
* Called by libpng when it encounters an warning.
|
||||
*/
|
||||
/* static */ void
|
||||
png_user_warning(png_structp png,
|
||||
png_const_charp msg)
|
||||
{
|
||||
|
||||
}
|
19
src/writer_png.h
Normal file
19
src/writer_png.h
Normal file
|
@ -0,0 +1,19 @@
|
|||
/* writer_png.h
|
||||
*
|
||||
* Declaration of the PNG writer.
|
||||
*
|
||||
* Eryn Wells <eryn@erynwells.me>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __WRITER_PNG_H
|
||||
#define __WRITER_PNG_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include "scene.h"
|
||||
|
||||
|
||||
int write_scene_png(Scene *scene, FILE *file);
|
||||
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue