diff --git a/pitfall/pdfkit/lib/image/png.coffee b/pitfall/pdfkit/lib/image/png.coffee index 340c88c1..a66d5414 100644 --- a/pitfall/pdfkit/lib/image/png.coffee +++ b/pitfall/pdfkit/lib/image/png.coffee @@ -107,6 +107,10 @@ class PNGImage splitAlphaChannel: -> console.log("start splitAlphaChannel in png.coffee") @image.decodePixels (pixels) => + console.log("decoded pixels length=" + pixels.length); + console.log("decoded pixels="); + console.log(pixels); + colorByteSize = @image.colors * @image.bits / 8 pixelCount = @width * @height imgData = new Buffer(pixelCount * colorByteSize) @@ -120,13 +124,28 @@ class PNGImage imgData[p++] = pixels[i++] alphaChannel[a++] = pixels[i++] + console.log("uncompressed imgData length=" + imgData.length) + console.log("uncompressed imgData=") + console.log(imgData) + + console.log("uncompressed alphaChannel length=" + alphaChannel.length) + console.log("uncompressed alphaChannel=") + console.log(alphaChannel) + done = 0 zlib.deflate imgData, (err, @imgData) => throw err if err + console.log("compressed @imgData length=" + @imgData.length) + console.log("compressed @imgData=") + console.log(@imgData) + @finalize() if ++done is 2 zlib.deflate alphaChannel, (err, @alphaChannel) => throw err if err + console.log("compressed @alphaChannel length=" + @alphaChannel.length) + console.log("compressed @alphaChannel=") + console.log(@alphaChannel) @finalize() if ++done is 2 loadIndexedAlphaChannel: (fn) -> diff --git a/pitfall/pdfkit/node_modules/png-js/png-node.js b/pitfall/pdfkit/node_modules/png-js/png-node.js index a8d69d8b..c28e28a8 100644 --- a/pitfall/pdfkit/node_modules/png-js/png-node.js +++ b/pitfall/pdfkit/node_modules/png-js/png-node.js @@ -251,6 +251,9 @@ } row++; } + console.log("decoded pixels length=" + pixels.length); + console.log("decoded pixels="); + console.log(pixels); return fn(pixels); }); }; @@ -309,6 +312,7 @@ }; PNG.prototype.decode = function(fn) { + console.log("another call to decodePixels") var ret, _this = this; ret = new Buffer(this.width * this.height * 4); diff --git a/pitfall/pitfall/png-reader.rkt b/pitfall/pitfall/png-reader.rkt index 15001b4d..1b0c868c 100644 --- a/pitfall/pitfall/png-reader.rkt +++ b/pitfall/pitfall/png-reader.rkt @@ -165,7 +165,8 @@ Grab key chunks from PNG. Doesn't require heavy lifting from libpng. )] [else (error 'invalid-filter-algorithm (format "~a" b))]))) - #;(report (bytes-length pixels)) + (report (bytes-length pixels) 'decoded-pixels-length) + (report (bytes->hex (subbytes pixels 0 20))) (fn pixels)) diff --git a/pitfall/pitfall/png.rkt b/pitfall/pitfall/png.rkt index 04022097..4d7b8b8b 100644 --- a/pitfall/pitfall/png.rkt +++ b/pitfall/pitfall/png.rkt @@ -77,7 +77,7 @@ (mhash 'Type "XObject" 'Subtype "Image" 'Height (· this height) - 'With (· this width) + 'Width (· this width) 'BitsPerComponent 8 'Filter "FlateDecode" 'ColorSpace "DeviceGray" @@ -111,25 +111,38 @@ (define imgData (apply bytes (reverse imgBytes))) (define alphaChannel (apply bytes (reverse alphaBytes))) + + (report (bytes-length imgData) 'uncompressed-imgdata-length) + (report (bytes->hex (subbytes imgData 0 20)) 'uncompressed-imgdata) + + (report (bytes-length alphaChannel) 'uncompressed-alphaChannel-length) + (report (bytes->hex (subbytes alphaChannel 0 20)) 'uncompressed-alphaChannel) + #;(report* (bytes-length imgData) (bytes-length alphaChannel)) #;(error 'in-pixel-proc) + + (define imgDataCompressed (deflate imgData)) + (define alphaChannelCompressed (deflate alphaChannel)) + + + (report (bytes-length alphaChannelCompressed) 'alphaChannelCompressed-length) + (report (bytes->hex (subbytes alphaChannelCompressed 0 20)) 'alphaChannelCompressed) + + (report (bytes-length imgDataCompressed) 'imgDataCompressed-length) + (report (bytes->hex (subbytes imgDataCompressed 0 20)) 'imgDataCompressed) + - (define done 0) - (set-field! imgData this (deflate imgData)) - (increment! done) - (when (= done 2) (· this finalize)) - - (set-field! alphaChannel this (deflate alphaChannel)) - (increment! done) - (when (= done 2) (· this finalize)) + (set-field! imgData this imgDataCompressed) + (set-field! alphaChannel this alphaChannelCompressed) + (· this finalize) - (report* done) + #;(report* 'done) (void) ) (decodePixels (· this imgData) (· this pixelBitlength) (· this width) (· this height) pixel-proc)) -(module+ test - (define pic (make-object PNG (file->bytes "test/assets/test.png"))) - (splitAlphaChannel pic)) \ No newline at end of file +#;(module+ test + (define pic (make-object PNG (file->bytes "test/assets/test.png"))) + (splitAlphaChannel pic)) \ No newline at end of file diff --git a/pitfall/pitfall/test/test8.coffee b/pitfall/pitfall/test/test8.coffee index 3f435eb2..cedb6cb1 100644 --- a/pitfall/pitfall/test/test8.coffee +++ b/pitfall/pitfall/test/test8.coffee @@ -14,7 +14,7 @@ doc = new PDFDocument({compress: no}) doc.pipe(fs.createWriteStream('test8.pdf')) make doc -doc = new PDFDocument({compress: yes}) -doc.pipe(fs.createWriteStream('test8c.pdf')) -make doc +#doc = new PDFDocument({compress: yes}) +#doc.pipe(fs.createWriteStream('test8c.pdf')) +#make doc diff --git a/pitfall/pitfall/test/test8.pdf b/pitfall/pitfall/test/test8.pdf index 40e92791..b87ffa3a 100644 Binary files a/pitfall/pitfall/test/test8.pdf and b/pitfall/pitfall/test/test8.pdf differ diff --git a/pitfall/pitfall/test/test8c.pdf b/pitfall/pitfall/test/test8c.pdf index 3eb23888..d7c179c4 100644 Binary files a/pitfall/pitfall/test/test8c.pdf and b/pitfall/pitfall/test/test8c.pdf differ diff --git a/pitfall/pitfall/test/test8rkt.pdf b/pitfall/pitfall/test/test8rkt.pdf index e69de29b..69f1b03d 100644 Binary files a/pitfall/pitfall/test/test8rkt.pdf and b/pitfall/pitfall/test/test8rkt.pdf differ