diff --git a/src/UglyToad.PdfPig.Tests/Images/Files/Png/1-16bitRGBA-Issue550.png b/src/UglyToad.PdfPig.Tests/Images/Files/Png/1-16bitRGBA-Issue550.png new file mode 100644 index 00000000..a6c982a6 Binary files /dev/null and b/src/UglyToad.PdfPig.Tests/Images/Files/Png/1-16bitRGBA-Issue550.png differ diff --git a/src/UglyToad.PdfPig.Tests/Images/Files/Png/2-16bitRGB.png b/src/UglyToad.PdfPig.Tests/Images/Files/Png/2-16bitRGB.png new file mode 100644 index 00000000..e9f70328 Binary files /dev/null and b/src/UglyToad.PdfPig.Tests/Images/Files/Png/2-16bitRGB.png differ diff --git a/src/UglyToad.PdfPig.Tests/Images/Files/Png/3-16bitGray.png b/src/UglyToad.PdfPig.Tests/Images/Files/Png/3-16bitGray.png new file mode 100644 index 00000000..2a07afdc Binary files /dev/null and b/src/UglyToad.PdfPig.Tests/Images/Files/Png/3-16bitGray.png differ diff --git a/src/UglyToad.PdfPig.Tests/Images/Files/Png/4-16bitRGBA.png b/src/UglyToad.PdfPig.Tests/Images/Files/Png/4-16bitRGBA.png new file mode 100644 index 00000000..2a07afdc Binary files /dev/null and b/src/UglyToad.PdfPig.Tests/Images/Files/Png/4-16bitRGBA.png differ diff --git a/src/UglyToad.PdfPig.Tests/Images/Files/Png/TestPattern1/ident.txt b/src/UglyToad.PdfPig.Tests/Images/Files/Png/TestPattern1/ident.txt new file mode 100644 index 00000000..295850af --- /dev/null +++ b/src/UglyToad.PdfPig.Tests/Images/Files/Png/TestPattern1/ident.txt @@ -0,0 +1,9 @@ +tp1-001-8bitRGB-withExif~Thumbnail~ColorProfile.png PNG 200x150 200x150+0+0 8-bit sRGB 1747B 0.000u 0:00.001 +tp1-002-8bitRGBA-withExif~Thumbnail~ColorProfile.png PNG 200x200 200x200+0+0 8-bit sRGB 1826B 0.000u 0:00.000 +tp1-003-8bitRGB-Interlaced-withExif~ColorProfile.png PNG 200x150 200x150+0+0 8-bit sRGB 1229B 0.000u 0:00.000 +tp1-004-8bitRGBA-Interlaced-withExif~ColorProfile.png PNG 200x200 200x200+0+0 8-bit sRGB 1328B 0.000u 0:00.000 +tp1-101-16bitRGB-withExif~Thumbnail~ColorProfile.png PNG 200x150 200x150+0+0 16-bit sRGB 1973B 0.000u 0:00.000 +tp1-102-16bitRGBA-withExif~Thumbnail~ColorProfile.png PNG 200x200 200x200+0+0 16-bit sRGB 2121B 0.000u 0:00.000 +tp1-201-32bitRGB-withExif~Thumbnail~ColorProfile.png PNG 200x150 200x150+0+0 16-bit sRGB 1973B 0.000u 0:00.000 +tp1-301-16bitFloatRGB-withExif~Thumbnail~ColorProfile.png PNG 200x150 200x150+0+0 16-bit sRGB 1970B 0.000u 0:00.000 +tp1-401-32bitFloatRGB-withExif~Thumbnail~ColorProfile.png PNG 200x150 200x150+0+0 16-bit sRGB 1970B 0.000u 0:00.000 diff --git a/src/UglyToad.PdfPig.Tests/Images/Files/Png/TestPattern1/identVerbose.txt b/src/UglyToad.PdfPig.Tests/Images/Files/Png/TestPattern1/identVerbose.txt new file mode 100644 index 00000000..13ad92fb --- /dev/null +++ b/src/UglyToad.PdfPig.Tests/Images/Files/Png/TestPattern1/identVerbose.txt @@ -0,0 +1,1043 @@ +Image: tp1-001-8bitRGB-withExif~Thumbnail~ColorProfile.png + Format: PNG (Portable Network Graphics) + Mime type: image/png + Class: DirectClass + Geometry: 200x150+0+0 + Resolution: 72x72 + Print size: 2.77778x2.08333 + Units: PixelsPerInch + Type: Palette + Base type: TrueColor + Endianess: Undefined + Colorspace: sRGB + Depth: 8-bit + Channel depth: + Red: 8-bit + Green: 8-bit + Blue: 8-bit + Channel statistics: + Pixels: 30000 + Red: + min: 0 (0) + max: 255 (1) + mean: 103.875 (0.407353) + standard deviation: 105.653 (0.414324) + kurtosis: -1.82802 + skewness: 0.108259 + entropy: 0.88686 + Green: + min: 0 (0) + max: 255 (1) + mean: 103.875 (0.407353) + standard deviation: 105.653 (0.414324) + kurtosis: -1.82802 + skewness: 0.108259 + entropy: 0.88686 + Blue: + min: 0 (0) + max: 255 (1) + mean: 103.875 (0.407353) + standard deviation: 105.653 (0.414324) + kurtosis: -1.82802 + skewness: 0.108259 + entropy: 0.88686 + Image statistics: + Overall: + min: 0 (0) + max: 255 (1) + mean: 103.875 (0.407353) + standard deviation: 105.651 (0.414319) + kurtosis: -1.82797 + skewness: 0.108263 + entropy: 0.88686 + Colors: 8 + Histogram: + 3750: ( 0, 0, 0) #000000 black + 3750: ( 0, 0,192) #0000C0 srgb(0,0,192) + 3750: ( 0,192, 0) #00C000 srgb(0,192,0) + 3750: ( 0,192,192) #00C0C0 srgb(0,192,192) + 3750: (192, 0, 0) #C00000 srgb(192,0,0) + 3750: (192, 0,192) #C000C0 srgb(192,0,192) + 3750: (192,192, 0) #C0C000 srgb(192,192,0) + 3750: (255,255,255) #FFFFFF white + 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) + Matte color: grey74 + Background color: white + Border color: srgb(223,223,223) + Transparent color: none + Interlace: None + Intensity: Undefined + Compose: Over + Page geometry: 200x150+0+0 + Dispose: Undefined + Iterations: 0 + Compression: Zip + Orientation: Undefined + Properties: + date:create: 2023-02-25T14:44:15+10:00 + date:modify: 2023-02-25T14:44:15+10:00 + exif:BitsPerSample: 8, 8, 8 + exif:ColorSpace: 1 + exif:DateTime: 2023:02:25 14:44:02 + exif:ExifOffset: 178 + exif:ImageLength: 150 + exif:ImageWidth: 200 + exif:ResolutionUnit: 2 + exif:Software: GIMP 2.10.14 + exif:thumbnail:BitsPerSample: 8, 8, 8 + exif:thumbnail:Compression: 6 + exif:thumbnail:ImageLength: 192 + exif:thumbnail:ImageWidth: 256 + exif:thumbnail:JPEGInterchangeFormat: 304 + exif:thumbnail:JPEGInterchangeFormatLength: 1711 + exif:thumbnail:PhotometricInterpretation: 6 + exif:thumbnail:SamplesPerPixel: 3 + exif:XResolution: 72/1 + exif:YResolution: 72/1 + icc:copyright: Public Domain + icc:description: GIMP built-in sRGB + icc:manufacturer: GIMP + icc:model: sRGB + png:iCCP: chunk was found + 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: 200, 150 + png:pHYs: x_res=2835, y_res=2835, units=1 + png:text: 1 tEXt/zTXt/iTXt chunks were found + png:text-encoded profiles: 1 were found + png:tIME: 2023-02-25T04:44:15Z + signature: e45c14eb01b14647136b13db711568054884aca01761562d19c27206d5cc03c1 + Profiles: + Profile-exif: 2022 bytes + Profile-icc: 672 bytes + Artifacts: + verbose: true + Tainted: False + Filesize: 1747B + Number pixels: 30000 + Pixels per second: 30.0165MB + User time: 0.000u + Elapsed time: 0:01.000 + Version: ImageMagick 7.0.6-3 Q16 x64 2017-07-24 http://www.imagemagick.org +Image: tp1-002-8bitRGBA-withExif~Thumbnail~ColorProfile.png + Format: PNG (Portable Network Graphics) + Mime type: image/png + Class: DirectClass + Geometry: 200x200+0+0 + Resolution: 28.35x28.35 + Print size: 7.05467x7.05467 + Units: PixelsPerCentimeter + Type: PaletteAlpha + Base type: TrueColorAlpha + Endianess: Undefined + Colorspace: sRGB + Depth: 8-bit + Channel depth: + Red: 8-bit + Green: 8-bit + Blue: 8-bit + Alpha: 1-bit + Channel statistics: + Pixels: 40000 + Red: + min: 0 (0) + max: 255 (1) + mean: 77.9063 (0.305515) + standard deviation: 101.956 (0.399826) + kurtosis: -1.4925 + skewness: 0.606588 + entropy: 0.794128 + Green: + min: 0 (0) + max: 255 (1) + mean: 77.9063 (0.305515) + standard deviation: 101.956 (0.399826) + kurtosis: -1.4925 + skewness: 0.606588 + entropy: 0.794128 + Blue: + min: 0 (0) + max: 255 (1) + mean: 77.9063 (0.305515) + standard deviation: 101.956 (0.399826) + kurtosis: -1.4925 + skewness: 0.606588 + entropy: 0.794128 + Alpha: + min: 0 (0) + max: 255 (1) + mean: 191.25 (0.75) + standard deviation: 110.42 (0.433018) + kurtosis: -0.666783 + skewness: -1.15466 + entropy: 0.811278 + Image statistics: + Overall: + min: 0 (0) + max: 255 (1) + mean: 106.242 (0.416636) + standard deviation: 115.121 (0.451456) + kurtosis: -1.8309 + skewness: 0.225892 + entropy: 0.798416 + Alpha: none #00000000 + Colors: 9 + Histogram: + 10000: ( 0, 0, 0, 0) #00000000 none + 3750: ( 0, 0, 0,255) #000000FF black + 3750: ( 0, 0,192,255) #0000C0FF srgba(0,0,192,1) + 3750: ( 0,192, 0,255) #00C000FF srgba(0,192,0,1) + 3750: ( 0,192,192,255) #00C0C0FF srgba(0,192,192,1) + 3750: (192, 0, 0,255) #C00000FF srgba(192,0,0,1) + 3750: (192, 0,192,255) #C000C0FF srgba(192,0,192,1) + 3750: (192,192, 0,255) #C0C000FF srgba(192,192,0,1) + 3750: (255,255,255,255) #FFFFFFFF white + 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) + Matte color: grey74 + Background color: white + Border color: srgb(223,223,223) + Transparent color: none + Interlace: None + Intensity: Undefined + Compose: Over + Page geometry: 200x200+0+0 + Dispose: Undefined + Iterations: 0 + Compression: Zip + Orientation: Undefined + Properties: + date:create: 2023-02-25T14:53:54+10:00 + date:modify: 2023-02-25T14:53:54+10:00 + exif:BitsPerSample: 8, 8, 8 + exif:ColorSpace: 1 + exif:DateTime: 2023:02:25 14:53:47 + exif:ExifOffset: 178 + exif:ImageLength: 200 + exif:ImageWidth: 200 + exif:ResolutionUnit: 3 + exif:Software: GIMP 2.10.14 + exif:thumbnail:BitsPerSample: 8, 8, 8 + exif:thumbnail:Compression: 6 + exif:thumbnail:ImageLength: 256 + exif:thumbnail:ImageWidth: 256 + exif:thumbnail:JPEGInterchangeFormat: 304 + exif:thumbnail:JPEGInterchangeFormatLength: 1967 + exif:thumbnail:PhotometricInterpretation: 6 + exif:thumbnail:SamplesPerPixel: 3 + exif:XResolution: 567/20 + exif:YResolution: 567/20 + icc:copyright: Public Domain + icc:description: GIMP built-in sRGB + icc:manufacturer: GIMP + icc:model: sRGB + png:iCCP: chunk was found + png:IHDR.bit-depth-orig: 8 + png:IHDR.bit_depth: 8 + png:IHDR.color-type-orig: 6 + png:IHDR.color_type: 6 (RGBA) + png:IHDR.interlace_method: 0 (Not interlaced) + png:IHDR.width,height: 200, 200 + png:pHYs: x_res=2835, y_res=2835, units=1 + png:text: 1 tEXt/zTXt/iTXt chunks were found + png:text-encoded profiles: 1 were found + png:tIME: 2023-02-25T04:53:54Z + signature: f16738b3957a79aee08dc2c79048ad04744276e5f898e1c24e64bee33e5cfa0e + Profiles: + Profile-exif: 2278 bytes + Profile-icc: 672 bytes + Artifacts: + verbose: true + Tainted: False + Filesize: 1826B + Number pixels: 40000 + Pixels per second: 13.3322MB + User time: 0.031u + Elapsed time: 0:01.003 + Version: ImageMagick 7.0.6-3 Q16 x64 2017-07-24 http://www.imagemagick.org +Image: tp1-003-8bitRGB-Interlaced-withExif~ColorProfile.png + Format: PNG (Portable Network Graphics) + Mime type: image/png + Class: DirectClass + Geometry: 200x150+0+0 + Resolution: 28.35x28.35 + Print size: 7.05467x5.29101 + Units: PixelsPerCentimeter + Type: Palette + Base type: TrueColor + Endianess: Undefined + Colorspace: sRGB + Depth: 8-bit + Channel depth: + Red: 8-bit + Green: 8-bit + Blue: 8-bit + Channel statistics: + Pixels: 30000 + Red: + min: 0 (0) + max: 255 (1) + mean: 103.875 (0.407353) + standard deviation: 105.653 (0.414324) + kurtosis: -1.82802 + skewness: 0.108259 + entropy: 0.88686 + Green: + min: 0 (0) + max: 255 (1) + mean: 103.875 (0.407353) + standard deviation: 105.653 (0.414324) + kurtosis: -1.82802 + skewness: 0.108259 + entropy: 0.88686 + Blue: + min: 0 (0) + max: 255 (1) + mean: 103.875 (0.407353) + standard deviation: 105.653 (0.414324) + kurtosis: -1.82802 + skewness: 0.108259 + entropy: 0.88686 + Image statistics: + Overall: + min: 0 (0) + max: 255 (1) + mean: 103.875 (0.407353) + standard deviation: 105.651 (0.414319) + kurtosis: -1.82797 + skewness: 0.108263 + entropy: 0.88686 + Colors: 8 + Histogram: + 3750: ( 0, 0, 0) #000000 black + 3750: ( 0, 0,192) #0000C0 srgb(0,0,192) + 3750: ( 0,192, 0) #00C000 srgb(0,192,0) + 3750: ( 0,192,192) #00C0C0 srgb(0,192,192) + 3750: (192, 0, 0) #C00000 srgb(192,0,0) + 3750: (192, 0,192) #C000C0 srgb(192,0,192) + 3750: (192,192, 0) #C0C000 srgb(192,192,0) + 3750: (255,255,255) #FFFFFF white + 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) + Matte color: grey74 + Background color: white + Border color: srgb(223,223,223) + Transparent color: none + Interlace: PNG + Intensity: Undefined + Compose: Over + Page geometry: 200x150+0+0 + Dispose: Undefined + Iterations: 0 + Compression: Zip + Orientation: Undefined + Properties: + date:create: 2023-02-25T14:56:25+10:00 + date:modify: 2023-02-25T14:56:25+10:00 + exif:BitsPerSample: 8, 8, 8 + exif:ColorSpace: 1 + exif:DateTime: 2023:02:25 14:56:19 + exif:ExifOffset: 178 + exif:ImageLength: 150 + exif:ImageWidth: 200 + exif:ResolutionUnit: 3 + exif:Software: GIMP 2.10.14 + exif:XResolution: 567/20 + exif:YResolution: 567/20 + icc:copyright: Public Domain + icc:description: GIMP built-in sRGB + icc:manufacturer: GIMP + icc:model: sRGB + png:iCCP: chunk was found + 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: 1 (Adam7 method) + png:IHDR.width,height: 200, 150 + png:pHYs: x_res=2835, y_res=2835, units=1 + png:text: 1 tEXt/zTXt/iTXt chunks were found + png:text-encoded profiles: 1 were found + png:tIME: 2023-02-25T04:56:25Z + signature: e45c14eb01b14647136b13db711568054884aca01761562d19c27206d5cc03c1 + Profiles: + Profile-exif: 202 bytes + Profile-icc: 672 bytes + Artifacts: + verbose: true + Tainted: False + Filesize: 1229B + Number pixels: 30000 + Pixels per second: 10.0055MB + User time: 0.000u + Elapsed time: 0:01.002 + Version: ImageMagick 7.0.6-3 Q16 x64 2017-07-24 http://www.imagemagick.org +Image: tp1-003-8bitRGB-Interlaced.png + Format: PNG (Portable Network Graphics) + Mime type: image/png + Class: DirectClass + Geometry: 200x150+0+0 + Resolution: 28.35x28.35 + Print size: 7.05467x5.29101 + Units: PixelsPerCentimeter + Type: Palette + Base type: TrueColor + Endianess: Undefined + Colorspace: sRGB + Depth: 8-bit + Channel depth: + Red: 8-bit + Green: 8-bit + Blue: 8-bit + Channel statistics: + Pixels: 30000 + Red: + min: 0 (0) + max: 255 (1) + mean: 103.875 (0.407353) + standard deviation: 105.653 (0.414324) + kurtosis: -1.82802 + skewness: 0.108259 + entropy: 0.88686 + Green: + min: 0 (0) + max: 255 (1) + mean: 103.875 (0.407353) + standard deviation: 105.653 (0.414324) + kurtosis: -1.82802 + skewness: 0.108259 + entropy: 0.88686 + Blue: + min: 0 (0) + max: 255 (1) + mean: 103.875 (0.407353) + standard deviation: 105.653 (0.414324) + kurtosis: -1.82802 + skewness: 0.108259 + entropy: 0.88686 + Image statistics: + Overall: + min: 0 (0) + max: 255 (1) + mean: 103.875 (0.407353) + standard deviation: 105.651 (0.414319) + kurtosis: -1.82797 + skewness: 0.108263 + entropy: 0.88686 + Colors: 8 + Histogram: + 3750: ( 0, 0, 0) #000000 black + 3750: ( 0, 0,192) #0000C0 srgb(0,0,192) + 3750: ( 0,192, 0) #00C000 srgb(0,192,0) + 3750: ( 0,192,192) #00C0C0 srgb(0,192,192) + 3750: (192, 0, 0) #C00000 srgb(192,0,0) + 3750: (192, 0,192) #C000C0 srgb(192,0,192) + 3750: (192,192, 0) #C0C000 srgb(192,192,0) + 3750: (255,255,255) #FFFFFF white + 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) + Matte color: grey74 + Background color: white + Border color: srgb(223,223,223) + Transparent color: none + Interlace: PNG + Intensity: Undefined + Compose: Over + Page geometry: 200x150+0+0 + Dispose: Undefined + Iterations: 0 + Compression: Zip + Orientation: Undefined + Properties: + date:create: 2023-02-25T14:55:13+10:00 + date:modify: 2023-02-25T14:55:13+10:00 + exif:BitsPerSample: 8, 8, 8 + exif:ColorSpace: 1 + exif:DateTime: 2023:02:25 14:55:10 + exif:ExifOffset: 178 + exif:ImageLength: 150 + exif:ImageWidth: 200 + exif:ResolutionUnit: 3 + exif:Software: GIMP 2.10.14 + exif:thumbnail:BitsPerSample: 8, 8, 8 + exif:thumbnail:Compression: 6 + exif:thumbnail:ImageLength: 192 + exif:thumbnail:ImageWidth: 256 + exif:thumbnail:JPEGInterchangeFormat: 304 + exif:thumbnail:JPEGInterchangeFormatLength: 1711 + exif:thumbnail:PhotometricInterpretation: 6 + exif:thumbnail:SamplesPerPixel: 3 + exif:XResolution: 567/20 + exif:YResolution: 567/20 + icc:copyright: Public Domain + icc:description: GIMP built-in sRGB + icc:manufacturer: GIMP + icc:model: sRGB + png:iCCP: chunk was found + 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: 1 (Adam7 method) + png:IHDR.width,height: 200, 150 + png:pHYs: x_res=2835, y_res=2835, units=1 + png:text: 1 tEXt/zTXt/iTXt chunks were found + png:text-encoded profiles: 1 were found + png:tIME: 2023-02-25T04:55:13Z + signature: e45c14eb01b14647136b13db711568054884aca01761562d19c27206d5cc03c1 + Profiles: + Profile-exif: 2022 bytes + Profile-icc: 672 bytes + Artifacts: + verbose: true + Tainted: False + Filesize: 1972B + Number pixels: 30000 + Pixels per second: 14.9939MB + User time: 0.000u + Elapsed time: 0:01.002 + Version: ImageMagick 7.0.6-3 Q16 x64 2017-07-24 http://www.imagemagick.org +Image: tp1-100-16bitRGB-withExif~Thumbnail~ColorProfile.png + Format: PNG (Portable Network Graphics) + Mime type: image/png + Class: DirectClass + Geometry: 200x150+0+0 + Resolution: 72x72 + Print size: 2.77778x2.08333 + Units: PixelsPerInch + Type: Palette + Base type: TrueColor + Endianess: Undefined + Colorspace: sRGB + Depth: 16/11-bit + Channel depth: + Red: 11-bit + Green: 11-bit + Blue: 11-bit + Channel statistics: + Pixels: 30000 + Red: + min: 0 (0) + max: 65535 (1) + mean: 21145.9 (0.322665) + standard deviation: 23177.7 (0.35367) + kurtosis: -0.930082 + skewness: 0.570806 + entropy: 0.88686 + Green: + min: 0 (0) + max: 65535 (1) + mean: 21145.9 (0.322665) + standard deviation: 23177.7 (0.35367) + kurtosis: -0.930082 + skewness: 0.570806 + entropy: 0.88686 + Blue: + min: 0 (0) + max: 65535 (1) + mean: 21145.9 (0.322665) + standard deviation: 23177.7 (0.35367) + kurtosis: -0.930082 + skewness: 0.570806 + entropy: 0.88686 + Image statistics: + Overall: + min: 0 (0) + max: 65535 (1) + mean: 21145.9 (0.322665) + standard deviation: 23177.5 (0.353666) + kurtosis: -0.92999 + skewness: 0.570825 + entropy: 0.88686 + Colors: 8 + Histogram: + 3750: ( 0, 0, 0) #000000000000 black + 3750: ( 0, 0,34544) #0000000086F0 srgb(0%,0%,53%) + 3750: ( 0,34544, 0) #000086F00000 srgb(0%,53%,0%) + 3750: ( 0,34544,34544) #000086F086F0 srgb(0%,53%,53%) + 3750: (34544, 0, 0) #86F000000000 srgb(53%,0%,0%) + 3750: (34544, 0,34544) #86F0000086F0 srgb(53%,0%,53%) + 3750: (34544,34544, 0) #86F086F00000 srgb(53%,53%,0%) + 3750: (65535,65535,65535) #FFFFFFFFFFFF white + 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) + Matte color: grey74 + Background color: white + Border color: srgb(223,223,223) + Transparent color: none + Interlace: None + Intensity: Undefined + Compose: Over + Page geometry: 200x150+0+0 + Dispose: Undefined + Iterations: 0 + Compression: Zip + Orientation: Undefined + Properties: + date:create: 2023-02-25T14:45:50+10:00 + date:modify: 2023-02-25T14:45:50+10:00 + exif:BitsPerSample: 8, 8, 8 + exif:ColorSpace: 1 + exif:DateTime: 2023:02:25 14:45:45 + exif:ExifOffset: 178 + exif:ImageLength: 150 + exif:ImageWidth: 200 + exif:ResolutionUnit: 2 + exif:Software: GIMP 2.10.14 + exif:thumbnail:BitsPerSample: 8, 8, 8 + exif:thumbnail:Compression: 6 + exif:thumbnail:ImageLength: 192 + exif:thumbnail:ImageWidth: 256 + exif:thumbnail:JPEGInterchangeFormat: 304 + exif:thumbnail:JPEGInterchangeFormatLength: 1686 + exif:thumbnail:PhotometricInterpretation: 6 + exif:thumbnail:SamplesPerPixel: 3 + exif:XResolution: 72/1 + exif:YResolution: 72/1 + icc:copyright: Public Domain + icc:description: GIMP built-in Linear sRGB + icc:manufacturer: GIMP + icc:model: Linear sRGB + png:iCCP: chunk was found + 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: 200, 150 + png:pHYs: x_res=2835, y_res=2835, units=1 + png:text: 1 tEXt/zTXt/iTXt chunks were found + png:text-encoded profiles: 1 were found + png:tIME: 2023-02-25T04:45:50Z + signature: a28b14b0fdf5e2981eeebfd1aad71ca85ee9496e53725e59374f801acce37c7c + Profiles: + Profile-exif: 1996 bytes + Profile-icc: 688 bytes + Artifacts: + verbose: true + Tainted: False + Filesize: 1973B + Number pixels: 30000 + Pixels per second: 10.0055MB + User time: 0.000u + Elapsed time: 0:01.002 + Version: ImageMagick 7.0.6-3 Q16 x64 2017-07-24 http://www.imagemagick.org +Image: tp1-200-32bitRGB-withExif~Thumbnail~ColorProfile.png + Format: PNG (Portable Network Graphics) + Mime type: image/png + Class: DirectClass + Geometry: 200x150+0+0 + Resolution: 72x72 + Print size: 2.77778x2.08333 + Units: PixelsPerInch + Type: Palette + Base type: TrueColor + Endianess: Undefined + Colorspace: sRGB + Depth: 16/11-bit + Channel depth: + Red: 11-bit + Green: 11-bit + Blue: 11-bit + Channel statistics: + Pixels: 30000 + Red: + min: 0 (0) + max: 65535 (1) + mean: 21145.9 (0.322665) + standard deviation: 23177.7 (0.35367) + kurtosis: -0.930082 + skewness: 0.570806 + entropy: 0.88686 + Green: + min: 0 (0) + max: 65535 (1) + mean: 21145.9 (0.322665) + standard deviation: 23177.7 (0.35367) + kurtosis: -0.930082 + skewness: 0.570806 + entropy: 0.88686 + Blue: + min: 0 (0) + max: 65535 (1) + mean: 21145.9 (0.322665) + standard deviation: 23177.7 (0.35367) + kurtosis: -0.930082 + skewness: 0.570806 + entropy: 0.88686 + Image statistics: + Overall: + min: 0 (0) + max: 65535 (1) + mean: 21145.9 (0.322665) + standard deviation: 23177.5 (0.353666) + kurtosis: -0.92999 + skewness: 0.570825 + entropy: 0.88686 + Colors: 8 + Histogram: + 3750: ( 0, 0, 0) #000000000000 black + 3750: ( 0, 0,34544) #0000000086F0 srgb(0%,0%,53%) + 3750: ( 0,34544, 0) #000086F00000 srgb(0%,53%,0%) + 3750: ( 0,34544,34544) #000086F086F0 srgb(0%,53%,53%) + 3750: (34544, 0, 0) #86F000000000 srgb(53%,0%,0%) + 3750: (34544, 0,34544) #86F0000086F0 srgb(53%,0%,53%) + 3750: (34544,34544, 0) #86F086F00000 srgb(53%,53%,0%) + 3750: (65535,65535,65535) #FFFFFFFFFFFF white + 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) + Matte color: grey74 + Background color: white + Border color: srgb(223,223,223) + Transparent color: none + Interlace: None + Intensity: Undefined + Compose: Over + Page geometry: 200x150+0+0 + Dispose: Undefined + Iterations: 0 + Compression: Zip + Orientation: Undefined + Properties: + date:create: 2023-02-25T14:46:29+10:00 + date:modify: 2023-02-25T14:46:29+10:00 + exif:BitsPerSample: 8, 8, 8 + exif:ColorSpace: 1 + exif:DateTime: 2023:02:25 14:46:26 + exif:ExifOffset: 178 + exif:ImageLength: 150 + exif:ImageWidth: 200 + exif:ResolutionUnit: 2 + exif:Software: GIMP 2.10.14 + exif:thumbnail:BitsPerSample: 8, 8, 8 + exif:thumbnail:Compression: 6 + exif:thumbnail:ImageLength: 192 + exif:thumbnail:ImageWidth: 256 + exif:thumbnail:JPEGInterchangeFormat: 304 + exif:thumbnail:JPEGInterchangeFormatLength: 1686 + exif:thumbnail:PhotometricInterpretation: 6 + exif:thumbnail:SamplesPerPixel: 3 + exif:XResolution: 72/1 + exif:YResolution: 72/1 + icc:copyright: Public Domain + icc:description: GIMP built-in Linear sRGB + icc:manufacturer: GIMP + icc:model: Linear sRGB + png:iCCP: chunk was found + 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: 200, 150 + png:pHYs: x_res=2835, y_res=2835, units=1 + png:text: 1 tEXt/zTXt/iTXt chunks were found + png:text-encoded profiles: 1 were found + png:tIME: 2023-02-25T04:46:29Z + signature: a28b14b0fdf5e2981eeebfd1aad71ca85ee9496e53725e59374f801acce37c7c + Profiles: + Profile-exif: 1996 bytes + Profile-icc: 688 bytes + Artifacts: + verbose: true + Tainted: False + Filesize: 1973B + Number pixels: 30000 + Pixels per second: 14.9939MB + User time: 0.000u + Elapsed time: 0:01.002 + Version: ImageMagick 7.0.6-3 Q16 x64 2017-07-24 http://www.imagemagick.org +Image: tp1-300-16bitFloatRGB-withExif~Thumbnail~ColorProfile.png + Format: PNG (Portable Network Graphics) + Mime type: image/png + Class: DirectClass + Geometry: 200x150+0+0 + Resolution: 72x72 + Print size: 2.77778x2.08333 + Units: PixelsPerInch + Type: Palette + Base type: TrueColor + Endianess: Undefined + Colorspace: sRGB + Depth: 16/15-bit + Channel depth: + Red: 15-bit + Green: 15-bit + Blue: 15-bit + Channel statistics: + Pixels: 30000 + Red: + min: 0 (0) + max: 65535 (1) + mean: 21151.5 (0.322751) + standard deviation: 23181 (0.353719) + kurtosis: -0.931609 + skewness: 0.570082 + entropy: 0.88686 + Green: + min: 0 (0) + max: 65535 (1) + mean: 21151.5 (0.322751) + standard deviation: 23181 (0.353719) + kurtosis: -0.931609 + skewness: 0.570082 + entropy: 0.88686 + Blue: + min: 0 (0) + max: 65535 (1) + mean: 21151.5 (0.322751) + standard deviation: 23181 (0.353719) + kurtosis: -0.931609 + skewness: 0.570082 + entropy: 0.88686 + Image statistics: + Overall: + min: 0 (0) + max: 65535 (1) + mean: 21151.5 (0.322751) + standard deviation: 23180.7 (0.353715) + kurtosis: -0.931517 + skewness: 0.570101 + entropy: 0.88686 + Colors: 8 + Histogram: + 3750: ( 0, 0, 0) #000000000000 black + 3750: ( 0, 0,34559) #0000000086FF srgb(0%,0%,53%) + 3750: ( 0,34559, 0) #000086FF0000 srgb(0%,53%,0%) + 3750: ( 0,34559,34559) #000086FF86FF srgb(0%,53%,53%) + 3750: (34559, 0, 0) #86FF00000000 srgb(53%,0%,0%) + 3750: (34559, 0,34559) #86FF000086FF srgb(53%,0%,53%) + 3750: (34559,34559, 0) #86FF86FF0000 srgb(53%,53%,0%) + 3750: (65535,65535,65535) #FFFFFFFFFFFF white + 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) + Matte color: grey74 + Background color: white + Border color: srgb(223,223,223) + Transparent color: none + Interlace: None + Intensity: Undefined + Compose: Over + Page geometry: 200x150+0+0 + Dispose: Undefined + Iterations: 0 + Compression: Zip + Orientation: Undefined + Properties: + date:create: 2023-02-25T14:50:44+10:00 + date:modify: 2023-02-25T14:50:44+10:00 + exif:BitsPerSample: 8, 8, 8 + exif:ColorSpace: 1 + exif:DateTime: 2023:02:25 14:50:40 + exif:ExifOffset: 178 + exif:ImageLength: 150 + exif:ImageWidth: 200 + exif:ResolutionUnit: 2 + exif:Software: GIMP 2.10.14 + exif:thumbnail:BitsPerSample: 8, 8, 8 + exif:thumbnail:Compression: 6 + exif:thumbnail:ImageLength: 192 + exif:thumbnail:ImageWidth: 256 + exif:thumbnail:JPEGInterchangeFormat: 304 + exif:thumbnail:JPEGInterchangeFormatLength: 1686 + exif:thumbnail:PhotometricInterpretation: 6 + exif:thumbnail:SamplesPerPixel: 3 + exif:XResolution: 72/1 + exif:YResolution: 72/1 + icc:copyright: Public Domain + icc:description: GIMP built-in Linear sRGB + icc:manufacturer: GIMP + icc:model: Linear sRGB + png:iCCP: chunk was found + 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: 200, 150 + png:pHYs: x_res=2835, y_res=2835, units=1 + png:text: 1 tEXt/zTXt/iTXt chunks were found + png:text-encoded profiles: 1 were found + png:tIME: 2023-02-25T04:50:44Z + signature: d2d376d22936afa78422b676f4a220aa31a85ab28c335f02c92f078e51ea863f + Profiles: + Profile-exif: 1996 bytes + Profile-icc: 688 bytes + Artifacts: + verbose: true + Tainted: False + Filesize: 1970B + Number pixels: 30000 + Pixels per second: 14.9939MB + User time: 0.000u + Elapsed time: 0:01.002 + Version: ImageMagick 7.0.6-3 Q16 x64 2017-07-24 http://www.imagemagick.org +Image: tp1-400-32bitFloatRGB-withExif~Thumbnail~ColorProfile.png + Format: PNG (Portable Network Graphics) + Mime type: image/png + Class: DirectClass + Geometry: 200x150+0+0 + Resolution: 72x72 + Print size: 2.77778x2.08333 + Units: PixelsPerInch + Type: Palette + Base type: TrueColor + Endianess: Undefined + Colorspace: sRGB + Depth: 16/15-bit + Channel depth: + Red: 15-bit + Green: 15-bit + Blue: 15-bit + Channel statistics: + Pixels: 30000 + Red: + min: 0 (0) + max: 65535 (1) + mean: 21151.5 (0.322751) + standard deviation: 23181 (0.353719) + kurtosis: -0.931609 + skewness: 0.570082 + entropy: 0.88686 + Green: + min: 0 (0) + max: 65535 (1) + mean: 21151.5 (0.322751) + standard deviation: 23181 (0.353719) + kurtosis: -0.931609 + skewness: 0.570082 + entropy: 0.88686 + Blue: + min: 0 (0) + max: 65535 (1) + mean: 21151.5 (0.322751) + standard deviation: 23181 (0.353719) + kurtosis: -0.931609 + skewness: 0.570082 + entropy: 0.88686 + Image statistics: + Overall: + min: 0 (0) + max: 65535 (1) + mean: 21151.5 (0.322751) + standard deviation: 23180.7 (0.353715) + kurtosis: -0.931517 + skewness: 0.570101 + entropy: 0.88686 + Colors: 8 + Histogram: + 3750: ( 0, 0, 0) #000000000000 black + 3750: ( 0, 0,34559) #0000000086FF srgb(0%,0%,53%) + 3750: ( 0,34559, 0) #000086FF0000 srgb(0%,53%,0%) + 3750: ( 0,34559,34559) #000086FF86FF srgb(0%,53%,53%) + 3750: (34559, 0, 0) #86FF00000000 srgb(53%,0%,0%) + 3750: (34559, 0,34559) #86FF000086FF srgb(53%,0%,53%) + 3750: (34559,34559, 0) #86FF86FF0000 srgb(53%,53%,0%) + 3750: (65535,65535,65535) #FFFFFFFFFFFF white + 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) + Matte color: grey74 + Background color: white + Border color: srgb(223,223,223) + Transparent color: none + Interlace: None + Intensity: Undefined + Compose: Over + Page geometry: 200x150+0+0 + Dispose: Undefined + Iterations: 0 + Compression: Zip + Orientation: Undefined + Properties: + date:create: 2023-02-25T14:51:49+10:00 + date:modify: 2023-02-25T14:51:49+10:00 + exif:BitsPerSample: 8, 8, 8 + exif:ColorSpace: 1 + exif:DateTime: 2023:02:25 14:51:47 + exif:ExifOffset: 178 + exif:ImageLength: 150 + exif:ImageWidth: 200 + exif:ResolutionUnit: 2 + exif:Software: GIMP 2.10.14 + exif:thumbnail:BitsPerSample: 8, 8, 8 + exif:thumbnail:Compression: 6 + exif:thumbnail:ImageLength: 192 + exif:thumbnail:ImageWidth: 256 + exif:thumbnail:JPEGInterchangeFormat: 304 + exif:thumbnail:JPEGInterchangeFormatLength: 1686 + exif:thumbnail:PhotometricInterpretation: 6 + exif:thumbnail:SamplesPerPixel: 3 + exif:XResolution: 72/1 + exif:YResolution: 72/1 + icc:copyright: Public Domain + icc:description: GIMP built-in Linear sRGB + icc:manufacturer: GIMP + icc:model: Linear sRGB + png:iCCP: chunk was found + 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: 200, 150 + png:pHYs: x_res=2835, y_res=2835, units=1 + png:text: 1 tEXt/zTXt/iTXt chunks were found + png:text-encoded profiles: 1 were found + png:tIME: 2023-02-25T04:51:49Z + signature: d2d376d22936afa78422b676f4a220aa31a85ab28c335f02c92f078e51ea863f + Profiles: + Profile-exif: 1996 bytes + Profile-icc: 688 bytes + Artifacts: + verbose: true + Tainted: False + Filesize: 1970B + Number pixels: 30000 + Pixels per second: 14.9939MB + User time: 0.000u + Elapsed time: 0:01.002 + Version: ImageMagick 7.0.6-3 Q16 x64 2017-07-24 http://www.imagemagick.org diff --git a/src/UglyToad.PdfPig.Tests/Images/Files/Png/TestPattern1/tp1-001-8bitRGB-withExif~Thumbnail~ColorProfile.png b/src/UglyToad.PdfPig.Tests/Images/Files/Png/TestPattern1/tp1-001-8bitRGB-withExif~Thumbnail~ColorProfile.png new file mode 100644 index 00000000..d999b7ef Binary files /dev/null and b/src/UglyToad.PdfPig.Tests/Images/Files/Png/TestPattern1/tp1-001-8bitRGB-withExif~Thumbnail~ColorProfile.png differ diff --git a/src/UglyToad.PdfPig.Tests/Images/Files/Png/TestPattern1/tp1-002-8bitRGBA-withExif~Thumbnail~ColorProfile.png b/src/UglyToad.PdfPig.Tests/Images/Files/Png/TestPattern1/tp1-002-8bitRGBA-withExif~Thumbnail~ColorProfile.png new file mode 100644 index 00000000..8408a8f3 Binary files /dev/null and b/src/UglyToad.PdfPig.Tests/Images/Files/Png/TestPattern1/tp1-002-8bitRGBA-withExif~Thumbnail~ColorProfile.png differ diff --git a/src/UglyToad.PdfPig.Tests/Images/Files/Png/TestPattern1/tp1-003-8bitRGB-Interlaced-withExif~ColorProfile.png b/src/UglyToad.PdfPig.Tests/Images/Files/Png/TestPattern1/tp1-003-8bitRGB-Interlaced-withExif~ColorProfile.png new file mode 100644 index 00000000..7ce8647c Binary files /dev/null and b/src/UglyToad.PdfPig.Tests/Images/Files/Png/TestPattern1/tp1-003-8bitRGB-Interlaced-withExif~ColorProfile.png differ diff --git a/src/UglyToad.PdfPig.Tests/Images/Files/Png/TestPattern1/tp1-004-8bitRGBA-Interlaced-withExif~ColorProfile.png b/src/UglyToad.PdfPig.Tests/Images/Files/Png/TestPattern1/tp1-004-8bitRGBA-Interlaced-withExif~ColorProfile.png new file mode 100644 index 00000000..cd3d5612 Binary files /dev/null and b/src/UglyToad.PdfPig.Tests/Images/Files/Png/TestPattern1/tp1-004-8bitRGBA-Interlaced-withExif~ColorProfile.png differ diff --git a/src/UglyToad.PdfPig.Tests/Images/Files/Png/TestPattern1/tp1-101-16bitRGB-withExif~Thumbnail~ColorProfile.png b/src/UglyToad.PdfPig.Tests/Images/Files/Png/TestPattern1/tp1-101-16bitRGB-withExif~Thumbnail~ColorProfile.png new file mode 100644 index 00000000..2f6c96e8 Binary files /dev/null and b/src/UglyToad.PdfPig.Tests/Images/Files/Png/TestPattern1/tp1-101-16bitRGB-withExif~Thumbnail~ColorProfile.png differ diff --git a/src/UglyToad.PdfPig.Tests/Images/Files/Png/TestPattern1/tp1-102-16bitRGBA-withExif~Thumbnail~ColorProfile.png b/src/UglyToad.PdfPig.Tests/Images/Files/Png/TestPattern1/tp1-102-16bitRGBA-withExif~Thumbnail~ColorProfile.png new file mode 100644 index 00000000..db91e34c Binary files /dev/null and b/src/UglyToad.PdfPig.Tests/Images/Files/Png/TestPattern1/tp1-102-16bitRGBA-withExif~Thumbnail~ColorProfile.png differ diff --git a/src/UglyToad.PdfPig.Tests/Images/Files/Png/TestPattern1/tp1-201-32bitRGB-withExif~Thumbnail~ColorProfile.png b/src/UglyToad.PdfPig.Tests/Images/Files/Png/TestPattern1/tp1-201-32bitRGB-withExif~Thumbnail~ColorProfile.png new file mode 100644 index 00000000..bf98e176 Binary files /dev/null and b/src/UglyToad.PdfPig.Tests/Images/Files/Png/TestPattern1/tp1-201-32bitRGB-withExif~Thumbnail~ColorProfile.png differ diff --git a/src/UglyToad.PdfPig.Tests/Images/Files/Png/TestPattern1/tp1-301-16bitFloatRGB-withExif~Thumbnail~ColorProfile.png b/src/UglyToad.PdfPig.Tests/Images/Files/Png/TestPattern1/tp1-301-16bitFloatRGB-withExif~Thumbnail~ColorProfile.png new file mode 100644 index 00000000..9503aa7e Binary files /dev/null and b/src/UglyToad.PdfPig.Tests/Images/Files/Png/TestPattern1/tp1-301-16bitFloatRGB-withExif~Thumbnail~ColorProfile.png differ diff --git a/src/UglyToad.PdfPig.Tests/Images/Files/Png/TestPattern1/tp1-401-32bitFloatRGB-withExif~Thumbnail~ColorProfile.png b/src/UglyToad.PdfPig.Tests/Images/Files/Png/TestPattern1/tp1-401-32bitFloatRGB-withExif~Thumbnail~ColorProfile.png new file mode 100644 index 00000000..68166faa Binary files /dev/null and b/src/UglyToad.PdfPig.Tests/Images/Files/Png/TestPattern1/tp1-401-32bitFloatRGB-withExif~Thumbnail~ColorProfile.png differ diff --git a/src/UglyToad.PdfPig.Tests/Writer/PdfPageBuilderTests.cs b/src/UglyToad.PdfPig.Tests/Writer/PdfPageBuilderTests.cs new file mode 100644 index 00000000..f93b5f3c --- /dev/null +++ b/src/UglyToad.PdfPig.Tests/Writer/PdfPageBuilderTests.cs @@ -0,0 +1,269 @@ +namespace UglyToad.PdfPig.Tests.Images +{ + using System; + using System.IO; + using System.Linq; + using UglyToad.PdfPig; + using UglyToad.PdfPig.Content; + using UglyToad.PdfPig.Core; + using UglyToad.PdfPig.Fonts.Standard14Fonts; + using UglyToad.PdfPig.Writer; + using Xunit; + + public class PdfPageBuilderTests + { + + + [Fact] + public void CanAddPng() + { + byte[] pdfBytes; + using (var pdfBuilder = new PdfDocumentBuilder()) + { + pdfBuilder.AddStandard14Font(Standard14Font.Courier); + { + var page1 = pdfBuilder.AddPage(595d, 842d); // A4 + var dataPNG = LoadPng("1-16bitRGBA-Issue550.png"); + page1.AddPng(dataPNG, new PdfRectangle(0, 0, 595, 842)); + } + { + var page2 = pdfBuilder.AddPage(595d, 842d); // A4 + var dataPNG = LoadPng("2-16bitRGB.png"); + page2.AddPng(dataPNG, new PdfRectangle(0, 0, 595, 842)); + } + { + var page3 = pdfBuilder.AddPage(595d, 842d); // A4 + var dataPNG = LoadPng("3-16bitGray.png"); + page3.AddPng(dataPNG, new PdfRectangle(0, 0, 595, 842)); + } + + { + var page4 = pdfBuilder.AddPage(595d, 842d); // A4 + var dataPNG = LoadPng("4-16bitRGBA.png"); + page4.AddPng(dataPNG, new PdfRectangle(0, 0, 595, 842)); + } + pdfBytes = pdfBuilder.Build(); + } + + + File.WriteAllBytes(@"PdfPageBuilderTests_CanAddPng.pdf", pdfBytes); + + using (var doc = PdfDocument.Open(pdfBytes)) + { + var numberOfPages = doc.NumberOfPages; + Assert.Equal(4, numberOfPages); + + // Page 1 - Image 1 + { + var page = doc.GetPage(1); + var image1 = page.GetImages().FirstOrDefault(); + + Assert.Equal(1170, image1.WidthInSamples); + Assert.Equal(2532, image1.HeightInSamples); + Assert.Equal(8, image1.BitsPerComponent); + } + + // Page 2 - Image 2 + { + var page = doc.GetPage(2); + var image1 = page.GetImages().FirstOrDefault(); + + Assert.Equal(900, image1.WidthInSamples); + Assert.Equal(900, image1.HeightInSamples); + Assert.Equal(8, image1.BitsPerComponent); + } + + // Page 3 - Image 3 + { + var page = doc.GetPage(3); + var image1 = page.GetImages().FirstOrDefault(); + + Assert.Equal(900, image1.WidthInSamples); + Assert.Equal(900, image1.HeightInSamples); + Assert.Equal(8, image1.BitsPerComponent); + } + + // Page 4 - Image 4 + { + var page = doc.GetPage(4); + var image1 = page.GetImages().FirstOrDefault(); + + Assert.Equal(900, image1.WidthInSamples); + Assert.Equal(900, image1.HeightInSamples); + Assert.Equal(8, image1.BitsPerComponent); + } + } + + + + + } + + + [Fact] + public void CanAddPngTestPattern1() + { + const string subfolderName = "TestPattern1"; + byte[] pdfBytes; + + using (var pdfBuilder = new PdfDocumentBuilder()) + { + var courierFont = pdfBuilder.AddStandard14Font(Standard14Font.Courier); + + AddPageWithImage(pdfBuilder, subfolderName, "tp1-001-8bitRGB-withExif~Thumbnail~ColorProfile.png", 150, courierFont); + AddPageWithImage(pdfBuilder, subfolderName, "tp1-002-8bitRGBA-withExif~Thumbnail~ColorProfile.png", 200, courierFont); + AddPageWithImage(pdfBuilder, subfolderName, "tp1-003-8bitRGB-Interlaced-withExif~ColorProfile.png", 150, courierFont); + AddPageWithImage(pdfBuilder, subfolderName, "tp1-004-8bitRGBA-Interlaced-withExif~ColorProfile.png", 200, courierFont); + + + AddPageWithImage(pdfBuilder, subfolderName, "tp1-101-16bitRGB-withExif~Thumbnail~ColorProfile.png", 150, courierFont); + AddPageWithImage(pdfBuilder, subfolderName, "tp1-102-16bitRGBA-withExif~Thumbnail~ColorProfile.png", 200, courierFont); + + AddPageWithImage(pdfBuilder, subfolderName, "tp1-201-32bitRGB-withExif~Thumbnail~ColorProfile.png", 150, courierFont); + + AddPageWithImage(pdfBuilder, subfolderName, "tp1-301-16bitFloatRGB-withExif~Thumbnail~ColorProfile.png", 150, courierFont); + + AddPageWithImage(pdfBuilder, subfolderName, "tp1-401-32bitFloatRGB-withExif~Thumbnail~ColorProfile.png", 150, courierFont); + + + pdfBytes = pdfBuilder.Build(); + } + + var outputFolder = Environment.CurrentDirectory; + File.WriteAllBytes(@"PdfPageBuilderTests_CanAddPngTestPattern1.pdf", pdfBytes); + + using (var doc = PdfDocument.Open(pdfBytes)) + { + var numberOfPages = doc.NumberOfPages; + Assert.Equal(9, numberOfPages); + + // Page 1 - Image 1 + { + var page = doc.GetPage(6); + var image1 = page.GetImages().FirstOrDefault(); + + Assert.Equal(200, image1.WidthInSamples); + Assert.Equal(200, image1.HeightInSamples); + Assert.Equal(8, image1.BitsPerComponent); + } + + // Page 2 - Image 2 + { + var page = doc.GetPage(2); + var image1 = page.GetImages().FirstOrDefault(); + + Assert.Equal(200, image1.WidthInSamples); + Assert.Equal(200, image1.HeightInSamples); + Assert.Equal(8, image1.BitsPerComponent); + } + + // Page 3 - Image 3 + { + var page = doc.GetPage(3); + var image1 = page.GetImages().FirstOrDefault(); + + Assert.Equal(200, image1.WidthInSamples); + Assert.Equal(150, image1.HeightInSamples); + Assert.Equal(8, image1.BitsPerComponent); + } + + // Page 4 - Image 4 + { + var page = doc.GetPage(4); + var image1 = page.GetImages().FirstOrDefault(); + + Assert.Equal(200, image1.WidthInSamples); + Assert.Equal(200, image1.HeightInSamples); + Assert.Equal(8, image1.BitsPerComponent); + } + + // Page 5 - Image 5 + { + var page = doc.GetPage(5); + var image1 = page.GetImages().FirstOrDefault(); + + Assert.Equal(200, image1.WidthInSamples); + Assert.Equal(150, image1.HeightInSamples); + Assert.Equal(8, image1.BitsPerComponent); + } + + // Page 6 - Image 6 + { + var page = doc.GetPage(6); + var image1 = page.GetImages().FirstOrDefault(); + + Assert.Equal(200, image1.WidthInSamples); + Assert.Equal(200, image1.HeightInSamples); + Assert.Equal(8, image1.BitsPerComponent); + } + + // Page 7 - Image 7 + { + var page = doc.GetPage(7); + var image1 = page.GetImages().FirstOrDefault(); + + Assert.Equal(200, image1.WidthInSamples); + Assert.Equal(150, image1.HeightInSamples); + Assert.Equal(8, image1.BitsPerComponent); + } + + // Page 8 - Image 8 + { + var page = doc.GetPage(8); + var image1 = page.GetImages().FirstOrDefault(); + + Assert.Equal(200, image1.WidthInSamples); + Assert.Equal(150, image1.HeightInSamples); + Assert.Equal(8, image1.BitsPerComponent); + } + + // Page 9 - Image 9 + { + var page = doc.GetPage(9); + var image1 = page.GetImages().FirstOrDefault(); + + Assert.Equal(200, image1.WidthInSamples); + Assert.Equal(150, image1.HeightInSamples); + Assert.Equal(8, image1.BitsPerComponent); + } + } + + + + + } + + private static void AddPageWithImage(PdfDocumentBuilder pdfBuilder, string subfolderName, string imageFileName, double imageHeight, PdfDocumentBuilder.AddedFont font) + { + + var imageMargin = 20d; + var imageBottom = 842d - 600d; + + //var imagePlacement = new PdfRectangle(0, imageTop, 595d, imageTop - imageHeight); + + var imagePlacement = new PdfRectangle(0, imageBottom, 595d, 842d); + var borderPlacement = new PdfPoint(imagePlacement.BottomLeft.X, imagePlacement.BottomLeft.Y); + var labelPlacement = new PdfPoint(50, imagePlacement.BottomLeft.Y - 50); + + var page = pdfBuilder.AddPage(595d, 842d); // A4 + var dataPNG = LoadPng(imageFileName, subfolderName); + page.DrawRectangle(borderPlacement, (decimal)imagePlacement.Width, (decimal)imagePlacement.Height, 3, true); + page.AddPng(dataPNG, imagePlacement); + page.AddText(imageFileName, 12m, labelPlacement, font); + } + + private static byte[] LoadPng(string name, string subfolderName = null) + { + var baseFolder = Path.GetFullPath(AppDomain.CurrentDomain.BaseDirectory); + var PngFilesFolder = Path.Combine(baseFolder, "..", "..", "..", "Images", "Files", "Png"); + if (subfolderName is not null) + { + PngFilesFolder = Path.Combine(PngFilesFolder,subfolderName); + } + var PngFilePath = Path.Combine(PngFilesFolder, name); + return File.ReadAllBytes(PngFilePath); + } + + + } +} diff --git a/src/UglyToad.PdfPig/Images/Png/RawPngData.cs b/src/UglyToad.PdfPig/Images/Png/RawPngData.cs index f884ca72..68754d95 100644 --- a/src/UglyToad.PdfPig/Images/Png/RawPngData.cs +++ b/src/UglyToad.PdfPig/Images/Png/RawPngData.cs @@ -107,8 +107,18 @@ } case 6: return new Pixel(first, data[pixelStartIndex + 2], data[pixelStartIndex + 4], 255, false); - case 8: - return new Pixel(first, data[pixelStartIndex + 2], data[pixelStartIndex + 4], data[pixelStartIndex + 6], false); + case 8: + var pos = pixelStartIndex; + + // 16 bit precision - 2 bytes + var R = ToSingleByte(data[pos++], data[pos++]); + var G = ToSingleByte(data[pos++], data[pos++]); + var B = ToSingleByte(data[pos++], data[pos++]); + var A = ToSingleByte(data[pos++], data[pos++]); + + var pixel = new Pixel(R, G, B, A, false); + + return pixel; default: throw new InvalidOperationException($"Unreconized number of bytes per pixel: {bytesPerPixel}."); } diff --git a/src/UglyToad.PdfPig/Writer/PdfPageBuilder.cs b/src/UglyToad.PdfPig/Writer/PdfPageBuilder.cs index c814f75b..8e018def 100644 --- a/src/UglyToad.PdfPig/Writer/PdfPageBuilder.cs +++ b/src/UglyToad.PdfPig/Writer/PdfPageBuilder.cs @@ -666,7 +666,7 @@ {NameToken.Width, widthToken}, {NameToken.Height, heightToken}, {NameToken.ColorSpace, NameToken.Devicegray}, - {NameToken.BitsPerComponent, new NumericToken(png.Header.BitDepth)}, + {NameToken.BitsPerComponent, new NumericToken(1)}, {NameToken.Decode, new ArrayToken(new IToken[] { new NumericToken(0), new NumericToken(1) })}, {NameToken.Length, new NumericToken(compressedSmask.Length)}, {NameToken.Filter, NameToken.FlateDecode} @@ -683,7 +683,7 @@ {NameToken.Subtype, NameToken.Image}, {NameToken.Width, widthToken}, {NameToken.Height, heightToken}, - {NameToken.BitsPerComponent, new NumericToken(png.Header.BitDepth)}, + {NameToken.BitsPerComponent, new NumericToken(8)}, {NameToken.ColorSpace, NameToken.Devicergb}, {NameToken.Filter, NameToken.FlateDecode}, {NameToken.Length, new NumericToken(compressed.Length)}