~ubuntu-branches/debian/sid/pngphoon/sid

« back to all changes in this revision

Viewing changes to pngwrite.c

  • Committer: Package Import Robot
  • Author(s): Paulo Roberto Alves de Oliveira (aka kretcheu)
  • Date: 2015-08-10 00:52:00 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20150810005200-6snhuszsm0a97m45
Tags: 1.2-1
* QA upload.
* New upstream release.
* Migrations:
    - DH level to 9.
    - Standards-Version to 3.9.6.
    - debian/copyright to 1.0 format.
    - DebSrc to 3.0 format.
* debian/clean: Included to remove manpage created when building.
* debian/copyright: revised and updated all information.
* debian/dirs: removed because it is useless now.
* debian/install:
    - Included pngphoon binary.
    - Included sample script to use with xdpyinfo from X11-utils.
* debian/manpages: created to install the manpage.
* debian/rules: 
    - Updated to reduced format.
    - Added DEB_BUILD_MAINT_OPTIONS to improve the GCC hardening.
* debian/watch: Improved and removed extra comments.
* Added a patch 01-fix-Makefile-for-hardening
  to enable hardening options and remove library not used.

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
#include "fail.h"
10
10
#include "pngwrite.h"
11
11
 
12
 
void pngwrite( image_t *image, char* filename )
 
12
void pngwrite( image_t *image, char* filename, int height )
13
13
{
14
14
   png_structp png_ptr;
15
15
   png_infop info_ptr;
16
 
   
17
 
   /* create file */
18
 
   FILE *fp = (FILE*)0;
 
16
   png_bytep *firstrowps = image->rowps;
 
17
   volatile png_FILE_p fp = stdout;
19
18
 
20
 
   if( !strcmp( filename, "-" ) )
21
 
   {
22
 
      fp = stdout;
23
 
   }
24
 
   else
 
19
   /* create file or use stdout */
 
20
   if( strcmp( filename, "-" ) )
25
21
   {
26
22
      /* create file */
27
23
      fp = fopen(filename, "wb");
28
24
   }
29
25
 
30
 
   if (!fp)
31
 
      fail("[pngwrite] File %s could not be opened for writing", filename);
 
26
   if( !fp )
 
27
   {
 
28
      fail( "[pngwrite] File %s could not be opened for writing\n", filename );
 
29
   }
32
30
   
33
31
   
34
32
   /* initialize stuff */
35
33
   png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
36
34
   
37
 
   if (!png_ptr)
38
 
      fail("[pngwrite] png_create_write_struct failed");
 
35
   if( !png_ptr )
 
36
   {
 
37
      fail( "[pngwrite] png_create_write_struct failed\n" );
 
38
   }
39
39
   
40
40
   info_ptr = png_create_info_struct(png_ptr);
41
 
   if (!info_ptr)
42
 
      fail("[pngwrite] png_create_info_struct failed");
 
41
   if( !info_ptr )
 
42
   {
 
43
      fail( "[pngwrite] png_create_info_struct failed\n" );
 
44
   }
43
45
   
44
 
   if (setjmp(png_jmpbuf(png_ptr)))
45
 
      fail("[pngwrite] Error during init_io");
 
46
   if( setjmp(png_jmpbuf(png_ptr)) )
 
47
   {
 
48
      fail( "[pngwrite] Error during init_io\n" );
 
49
   }
46
50
   
47
51
   png_init_io(png_ptr, fp);
48
52
   
49
53
   
50
54
   /* write header */
51
 
   if (setjmp(png_jmpbuf(png_ptr)))
52
 
      fail("[pngwrite] Error during writing header");
 
55
   if( setjmp(png_jmpbuf(png_ptr)) )
 
56
   {
 
57
      fail( "[pngwrite] Error during writing header\n" );
 
58
   }
53
59
   
54
 
   png_set_IHDR(png_ptr, info_ptr, image->width, image->height,
55
 
                1, PNG_COLOR_TYPE_GRAY, PNG_INTERLACE_NONE,
56
 
                PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
 
60
   png_set_IHDR(png_ptr, info_ptr, image->width, height,
 
61
                1, PNG_COLOR_TYPE_GRAY, PNG_INTERLACE_NONE,
 
62
                PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
57
63
   
58
64
   png_write_info(png_ptr, info_ptr);
59
65
   
60
66
   
61
67
   /* write bytes */
62
 
   if (setjmp(png_jmpbuf(png_ptr)))
63
 
      fail("[pngwrite] Error during writing bytes");
64
 
   
65
 
   png_write_image(png_ptr, image->rowps);
66
 
   
 
68
   if( setjmp(png_jmpbuf(png_ptr)) )
 
69
   {
 
70
      fail( "[pngwrite] Error during writing bytes\n" );
 
71
   }
 
72
   
 
73
   if( height < image->height )
 
74
   {
 
75
      firstrowps += (image->height - height) / 2;
 
76
      png_write_rows( png_ptr, firstrowps, height );
 
77
   }
 
78
   else
 
79
   {
 
80
      png_write_image(png_ptr, image->rowps );
 
81
   }
 
82
 
67
83
   
68
84
   /* end write */
69
 
   if (setjmp(png_jmpbuf(png_ptr)))
70
 
      fail("[pngwrite] Error during end of write");
 
85
   if( setjmp(png_jmpbuf(png_ptr)) )
 
86
   {
 
87
      fail("[pngwrite] Error during end of write\n");
 
88
   }
71
89
   
72
 
   png_write_end(png_ptr, NULL);
 
90
   png_write_end( png_ptr, NULL );
73
91
   
74
92
   fclose(fp);
75
93
}