pngwriter / pngwriter Goto Github PK
View Code? Open in Web Editor NEWC++ library for creating PNG images
Home Page: http://pngwriter.sourceforge.net/
C++ library for creating PNG images
Home Page: http://pngwriter.sourceforge.net/
src/pngwriter.cc
:
if((bit_depth_ == 16))
if((index > 999999999)||(index < 0))
cmake \
-DCMAKE_C_COMPILER=/usr/share/clang/scan-build/ccc-analyzer \
-DCMAKE_CXX_COMPILER=/usr/share/clang/scan-build/c++-analyzer \
path/to/pngwriter/
scan-build make
# scan-build -enable-checker core,unix,cplusplus,alpha.cplusplus,alpha.unix,alpha.core -v [-v] make
(~25+1 bugs)
Some examples are actually tests from bug reports.
Lets move them to tests/
so users are not confused and can focus on well documented examples.
Install the pngwriter.h
file to include/
Add RPATH, see kitware blog & kitware wiki and warning:
Make Warning (dev):
Policy CMP0042 is not set: MACOSX_RPATH is enabled by default. Run "cmake
--help-policy CMP0042" for policy details. Use the cmake_policy command to
set the policy and suppress this warning.
MACOSX_RPATH is not specified for the following targets:
pngwriter
This warning is for project developers. Use -Wno-dev to suppress it.
thx to @PrometheusPi for spotting that.
The functions pngwriter::bezier
and pngwriter::bezier_blend
are one example. the only difference in their 10+ lines body are line
vs. line_blend
. I think this is not the only case I saw.
pngwriter::plot_text_utf8
, pngwriter::get_text_width_utf8
and pngwriter::plot_text_utf8_blend
is another triple contender with an even larger body of copy-paste.
How do I find these doubles? I'm trying out cppcheck, see #75
[../src/pngwriter.cc:753]: (style) The scope of the variable 'temp1' can be reduced.
[../src/pngwriter.cc:753]: (style) The scope of the variable 'temp2' can be reduced.
[../src/pngwriter.cc:820]: (style) The scope of the variable 'temp1' can be reduced.
[../src/pngwriter.cc:820]: (style) The scope of the variable 'temp2' can be reduced.
[../src/pngwriter.cc:820]: (style) The scope of the variable 'temp3' can be reduced.
[../src/pngwriter.cc:820]: (style) The scope of the variable 'temp4' can be reduced.
[../src/pngwriter.cc:820]: (style) The scope of the variable 'temp5' can be reduced.
[../src/pngwriter.cc:1972]: (style) The scope of the variable 'newx' can be reduced.
[../src/pngwriter.cc:1972]: (style) The scope of the variable 'newy' can be reduced.
[../src/pngwriter.cc:2174]: (style) The scope of the variable 'z' can be reduced.
[../src/pngwriter.cc:2546]: (style) The scope of the variable 'z' can be reduced.
[../src/pngwriter.cc:3758]: (style) The scope of the variable 'newx' can be reduced.
[../src/pngwriter.cc:3758]: (style) The scope of the variable 'newy' can be reduced.
[../src/pngwriter.cc:3944]: (style) The scope of the variable 'z' can be reduced.
Check for memory leaks.
I have these two images (I hope they aren't changed by uploading it (happened to me at least on sourceforge already))
The second one was sent through gimp without changing it. One notable difference seems to be the bit depth which is 8 bits per channel for b.png
instead of 16 bits as the first image has.
I check if they are identical with python:
#!/usr/bin/python
# python oI_300x200.png oI_300x200-gimp.png
from numpy import *
from matplotlib.pyplot import *
from mpl_toolkits.mplot3d import Axes3D
from PIL import Image
import sys # argv
diff = array( Image.open( sys.argv[1] ) ) - array( Image.open( sys.argv[2] ) )
print "diff.sum =",diff.sum()
fig = figure()
imshow( diff )
tight_layout()
show()
which returns:
diff.sum = 0
And I also check if they are identical with pngwriter in C++:
/*
file=comparePng; g++ -c -std=c++11 -Wall -Wextra -DNO_FREETYPE -I$PNGWRITER_ROOT/include -o $file.o $file.cpp; g++ -L$PNGWRITER_ROOT/lib ./$file.o -Wl,-Bstatic -lpngwriter -lpng -lfreetype -lz -Wl,-Bdynamic -o $file.exe; ./$file.exe ../buildwoalpaka/oI_1200x1000.png-diffraction.png ../buildwoalpaka/oI_1200x1000-diffraction-center-white-out.png
*/
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <pngwriter.h>
int main( int argc, char ** argv )
{
assert( argc >= 3 );
auto & fnameA = argv[1];
auto & fnameB = argv[2];
int Nx, Ny;
int * diff = NULL;
pngwriter png( 1, 1, 0, "a" );
png.pngwriter_rename("b");
char test[25] = "a";
png.pngwriter_rename( test );
std::cout << "read in " << fnameA;
{
png.readfromfile( fnameA );
std::cout << " (bit depth = " << png.getbitdepth() << ")" << std::endl;
Nx = png.getwidth( );
Ny = png.getheight( );
diff = new int[ Nx*Ny ];
for ( int iy = 0; iy < Ny; ++iy )
{
for ( int ix = 0; ix < Nx; ++ix )
{
int const i = (iy*Nx)+ix;
diff[ (iy*Nx)+ix ] = png.read( 1+ix, 1+iy, 1 );
if ( i < 5 or ( i > Nx*Ny/2+Nx/2 and i < Nx*Ny/2+Nx/2+5 ) )
std::cout << "[i=" << std::setw(6) << i << "] : "
<< diff[i] << std::endl;
assert( png.read( 1+ix, 1+iy, 1 ) == png.read( 1+ix, 1+iy, 2 ) &&
"red channel must be equal to blue channel" );
assert( png.read( 1+ix, 1+iy, 2 ) == png.read( 1+ix, 1+iy, 3 ) &&
"blue channel must be equal to green channel" );
}
}
}
std::cout << "subtract " << fnameB;
{
png.readfromfile( fnameB );
std::cout << " (bit depth = " << png.getbitdepth() << ")" << std::endl;
assert( Nx == png.getwidth( ) );
assert( Ny == png.getheight( ) );
for ( int iy = 0; iy < Ny; ++iy )
{
for ( int ix = 0; ix < Nx; ++ix )
{
int const i = (iy*Nx)+ix;
diff[i] -= png.read( 1+ix, 1+iy, 1 );
if ( i < 5 or ( i > Nx*Ny/2+Nx/2 and i < Nx*Ny/2+Nx/2+5 ) )
std::cout << "[i=" << std::setw(6) << i << "] : "
<< png.read( 1+ix, 1+iy, 1 ) << std::endl;
assert( png.read( 1+ix, 1+iy, 1 ) == png.read( 1+ix, 1+iy, 2 ) &&
"red channel must be equal to blue channel" );
assert( png.read( 1+ix, 1+iy, 2 ) == png.read( 1+ix, 1+iy, 3 ) &&
"blue channel must be equal to green channel" );
}
}
}
std::cout << "Difference:" << std::endl;
int diffAbsSum = 0, maxDiff = 0, minDiff = 0;
for ( int i = 0; i < Nx*Ny; ++i )
{
if ( diff[i] != 0 and ( i < 5 or ( i > Nx*Ny/2+Nx/2 and i < Nx*Ny/2+Nx/2+5 ) ) )
std::cout << "[i=" << std::setw(6) << i << "] " << diff[i] << std::endl;
diffAbsSum += std::abs( diff[i] );
maxDiff = std::max( maxDiff, diff[i] );
minDiff = std::min( minDiff, diff[i] );
}
std::cout << "minimum difference : " << minDiff << std::endl;
std::cout << "maximum difference : " << maxDiff << std::endl;
return 0;
}
which returns
read in a.png (bit depth = 16)
[i= 0] : 19
[i= 1] : 16
[i= 2] : 5
[i= 3] : 8
[i= 4] : 15
[i=600601] : 40630
[i=600602] : 18786
[i=600603] : 10525
[i=600604] : 4403
subtract b.png (bit depth = 8)
[i= 0] : 0
[i= 1] : 0
[i= 2] : 0
[i= 3] : 0
[i= 4] : 0
[i=600601] : 40448
[i=600602] : 18688
[i=600603] : 10496
[i=600604] : 4352
Difference:
[i= 0] 19
[i= 1] 16
[i= 2] 5
[i= 3] 8
[i= 4] 15
[i=600601] 182
[i=600602] 98
[i=600603] 29
[i=600604] 51
minimum difference : 0
maximum difference : 255
With pull request #90 applied the output is:
read in a.png (bit depth = 16)
[i= 0] : 19
[i= 1] : 16
[i= 2] : 5
[i= 3] : 8
[i= 4] : 15
[i=600601] : 40630
[i=600602] : 18786
[i=600603] : 10525
[i=600604] : 4403
subtract b.png (bit depth = 8)
[i= 0] : 0
[i= 1] : 0
[i= 2] : 0
[i= 3] : 0
[i= 4] : 0
[i=600601] : 40606
[i=600602] : 18761
[i=600603] : 10537
[i=600604] : 4369
Difference:
[i= 0] 19
[i= 1] 16
[i= 2] 5
[i= 3] 8
[i= 4] 15
[i=600601] 24
[i=600602] 25
[i=600603] -12
[i=600604] 34
minimum difference : -53
maximum difference : 255
I'm not entirely sure why. And why this doesn't happen with python. Here are the outputs by ImageMagick's identify
identify -verbose a.png
Image: a.png
Format: PNG (Portable Network Graphics)
Mime type: image/png
Class: DirectClass
Geometry: 1200x1000+0+0
Units: Undefined
Type: Grayscale
Endianess: Undefined
Colorspace: Gray
Depth: 16-bit
Channel depth:
gray: 16-bit
Channel statistics:
Pixels: 1200000
Gray:
min: 0 (0)
max: 65535 (1)
mean: 13.0979 (0.000199862)
standard deviation: 160.475 (0.0024487)
kurtosis: 57702.6
skewness: 201.147
Rendering intent: Perceptual
Gamma: 0.6
Chromaticity:
red primary: (0.64,0.33)
green primary: (0.3,0.6)
blue primary: (0.15,0.06)
white point: (0.3127,0.329)
Background color: gray(255)
Border color: gray(223)
Matte color: gray(189)
Transparent color: gray(0)
Interlace: None
Intensity: Undefined
Compose: Over
Page geometry: 1200x1000+0+0
Dispose: Undefined
Iterations: 0
Compression: Zip
Orientation: Undefined
Properties:
Author: PNGwriter Author: Paul Blackburn
Creation Time: 5 Mar 2016 22:01:06 +0000
date:create: 2016-03-06T01:44:38+01:00
date:modify: 2016-03-05T23:01:07+01:00
Description: http://pngwriter.sourceforge.net/
png:gAMA: gamma=0.60000002 (See Gamma, above)
png:IHDR.bit-depth-orig: 16
png:IHDR.bit_depth: 16
png:IHDR.color-type-orig: 2
png:IHDR.color_type: 2 (Truecolor)
png:IHDR.interlace_method: 0 (Not interlaced)
png:IHDR.width,height: 1200, 1000
png:text: 5 tEXt/zTXt/iTXt chunks were found
png:tIME: 2016-03-05T22:01:06Z
signature: c904ab0fdffc555f82c8ff652676f6490812fdc17dc3ae4d8e201067436abba2
Software: PNGwriter: An easy to use graphics library.
Title: oI_1200x1000.png-diffraction.png
Artifacts:
filename: a.png
verbose: true
Tainted: False
Filesize: 1.234MB
Number pixels: 1.2M
Pixels per second: 20MB
User time: 0.060u
Elapsed time: 0:01.059
Version: ImageMagick 6.8.9-9 Q16 x86_64 2016-02-02 http://www.imagemagick.org
and for file b.png
identify -verbose b.png
Image: b.png
Format: PNG (Portable Network Graphics)
Mime type: image/png
Class: DirectClass
Geometry: 1200x1000+0+0
Resolution: 28.35x28.35
Print size: 42.328x35.2734
Units: PixelsPerCentimeter
Type: Grayscale
Endianess: Undefined
Colorspace: Gray
Depth: 8-bit
Channel depth:
gray: 8-bit
Channel statistics:
Pixels: 1200000
Gray:
min: 0 (0)
max: 255 (1)
mean: 0.0108958 (4.27288e-05)
standard deviation: 0.615423 (0.00241342)
kurtosis: 61157.9
skewness: 209.611
Colors: 55
Histogram:
1196167: ( 0, 0, 0) #000000 gray(0)
2264: ( 1, 1, 1) #010101 gray(1)
628: ( 2, 2, 2) #020202 gray(2)
284: ( 3, 3, 3) #030303 gray(3)
172: ( 4, 4, 4) #040404 gray(4)
102: ( 5, 5, 5) #050505 gray(5)
56: ( 6, 6, 6) #060606 gray(6)
34: ( 7, 7, 7) #070707 gray(7)
44: ( 8, 8, 8) #080808 gray(8)
30: ( 9, 9, 9) #090909 gray(9)
20: ( 10, 10, 10) #0A0A0A gray(10)
28: ( 11, 11, 11) #0B0B0B gray(11)
22: ( 12, 12, 12) #0C0C0C gray(12)
6: ( 13, 13, 13) #0D0D0D gray(13)
12: ( 14, 14, 14) #0E0E0E gray(14)
10: ( 15, 15, 15) #0F0F0F gray(15)
10: ( 16, 16, 16) #101010 gray(16)
8: ( 17, 17, 17) #111111 gray(17)
10: ( 18, 18, 18) #121212 gray(18)
4: ( 19, 19, 19) #131313 gray(19)
2: ( 20, 20, 20) #141414 gray(20)
2: ( 21, 21, 21) #151515 gray(21)
6: ( 22, 22, 22) #161616 gray(22)
4: ( 23, 23, 23) #171717 gray(23)
4: ( 25, 25, 25) #191919 gray(25)
4: ( 26, 26, 26) #1A1A1A gray(26)
2: ( 27, 27, 27) #1B1B1B gray(27)
4: ( 28, 28, 28) #1C1C1C gray(28)
6: ( 30, 30, 30) #1E1E1E gray(30)
2: ( 31, 31, 31) #1F1F1F gray(31)
2: ( 32, 32, 32) #202020 gray(32)
2: ( 33, 33, 33) #212121 gray(33)
2: ( 34, 34, 34) #222222 gray(34)
4: ( 35, 35, 35) #232323 gray(35)
4: ( 36, 36, 36) #242424 gray(36)
2: ( 37, 37, 37) #252525 gray(37)
2: ( 39, 39, 39) #272727 gray(39)
2: ( 41, 41, 41) #292929 gray(41)
2: ( 42, 42, 42) #2A2A2A gray(42)
2: ( 44, 44, 44) #2C2C2C gray(44)
2: ( 49, 49, 49) #313131 gray(49)
2: ( 51, 51, 51) #333333 gray(51)
2: ( 54, 54, 54) #363636 gray(54)
2: ( 57, 57, 57) #393939 gray(57)
2: ( 59, 59, 59) #3B3B3B gray(59)
2: ( 60, 60, 60) #3C3C3C gray(60)
2: ( 69, 69, 69) #454545 gray(69)
2: ( 73, 73, 73) #494949 gray(73)
2: ( 83, 83, 83) #535353 gray(83)
2: ( 94, 94, 94) #5E5E5E gray(94)
2: ( 96, 96, 96) #606060 gray(96)
2: (158,158,158) #9E9E9E gray(158)
2: (169,169,169) #A9A9A9 gray(169)
2: (192,192,192) #C0C0C0 gray(192)
1: (255,255,255) #FFFFFF gray(255)
Rendering intent: Perceptual
Gamma: 0.454545
Chromaticity:
red primary: (0.64,0.33)
green primary: (0.3,0.6)
blue primary: (0.15,0.06)
white point: (0.3127,0.329)
Background color: gray(255)
Border color: gray(223)
Matte color: gray(189)
Transparent color: gray(0)
Interlace: None
Intensity: Undefined
Compose: Over
Page geometry: 1200x1000+0+0
Dispose: Undefined
Iterations: 0
Compression: Zip
Orientation: Undefined
Properties:
date:create: 2016-03-06T01:44:40+01:00
date:modify: 2016-03-05T23:08:51+01:00
png:IHDR.bit-depth-orig: 8
png:IHDR.bit_depth: 8
png:IHDR.color-type-orig: 2
png:IHDR.color_type: 2 (Truecolor)
png:IHDR.interlace_method: 0 (Not interlaced)
png:IHDR.width,height: 1200, 1000
png:pHYs: x_res=2835, y_res=2835, units=1
png:sRGB: intent=0 (Perceptual Intent)
png:tIME: 2016-03-05T22:08:51Z
signature: f1e466877cb0fedd6e4c940f801b4db5085c8c4b7c36277327d2b93e2794cb95
Artifacts:
filename: b.png
verbose: true
Tainted: False
Filesize: 10.1KB
Number pixels: 1.2M
Pixels per second: 40MB
User time: 0.020u
Elapsed time: 0:01.029
Version: ImageMagick 6.8.9-9 Q16 x86_64 2016-02-02 http://www.imagemagick.org
and lastly the diff for easier viewing:
colordiff <(identify -verbose a.png) <(identify -verbose b.png)
1c1
< Image: a.png
---
> Image: b.png
6c6,8
< Units: Undefined
---
> Resolution: 28.35x28.35
> Print size: 42.328x35.2734
> Units: PixelsPerCentimeter
10c12
< Depth: 16-bit
---
> Depth: 8-bit
12c14
< gray: 16-bit
---
> gray: 8-bit
17,21c19,80
< max: 65535 (1)
< mean: 13.0979 (0.000199862)
< standard deviation: 160.475 (0.0024487)
< kurtosis: 57702.6
< skewness: 201.147
---
> max: 255 (1)
> mean: 0.0108958 (4.27288e-05)
> standard deviation: 0.615423 (0.00241342)
> kurtosis: 61157.9
> skewness: 209.611
> Colors: 55
> Histogram:
> 1196167: ( 0, 0, 0) #000000 gray(0)
> 2264: ( 1, 1, 1) #010101 gray(1)
> 628: ( 2, 2, 2) #020202 gray(2)
> 284: ( 3, 3, 3) #030303 gray(3)
> 172: ( 4, 4, 4) #040404 gray(4)
> 102: ( 5, 5, 5) #050505 gray(5)
> 56: ( 6, 6, 6) #060606 gray(6)
> 34: ( 7, 7, 7) #070707 gray(7)
> 44: ( 8, 8, 8) #080808 gray(8)
> 30: ( 9, 9, 9) #090909 gray(9)
> 20: ( 10, 10, 10) #0A0A0A gray(10)
> 28: ( 11, 11, 11) #0B0B0B gray(11)
> 22: ( 12, 12, 12) #0C0C0C gray(12)
> 6: ( 13, 13, 13) #0D0D0D gray(13)
> 12: ( 14, 14, 14) #0E0E0E gray(14)
> 10: ( 15, 15, 15) #0F0F0F gray(15)
> 10: ( 16, 16, 16) #101010 gray(16)
> 8: ( 17, 17, 17) #111111 gray(17)
> 10: ( 18, 18, 18) #121212 gray(18)
> 4: ( 19, 19, 19) #131313 gray(19)
> 2: ( 20, 20, 20) #141414 gray(20)
> 2: ( 21, 21, 21) #151515 gray(21)
> 6: ( 22, 22, 22) #161616 gray(22)
> 4: ( 23, 23, 23) #171717 gray(23)
> 4: ( 25, 25, 25) #191919 gray(25)
> 4: ( 26, 26, 26) #1A1A1A gray(26)
> 2: ( 27, 27, 27) #1B1B1B gray(27)
> 4: ( 28, 28, 28) #1C1C1C gray(28)
> 6: ( 30, 30, 30) #1E1E1E gray(30)
> 2: ( 31, 31, 31) #1F1F1F gray(31)
> 2: ( 32, 32, 32) #202020 gray(32)
> 2: ( 33, 33, 33) #212121 gray(33)
> 2: ( 34, 34, 34) #222222 gray(34)
> 4: ( 35, 35, 35) #232323 gray(35)
> 4: ( 36, 36, 36) #242424 gray(36)
> 2: ( 37, 37, 37) #252525 gray(37)
> 2: ( 39, 39, 39) #272727 gray(39)
> 2: ( 41, 41, 41) #292929 gray(41)
> 2: ( 42, 42, 42) #2A2A2A gray(42)
> 2: ( 44, 44, 44) #2C2C2C gray(44)
> 2: ( 49, 49, 49) #313131 gray(49)
> 2: ( 51, 51, 51) #333333 gray(51)
> 2: ( 54, 54, 54) #363636 gray(54)
> 2: ( 57, 57, 57) #393939 gray(57)
> 2: ( 59, 59, 59) #3B3B3B gray(59)
> 2: ( 60, 60, 60) #3C3C3C gray(60)
> 2: ( 69, 69, 69) #454545 gray(69)
> 2: ( 73, 73, 73) #494949 gray(73)
> 2: ( 83, 83, 83) #535353 gray(83)
> 2: ( 94, 94, 94) #5E5E5E gray(94)
> 2: ( 96, 96, 96) #606060 gray(96)
> 2: (158,158,158) #9E9E9E gray(158)
> 2: (169,169,169) #A9A9A9 gray(169)
> 2: (192,192,192) #C0C0C0 gray(192)
> 1: (255,255,255) #FFFFFF gray(255)
23c82
< Gamma: 0.6
---
> Gamma: 0.454545
42,49c101,104
< Author: PNGwriter Author: Paul Blackburn
< Creation Time: 5 Mar 2016 22:01:06 +0000
< date:create: 2016-03-06T01:44:38+01:00
< date:modify: 2016-03-05T23:01:07+01:00
< Description: http://pngwriter.sourceforge.net/
< png:gAMA: gamma=0.60000002 (See Gamma, above)
< png:IHDR.bit-depth-orig: 16
< png:IHDR.bit_depth: 16
---
> date:create: 2016-03-06T01:44:40+01:00
> date:modify: 2016-03-05T23:08:51+01:00
> png:IHDR.bit-depth-orig: 8
> png:IHDR.bit_depth: 8
54,58c109,112
< png:text: 5 tEXt/zTXt/iTXt chunks were found
< png:tIME: 2016-03-05T22:01:06Z
< signature: c904ab0fdffc555f82c8ff652676f6490812fdc17dc3ae4d8e201067436abba2
< Software: PNGwriter: An easy to use graphics library.
< Title: oI_1200x1000.png-diffraction.png
---
> png:pHYs: x_res=2835, y_res=2835, units=1
> png:sRGB: intent=0 (Perceptual Intent)
> png:tIME: 2016-03-05T22:08:51Z
> signature: f1e466877cb0fedd6e4c940f801b4db5085c8c4b7c36277327d2b93e2794cb95
60c114
< filename: a.png
---
> filename: b.png
63c117
< Filesize: 1.234MB
---
> Filesize: 10.1KB
65,67c119,121
< Pixels per second: 15MB
< User time: 0.060u
< Elapsed time: 0:01.079
---
> Pixels per second: 40MB
> User time: 0.020u
> Elapsed time: 0:01.030
So the 3 in my opinion main differences are:
Lastly!
The 16-bit version returns non-zero values for i=0...5
, although they should be perfectly 0!
Some standard lib includes are a bit adventurous.
E.g. the correct std-lib math include in c++ should look:
#include <cmath>
also check:
m
in CMakeLists.txtWrite a CMake Module like in ComputationalRadiationPhysics/libSplash#78
As 0.996109 ~ 1-1/255
this seems to happen because of some error in upscaling 255 to 65535. So unlike mentioned in the documentation
returned value will be of type int and be between 0 and 65535.
the highest value is not 65535
but 65280=65535-255
.
This bug afflicts both read
and dread
and all other read functions which call read
, like scaling and interpolation, ....
I will submit a pull request shortly.
Remove Compiler Warnings:
pngwriter/src/pngwriter.cc`: in »void pngwriter::close()«:
pngwriter/src/pngwriter.cc:991:22: ... »png_charp {aka char_}« [-Wwrite-strings]
pngwriter/src/pngwriter.cc:994:22: ... »png_charp {aka char_}« [-Wwrite-strings]
pngwriter/src/pngwriter.cc:997:22: ... »png_charp {aka char_}« [-Wwrite-strings]
pngwriter/src/pngwriter.cc:1000:22: ... »png_charp {aka char_}« [-Wwrite-strings]
pngwriter/src/pngwriter.cc:1003:22: ... »png_charp {aka char*}« [-Wwrite-strings]
See here.
Add CPack Routines like ComputationalRadiationPhysics/libSplash#82
Hi,
I write the short test, it only generates a full black png.
int main()
{
pngwriter one(300,300,0,"mytest.png");
std::cout << "Generating mytest.png...";
one.plot_text("Ubuntu-M.ttf", 16, 30, 30,0, "Hello World", 255,255,255);
one.write_png();
return 0;
}
Add the tests/
dir to CMake as soon as #26 is merged.
It might be worth re-building the internal image storage in a separate class.
That should make support for issues like #15 way easier.
Add examples/ to CMakeLists.txt
.
Add "const" methods to all pngwriter::
methods that do not change the state of the object.
Feature request/submission from Alex Flint (Dec 12th, 2006).
GCC 4.8.5 prints the following warnings with release 0.5.6
(on missing Freetype support):
src/pngwriter.cc:2730:6: warning: unused parameter ‘face_path’ [-Wunused-parameter]
void pngwriter::plot_text( char * face_path, int fontsize, int x_start, int y_start, double angle, char * text, int red, int green, int blue)
^
src/pngwriter.cc:2730:6: warning: unused parameter ‘fontsize’ [-Wunused-parameter]
src/pngwriter.cc:2730:6: warning: unused parameter ‘x_start’ [-Wunused-parameter]
src/pngwriter.cc:2730:6: warning: unused parameter ‘y_start’ [-Wunused-parameter]
src/pngwriter.cc:2730:6: warning: unused parameter ‘angle’ [-Wunused-parameter]
src/pngwriter.cc:2730:6: warning: unused parameter ‘text’ [-Wunused-parameter]
src/pngwriter.cc:2730:6: warning: unused parameter ‘red’ [-Wunused-parameter]
src/pngwriter.cc:2730:6: warning: unused parameter ‘green’ [-Wunused-parameter]
src/pngwriter.cc:2730:6: warning: unused parameter ‘blue’ [-Wunused-parameter]
src/pngwriter.cc:2736:6: warning: unused parameter ‘face_path’ [-Wunused-parameter]
void pngwriter::plot_text( char * face_path, int fontsize, int x_start, int y_start, double angle, char * text, double red, double green, double blue)
^
src/pngwriter.cc:2736:6: warning: unused parameter ‘fontsize’ [-Wunused-parameter]
src/pngwriter.cc:2736:6: warning: unused parameter ‘x_start’ [-Wunused-parameter]
src/pngwriter.cc:2736:6: warning: unused parameter ‘y_start’ [-Wunused-parameter]
src/pngwriter.cc:2736:6: warning: unused parameter ‘angle’ [-Wunused-parameter]
src/pngwriter.cc:2736:6: warning: unused parameter ‘text’ [-Wunused-parameter]
src/pngwriter.cc:2736:6: warning: unused parameter ‘red’ [-Wunused-parameter]
src/pngwriter.cc:2736:6: warning: unused parameter ‘green’ [-Wunused-parameter]
src/pngwriter.cc:2736:6: warning: unused parameter ‘blue’ [-Wunused-parameter]
src/pngwriter.cc:2743:6: warning: unused parameter ‘face_path’ [-Wunused-parameter]
void pngwriter::plot_text_utf8( char * face_path, int fontsize, int x_start, int y_start, double angle, char * text, int red, int green, int blue)
^
src/pngwriter.cc:2743:6: warning: unused parameter ‘fontsize’ [-Wunused-parameter]
src/pngwriter.cc:2743:6: warning: unused parameter ‘x_start’ [-Wunused-parameter]
src/pngwriter.cc:2743:6: warning: unused parameter ‘y_start’ [-Wunused-parameter]
src/pngwriter.cc:2743:6: warning: unused parameter ‘angle’ [-Wunused-parameter]
src/pngwriter.cc:2743:6: warning: unused parameter ‘text’ [-Wunused-parameter]
src/pngwriter.cc:2743:6: warning: unused parameter ‘red’ [-Wunused-parameter]
src/pngwriter.cc:2743:6: warning: unused parameter ‘green’ [-Wunused-parameter]
src/pngwriter.cc:2743:6: warning: unused parameter ‘blue’ [-Wunused-parameter]
src/pngwriter.cc:2730:6: warning: unused parameter ‘face_path’ [-Wunused-parameter]
void pngwriter::plot_text( char * face_path, int fontsize, int x_start, int y_start, double angle, char * text, int red, int green, int blue)
^
src/pngwriter.cc:2730:6: warning: unused parameter ‘fontsize’ [-Wunused-parameter]
src/pngwriter.cc:2730:6: warning: unused parameter ‘x_start’ [-Wunused-parameter]
src/pngwriter.cc:2730:6: warning: unused parameter ‘y_start’ [-Wunused-parameter]
src/pngwriter.cc:2730:6: warning: unused parameter ‘angle’ [-Wunused-parameter]
src/pngwriter.cc:2730:6: warning: unused parameter ‘text’ [-Wunused-parameter]
src/pngwriter.cc:2730:6: warning: unused parameter ‘red’ [-Wunused-parameter]
src/pngwriter.cc:2730:6: warning: unused parameter ‘green’ [-Wunused-parameter]
src/pngwriter.cc:2730:6: warning: unused parameter ‘blue’ [-Wunused-parameter]
src/pngwriter.cc:2749:6: warning: unused parameter ‘face_path’ [-Wunused-parameter]
void pngwriter::plot_text_utf8( char * face_path, int fontsize, int x_start, int y_start, double angle, char * text, double red, double green, double blue)
^
src/pngwriter.cc:2749:6: warning: unused parameter ‘fontsize’ [-Wunused-parameter]
src/pngwriter.cc:2749:6: warning: unused parameter ‘x_start’ [-Wunused-parameter]
src/pngwriter.cc:2749:6: warning: unused parameter ‘y_start’ [-Wunused-parameter]
src/pngwriter.cc:2749:6: warning: unused parameter ‘angle’ [-Wunused-parameter]
src/pngwriter.cc:2749:6: warning: unused parameter ‘text’ [-Wunused-parameter]
src/pngwriter.cc:2749:6: warning: unused parameter ‘red’ [-Wunused-parameter]
src/pngwriter.cc:2749:6: warning: unused parameter ‘green’ [-Wunused-parameter]
src/pngwriter.cc:2749:6: warning: unused parameter ‘blue’ [-Wunused-parameter]
src/pngwriter.cc:2736:6: warning: unused parameter ‘face_path’ [-Wunused-parameter]
void pngwriter::plot_text( char * face_path, int fontsize, int x_start, int y_start, double angle, char * text, double red, double green, double blue)
^
src/pngwriter.cc:2736:6: warning: unused parameter ‘fontsize’ [-Wunused-parameter]
src/pngwriter.cc:2736:6: warning: unused parameter ‘x_start’ [-Wunused-parameter]
src/pngwriter.cc:2736:6: warning: unused parameter ‘y_start’ [-Wunused-parameter]
src/pngwriter.cc:2736:6: warning: unused parameter ‘angle’ [-Wunused-parameter]
src/pngwriter.cc:2736:6: warning: unused parameter ‘text’ [-Wunused-parameter]
src/pngwriter.cc:2736:6: warning: unused parameter ‘red’ [-Wunused-parameter]
src/pngwriter.cc:2736:6: warning: unused parameter ‘green’ [-Wunused-parameter]
src/pngwriter.cc:2736:6: warning: unused parameter ‘blue’ [-Wunused-parameter]
src/pngwriter.cc:2756:5: warning: unused parameter ‘face_path’ [-Wunused-parameter]
int pngwriter::get_text_width(char * face_path, int fontsize, char * text)
^
src/pngwriter.cc:2756:5: warning: unused parameter ‘fontsize’ [-Wunused-parameter]
src/pngwriter.cc:2756:5: warning: unused parameter ‘text’ [-Wunused-parameter]
src/pngwriter.cc:2743:6: warning: unused parameter ‘face_path’ [-Wunused-parameter]
void pngwriter::plot_text_utf8( char * face_path, int fontsize, int x_start, int y_start, double angle, char * text, int red, int green, int blue)
^
src/pngwriter.cc:2743:6: warning: unused parameter ‘fontsize’ [-Wunused-parameter]
src/pngwriter.cc:2743:6: warning: unused parameter ‘x_start’ [-Wunused-parameter]
src/pngwriter.cc:2743:6: warning: unused parameter ‘y_start’ [-Wunused-parameter]
src/pngwriter.cc:2743:6: warning: unused parameter ‘angle’ [-Wunused-parameter]
src/pngwriter.cc:2743:6: warning: unused parameter ‘text’ [-Wunused-parameter]
src/pngwriter.cc:2763:5: warning: unused parameter ‘face_path’ [-Wunused-parameter]
int pngwriter::get_text_width_utf8(char * face_path, int fontsize, char * text)
^
src/pngwriter.cc:2743:6: warning: unused parameter ‘red’ [-Wunused-parameter]
src/pngwriter.cc:2743:6: warning: unused parameter ‘green’ [-Wunused-parameter]
src/pngwriter.cc:2743:6: warning: unused parameter ‘blue’ [-Wunused-parameter]
src/pngwriter.cc:2763:5: warning: unused parameter ‘fontsize’ [-Wunused-parameter]
src/pngwriter.cc:2763:5: warning: unused parameter ‘text’ [-Wunused-parameter]
src/pngwriter.cc:2749:6: warning: unused parameter ‘face_path’ [-Wunused-parameter]
void pngwriter::plot_text_utf8( char * face_path, int fontsize, int x_start, int y_start, double angle, char * text, double red, double green, double blue)
^
src/pngwriter.cc:2749:6: warning: unused parameter ‘fontsize’ [-Wunused-parameter]
src/pngwriter.cc:2749:6: warning: unused parameter ‘x_start’ [-Wunused-parameter]
src/pngwriter.cc:2749:6: warning: unused parameter ‘y_start’ [-Wunused-parameter]
src/pngwriter.cc:2749:6: warning: unused parameter ‘angle’ [-Wunused-parameter]
src/pngwriter.cc:2749:6: warning: unused parameter ‘text’ [-Wunused-parameter]
src/pngwriter.cc:2749:6: warning: unused parameter ‘red’ [-Wunused-parameter]
src/pngwriter.cc:2749:6: warning: unused parameter ‘green’ [-Wunused-parameter]
src/pngwriter.cc:2749:6: warning: unused parameter ‘blue’ [-Wunused-parameter]
src/pngwriter.cc:2756:5: warning: unused parameter ‘face_path’ [-Wunused-parameter]
int pngwriter::get_text_width(char * face_path, int fontsize, char * text)
^
src/pngwriter.cc:2756:5: warning: unused parameter ‘fontsize’ [-Wunused-parameter]
src/pngwriter.cc:2756:5: warning: unused parameter ‘text’ [-Wunused-parameter]
src/pngwriter.cc:2763:5: warning: unused parameter ‘face_path’ [-Wunused-parameter]
int pngwriter::get_text_width_utf8(char * face_path, int fontsize, char * text)
^
src/pngwriter.cc:2763:5: warning: unused parameter ‘fontsize’ [-Wunused-parameter]
src/pngwriter.cc:2763:5: warning: unused parameter ‘text’ [-Wunused-parameter]
src/pngwriter.cc:4159:6: warning: unused parameter ‘face_path’ [-Wunused-parameter]
void pngwriter::plot_text_blend( char * face_path, int fontsize, int x_start, int y_start, double angle, char * text, double opacity, int red, int green, int blue)
^
src/pngwriter.cc:4159:6: warning: unused parameter ‘fontsize’ [-Wunused-parameter]
src/pngwriter.cc:4159:6: warning: unused parameter ‘x_start’ [-Wunused-parameter]
src/pngwriter.cc:4159:6: warning: unused parameter ‘y_start’ [-Wunused-parameter]
src/pngwriter.cc:4159:6: warning: unused parameter ‘angle’ [-Wunused-parameter]
src/pngwriter.cc:4159:6: warning: unused parameter ‘text’ [-Wunused-parameter]
src/pngwriter.cc:4159:6: warning: unused parameter ‘opacity’ [-Wunused-parameter]
src/pngwriter.cc:4159:6: warning: unused parameter ‘red’ [-Wunused-parameter]
src/pngwriter.cc:4159:6: warning: unused parameter ‘green’ [-Wunused-parameter]
src/pngwriter.cc:4159:6: warning: unused parameter ‘blue’ [-Wunused-parameter]
src/pngwriter.cc:4165:6: warning: unused parameter ‘face_path’ [-Wunused-parameter]
void pngwriter::plot_text_blend( char * face_path, int fontsize, int x_start, int y_start, double angle, char * text, double opacity, double red, double green, double blue)
^
src/pngwriter.cc:4165:6: warning: unused parameter ‘fontsize’ [-Wunused-parameter]
src/pngwriter.cc:4165:6: warning: unused parameter ‘x_start’ [-Wunused-parameter]
src/pngwriter.cc:4165:6: warning: unused parameter ‘y_start’ [-Wunused-parameter]
src/pngwriter.cc:4165:6: warning: unused parameter ‘angle’ [-Wunused-parameter]
src/pngwriter.cc:4165:6: warning: unused parameter ‘text’ [-Wunused-parameter]
src/pngwriter.cc:4165:6: warning: unused parameter ‘opacity’ [-Wunused-parameter]
src/pngwriter.cc:4165:6: warning: unused parameter ‘red’ [-Wunused-parameter]
src/pngwriter.cc:4165:6: warning: unused parameter ‘green’ [-Wunused-parameter]
src/pngwriter.cc:4165:6: warning: unused parameter ‘blue’ [-Wunused-parameter]
src/pngwriter.cc:4172:6: warning: unused parameter ‘face_path’ [-Wunused-parameter]
void pngwriter::plot_text_utf8_blend( char * face_path, int fontsize, int x_start, int y_start, double angle, char * text, double opacity, int red, int green, int blue)
^
src/pngwriter.cc:4172:6: warning: unused parameter ‘fontsize’ [-Wunused-parameter]
src/pngwriter.cc:4172:6: warning: unused parameter ‘x_start’ [-Wunused-parameter]
src/pngwriter.cc:4172:6: warning: unused parameter ‘y_start’ [-Wunused-parameter]
src/pngwriter.cc:4172:6: warning: unused parameter ‘angle’ [-Wunused-parameter]
src/pngwriter.cc:4172:6: warning: unused parameter ‘text’ [-Wunused-parameter]
src/pngwriter.cc:4172:6: warning: unused parameter ‘opacity’ [-Wunused-parameter]
src/pngwriter.cc:4172:6: warning: unused parameter ‘red’ [-Wunused-parameter]
src/pngwriter.cc:4172:6: warning: unused parameter ‘green’ [-Wunused-parameter]
src/pngwriter.cc:4172:6: warning: unused parameter ‘blue’ [-Wunused-parameter]
src/pngwriter.cc:4178:6: warning: unused parameter ‘face_path’ [-Wunused-parameter]
void pngwriter::plot_text_utf8_blend( char * face_path, int fontsize, int x_start, int y_start, double angle, char * text, double opacity, double red, double green, double blue)
^
src/pngwriter.cc:4178:6: warning: unused parameter ‘fontsize’ [-Wunused-parameter]
src/pngwriter.cc:4178:6: warning: unused parameter ‘x_start’ [-Wunused-parameter]
src/pngwriter.cc:4178:6: warning: unused parameter ‘y_start’ [-Wunused-parameter]
src/pngwriter.cc:4178:6: warning: unused parameter ‘angle’ [-Wunused-parameter]
src/pngwriter.cc:4178:6: warning: unused parameter ‘text’ [-Wunused-parameter]
src/pngwriter.cc:4178:6: warning: unused parameter ‘opacity’ [-Wunused-parameter]
src/pngwriter.cc:4178:6: warning: unused parameter ‘red’ [-Wunused-parameter]
src/pngwriter.cc:4178:6: warning: unused parameter ‘green’ [-Wunused-parameter]
src/pngwriter.cc:4178:6: warning: unused parameter ‘blue’ [-Wunused-parameter]
src/pngwriter.cc:4159:6: warning: unused parameter ‘face_path’ [-Wunused-parameter]
void pngwriter::plot_text_blend( char * face_path, int fontsize, int x_start, int y_start, double angle, char * text, double opacity, int red, int green, int blue)
^
src/pngwriter.cc:4159:6: warning: unused parameter ‘fontsize’ [-Wunused-parameter]
src/pngwriter.cc:4159:6: warning: unused parameter ‘x_start’ [-Wunused-parameter]
src/pngwriter.cc:4159:6: warning: unused parameter ‘y_start’ [-Wunused-parameter]
src/pngwriter.cc:4159:6: warning: unused parameter ‘angle’ [-Wunused-parameter]
src/pngwriter.cc:4159:6: warning: unused parameter ‘text’ [-Wunused-parameter]
src/pngwriter.cc:4159:6: warning: unused parameter ‘opacity’ [-Wunused-parameter]
src/pngwriter.cc:4159:6: warning: unused parameter ‘red’ [-Wunused-parameter]
src/pngwriter.cc:4159:6: warning: unused parameter ‘green’ [-Wunused-parameter]
src/pngwriter.cc:4159:6: warning: unused parameter ‘blue’ [-Wunused-parameter]
src/pngwriter.cc:4165:6: warning: unused parameter ‘face_path’ [-Wunused-parameter]
void pngwriter::plot_text_blend( char * face_path, int fontsize, int x_start, int y_start, double angle, char * text, double opacity, double red, double green, double blue)
^
src/pngwriter.cc:4165:6: warning: unused parameter ‘fontsize’ [-Wunused-parameter]
src/pngwriter.cc:4165:6: warning: unused parameter ‘x_start’ [-Wunused-parameter]
src/pngwriter.cc:4165:6: warning: unused parameter ‘y_start’ [-Wunused-parameter]
src/pngwriter.cc:4165:6: warning: unused parameter ‘angle’ [-Wunused-parameter]
src/pngwriter.cc:4165:6: warning: unused parameter ‘text’ [-Wunused-parameter]
src/pngwriter.cc:4165:6: warning: unused parameter ‘opacity’ [-Wunused-parameter]
src/pngwriter.cc:4165:6: warning: unused parameter ‘red’ [-Wunused-parameter]
src/pngwriter.cc:4165:6: warning: unused parameter ‘green’ [-Wunused-parameter]
src/pngwriter.cc:4165:6: warning: unused parameter ‘blue’ [-Wunused-parameter]
src/pngwriter.cc:4172:6: warning: unused parameter ‘face_path’ [-Wunused-parameter]
void pngwriter::plot_text_utf8_blend( char * face_path, int fontsize, int x_start, int y_start, double angle, char * text, double opacity, int red, int green, int blue)
^
src/pngwriter.cc:4172:6: warning: unused parameter ‘fontsize’ [-Wunused-parameter]
src/pngwriter.cc:4172:6: warning: unused parameter ‘x_start’ [-Wunused-parameter]
src/pngwriter.cc:4172:6: warning: unused parameter ‘y_start’ [-Wunused-parameter]
src/pngwriter.cc:4172:6: warning: unused parameter ‘angle’ [-Wunused-parameter]
src/pngwriter.cc:4172:6: warning: unused parameter ‘text’ [-Wunused-parameter]
src/pngwriter.cc:4172:6: warning: unused parameter ‘opacity’ [-Wunused-parameter]
src/pngwriter.cc:4172:6: warning: unused parameter ‘red’ [-Wunused-parameter]
src/pngwriter.cc:4172:6: warning: unused parameter ‘green’ [-Wunused-parameter]
src/pngwriter.cc:4172:6: warning: unused parameter ‘blue’ [-Wunused-parameter]
src/pngwriter.cc:4178:6: warning: unused parameter ‘face_path’ [-Wunused-parameter]
void pngwriter::plot_text_utf8_blend( char * face_path, int fontsize, int x_start, int y_start, double angle, char * text, double opacity, double red, double green, double blue)
^
src/pngwriter.cc:4178:6: warning: unused parameter ‘fontsize’ [-Wunused-parameter]
src/pngwriter.cc:4178:6: warning: unused parameter ‘x_start’ [-Wunused-parameter]
src/pngwriter.cc:4178:6: warning: unused parameter ‘y_start’ [-Wunused-parameter]
src/pngwriter.cc:4178:6: warning: unused parameter ‘angle’ [-Wunused-parameter]
src/pngwriter.cc:4178:6: warning: unused parameter ‘text’ [-Wunused-parameter]
src/pngwriter.cc:4178:6: warning: unused parameter ‘opacity’ [-Wunused-parameter]
src/pngwriter.cc:4178:6: warning: unused parameter ‘red’ [-Wunused-parameter]
src/pngwriter.cc:4178:6: warning: unused parameter ‘green’ [-Wunused-parameter]
src/pngwriter.cc:4178:6: warning: unused parameter ‘blue’ [-Wunused-parameter]
Looks like the include of <cstring>
is missing in gcc 4.8.x
for pngwriter.cc
Might should add a test case in travis (but this extends the build matrix -.-)
The installed version of pngwriter still requires programs to detect and set the NO_FREETYPE
flag if freetype fonts are not found (e.g. here).
That's rather shitty and would be nice if the first install could either remember this (introduce a version.hpp
?) or a CMakeModule could set this during find_package
.
Since pngwriter.h
is the general include that users include, the third party includes of png.h
, zlib.h
and ft2build.h
are required to reside in their INCLUDE_PATH
.
That's not necessary (since we don't use them in interfaces) and a pain with non-default paths.
Related to:
Found by @psychocoderHPC with a non-default libpng
.
The write performance with very big images (above 4K) is pretty poor, see #46.
libpng
inefficiently for writes?
png_set_interlace_handling
really disabled by default and what is the performance impact? Can one play with the ADAM7
passes?png_set_filter
?setcompressionlevel
/PNGWRITER_DEFAULT_COMPRESSION
(6) ? (currently, pretty high compression) -> also, there are more zlib parameters with png_set_compression_*
to tune! window_bits
, buffer_size
and mem_level
seem worth a look.libpng
itself the bottleneck?This will cause a lot of work :D
Coverity Scan with travis in a special branch.
Looks like the default should be 0.5
but sometimes is 0.45
or similar.
both read(x, y)
and dread(x, y)
fail to return the full color scale [0-65535] and [0.0-1.0], respectively. The reason most likely is that the multiplication of the internal 8but value with 256 will never reach the last 256 color values.
Can be reproduced with black/white image and the following test case:
#include <pngwriter.h>
#include <iostream>
int main(int argc, char **argv)
{
if (argc < 2)
return 1;
const std::string filename = argv[1];
const size_t size_x = 256, size_y = 256;
pngwriter image(size_x, size_y, 0, (filename + std::string(".tmp")).c_str());
image.readfromfile(filename.c_str());
size_t width = image.getwidth();
size_t height = image.getheight();
size_t bit_depth = image.getbitdepth();
bool black = false, white = false;
bool black_int = false, white_int = false;
std::cout << "bit depth = " << bit_depth << std::endl;
for (size_t x = 0; x < width; ++x)
for (size_t y = 0; y < height; ++y)
{
/* pngwriter coordinates start at (1,1) and the y direction is inverted */
int pos_x = 1 + x;
int pos_y = height - y - 1;
double color = image.dread(pos_x, pos_y);
if (color == 0.0)
black = true;
if (color == 1.0)
white = true;
int col = image.read(pos_x, pos_y);
if (col == 0)
black_int = true;
if (col == 65535 && bit_depth == 16)
white_int = true;
if (col == 255 && bit_depth == 8)
white_int = true;
}
image.close();
if (!(black && white))
std::cout << "failed double" << std::endl;
if (!(black_int && white_int))
std::cout << "failed int" << std::endl;
return 0;
}
In-cooperate patch from
http://sourceforge.net/p/pngwriter/discussion/238247/thread/6e7f2697/
pngwriter::readfromfile
as used in examples/pngtest.cc needs a return value.
Else, segfaults will appear as in this example, where the read call failed to to an invalid transform that was applied to the "png object".
Also, memory might be leaked (or it's not sure if memory is leaked since the test segfaults).
Is writing 0.55
for 0.5.5
a good idea or should we define major
, minor
and revision
in individual defines?
can we deprecate and in 0.6.0
remove the old define PNGWRITER_VERSION
?
Follow up to #10 and the patch from Daniel Hornung provided in Sourceforge Bugs 1:
diff -r e3904f443cd1 pngwriter.cpp
--- a/pngwriter.cpp
+++ b/pngwriter.cpp
@@ -1214,7 +1214,7 @@ void pngwriter::readfromfile(char * name
png_structp png_ptr;
png_infop info_ptr;
unsigned char **image;
- unsigned long width, height;
+ png_uint_32 width, height;
int bit_depth, color_type, interlace_type;
// png_uint_32 i;
//
...
Does this Bug still exist?
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=633405
Edit: Tested and yes still does...
Check against the newer branches of libpng
Compile-test only updates:
Newly deprecated functions used by PNGwriter
:
png_convert_to_rfc1123
-> png_convert_to_rfc1123_buffer
since version 1.6.0beta03
(and removed in 1.7.0beta59
):Added png_convert_to_rfc1123_buffer() and deprecated png_convert_to_rfc1123()
to avoid including a spurious buffer in the png_struct.
is that issue fixed by now? -> No
The private member function read_png_image
use pointers (instead of plain png_uint_32
) for width
and height
arguments.
This confuses the Coverity Scan (CID 114042f.) since this would require an input check for NULL
before de-referencing and assigning values.
I would therefore propose to change this private signature to use png_uint_32&
references instead of pointers (it's pretty c-style currently).
Also, png_get_image_width|height do return real values/copies and a real 0
value in case something went wrong.
Run and fix issues uncovered with cppcheck and splint.
Also interesting: -fsanitize=undefined
cppcheck [--enable=all] <pathToDir>
Example images: http://www.fnordware.com/superpng/samples.html, and PngSuite
(careful: the pnggrad
image does only contain the highest channel value for blue)
scale...
16-bit grayscale images (maybe all greyscale images?)
readfromfile
converts to 8bit without scaling down right (cut off?) for[0:65535]
back in read
png file type | readfromfile +read |
---|---|
8-bit/color RGB | ok |
8-bit grayscale | broken? |
16-bit/color RGB | ok |
16-bit grayscale | broken |
And palette based images? Forum
(d)readHSV
calls might also be broken and need a check + CI supportNote: talking about 8-bit
means per channel here. same for 16-bit
. Wiki
The creation time looks odd (png meta).
# ImageMagick
identify -verbose image.png
# [...]
Properties:
Author: Is OK!
Creation Time: 10 Dec
date:create: 2015-12-10T18:16:57+01:00
date:modify: 2015-12-10T18:16:57+01:00
Description: Is OK, too!
# [...]
Maybe we need to crop the user input/author to strlen 28 ? but description can be longer... hm.
what is the actual length of png_text::text
?
Reported by Dongkook Park in November 2009.
filledtriangle
and filledtriangle_blend
- y1^=x2;
+ y1^=y2;
@individual61 can you confirm that?
Add a "call for feedback" section in the readme to motive users to send in the pictures they create with pngwriter.
I get the following warning when I compile with gcc 4.9.1
and use libpng version 1.6.17
/home/slpp021/workspace/pngwriter/src/pngwriter.cc: In member function ‘void pngwriter::close()’:
/home/slpp021/workspace/pngwriter/src/pngwriter.cc:1081:11: warning: ‘const char* png_convert_to_rfc1123(png_structrp, png_const_timep)’ is deprecated (declared at /home/slpp021/lib/libpng-1.6.17/include/png.h:1175) [-Wdeprecated-declarations]
png_convert_to_rfc1123(png_ptr, &mod_time),
^
/home/slpp021/workspace/pngwriter/src/pngwriter.cc:1081:52: warning: ‘const char* png_convert_to_rfc1123(png_structrp, png_const_timep)’ is deprecated (declared at /home/slpp021/lib/libpng-1.6.17/include/png.h:1175) [-Wdeprecated-declarations]
png_convert_to_rfc1123(png_ptr, &mod_time),
Run the examples and validate the output (hash sums?)
Currently there is no error handling except prints with std::err
and perror
. This means, that it is hard to test if readFromFile
failed or not. Currently it is done like this:
pngwriter png( 1, 1, 0, "tmp.png" );
png.readfromfile( "input.png" );
if ( png.getwidth() == 1 and png.getwidth() == 1 )
exit( EXIT_FAILURE );
But this check has a false positive for images of size 1x1. These are border cases, but the may not always be unimportant. It would be nice if readFromFile
could return some error code.
Freshmeat (later: Freecode) closed June 2014.
Not sure if we still need the links or if listing in the new Freshcode.club
is necessary (imho: not for now).
Does the memory leak reported here still exist in the release-0.5.5
branch?
https://sourceforge.net/p/pngwriter/discussion/238247/thread/c7607b9b/
Hey @individual61 - do you think it's fine if we remove all the copied and translated Spanish files in 0.6.0 onwards?
It is just a huge pain to update them and the code is super duplicated :(
There are quite a few usages of graph_
even if a NULL
check failed and did print warnings to stderr
.
Coverity Scan CID 114014-114024
I was implementing a unit test for a read/write function using pngwriter and found the following problem. Some input values, like 0.868921399117f
were degrading to smaller and smaller values when chaining calls to read
and plot
. (More exactly I really wrote out the png and then read it in anew).
After roughly 120 iterations the value reaches a fix value of 0.868925001907f
. When representing this as the pngwriter internal integer this means the first value of 56945
degraded down to 56831
thereby loosing quite a bit of precision.
The problem is the simple cast to int in pngwriter::plot(int, int, double, double, double)
. Here is an example reproducing the problem and showing two possible bugfixes.
#include <iostream>
int main(void)
{
float originalValue = 0.868921399117;
for ( int i = 0; i < 120; ++i )
{
/* call pngwriter.plot which only exists with double arguments */
double doubleValueToPlot = double( originalValue );
/* the double version calls the int version with a cast wich always
* rounds using floor which results in value degradataion */
int intToPlot = int( doubleValueToPlot*65535 );
std::cout << "Plot int: " << intToPlot << "\n";
/* the int is written out without loss and then normally you would
* try to reconstruct the original float: */
float readInValue = (float) intToPlot / 65535;
originalValue = readInValue;
}
std::cout << "=== Bugfix 1 ===\n";
originalValue = 0.868921399117;
for ( int i = 0; i < 10; ++i )
{
/* add a plot function in pngwriter accepting float */
float valueToPlot = float( originalValue );
int intToPlot = int( valueToPlot*65535 );
std::cout << "Plot int: " << intToPlot << "\n";
float readInValue = (float) intToPlot / 65535;
originalValue = readInValue;
}
std::cout << "=== Bugfix 2 ===\n";
originalValue = 0.868921399117;
for ( int i = 0; i < 10; ++i )
{
double doubleValueToPlot = double( originalValue );
/* round correctly instead of doing a direct floor-like int cast */
auto round = []( double x ) -> int {
return (x > 0.0) ? (x + 0.5) : (x - 0.5);
};
int intToPlot = round( doubleValueToPlot*65535 );
std::cout << "Plot int: " << intToPlot << "\n";
float readInValue = (float) intToPlot / 65535;
originalValue = readInValue;
}
}
Note that Bugfix 1 converges to 56944
but bugfix 2 converges to 56945
. The latter is more correct, because the input was: 56944.7638911
many functions use 0
as an integer error
return code and 1
or something higher as success
read_png_image
read_png_info
check_if_png
this is against common sense, where 0
is always the successful result in the coding world.
One could/should also define enums for those magic numbers (at least for success).
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.