Matthew Butterick 7 years ago
parent 0e9de4a198
commit 6804a31629

@ -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) ->

@ -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);

@ -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))

@ -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))
#;(module+ test
(define pic (make-object PNG (file->bytes "test/assets/test.png")))
(splitAlphaChannel pic))

@ -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

Binary file not shown.

Binary file not shown.

Binary file not shown.
Loading…
Cancel
Save