-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Windows JPEG support #815
Windows JPEG support #815
Conversation
}], | ||
'include_dirs': [ | ||
'<(jpeg_root)/include' | ||
], | ||
'libraries': [ | ||
'-l<(GTK_Root)/lib/jpeg.lib' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I've botched my GTK dir, but I don't have a (GTK_Root)/lib/jpeg.lib, so I get a linker error. Did you add this file manually?
#458 changes it to '-l<(jpeg_root)/lib/jpeg-static.lib'
, but that does not build.
If I change it to '-l<(jpeg_root)/lib/jpeg.lib'
, it builds, but see comment in main discussion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zbjornson You're right, jpeg.lib
isn't in GTK, so need the one from libjpeg-turbo
.
That compiles. But... there's a nasty issue.
img.src = fs.readFileSync('foo.jpg')
works
img.src = foo.jpg
doesn't work
The problem is that libjpeg-turbo was compiled against msvcrt.lib
, whilst Visual Studio uses msvcrt{VS_VERSION}.lib
... Apparently this makes jpeg_read_header
hang / crash... See http://stackoverflow.com/questions/4092251/alternatives-to-jpeg-read-header-libjpeg
I'll try fix Image.cc
... but in any case: it seems more involved then previously thought ;-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Worked around the img.src ="foo.jpg"
issue... See below.
Glad to see someone working on jpeg support for Windows, thanks! I'm not sure this fully works. Per the comment here, apparently Could you please add this test to see if the CI builds it on linux? --- a/test/image.test.js
+++ b/test/image.test.js
@@ -9,6 +9,7 @@ var Canvas = require('../')
var png_checkers = __dirname + '/fixtures/checkers.png';
var png_clock = __dirname + '/fixtures/clock.png';
+var jpg_face = __dirname + '/public/face.jpeg';
describe('Image', function () {
it('should require new', function () {
@@ -40,6 +41,31 @@ describe('Image', function () {
assert.strictEqual(320, img.height);
});
+ it('Image set src to JPEG', function () {
+ var img = new Image
+ , onloadCalled = 0;
+
+ assert.strictEqual(null, img.onload);
+ assert.strictEqual(false, img.complete);
+
+ img.onload = function () {
+ onloadCalled += 1;
+ assert.strictEqual(img.src, jpg_face);
+ };
+
+ img.onerror = function (e) {
+ console.error("ERROR", e); // temporary...
+ };
+
+ img.src = jpg_face;
+ assert.strictEqual(1, onloadCalled);
+ assert.strictEqual(img.src, jpg_face);
+
+ assert.strictEqual(true, img.complete);
+ assert.strictEqual(320, img.width);
+ assert.strictEqual(320, img.height);
+ });
+
it('test Image#onload multiple times', function() {
var img = new Image
, onloadCalled = 0; |
Also:
Hmm, is there a case when having libjpegturbo installed and findable would break? It's nice to not have to pass a flag to add jpeg support (a la the script in #458). If anyone is installing canvas as something other than a primary dependency (e.g. they depend on package that depends on canvas), it'll be hard to pass the flag along. |
Latest commit includes your patch for
I edited
EDIT: see below |
@zbjornson Ok reworked Furthermore I used
Only when Seems the only difference with #458 is usage of
Note: this PR hence fixes the problem with Compilation succeeds both with VS2013 and VS2015. So guess it'll build on any recent VS version.
|
👍 Good solution. Compiles for me on Win 7 / VS2015 and tests pass. Browser JPEG tests have a black background but, if I remember, that's normal... Thanks! |
@LinusU when you're free would you mind taking a look at this please? It looks good to me, is semver-minor and would be super nice to finally get settled. ;) (Edit: maybe even semver patch, if you consider missing jpeg support a bug. -- not major at least.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Just a few nits, I would be very happy if you dropped the 50b080b commit entirely. I'll create a release commit when I cut a new release, as it is now I can't merge this because the version number is outdated...
@zbjornson thanks for the ping 💌
@@ -1,7 +1,7 @@ | |||
{ | |||
"name": "canvas", | |||
"description": "Canvas graphics API backed by Cairo", | |||
"version": "1.5.0", | |||
"version": "1.5.1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't bump the version number, I'll do that as part of the release process
}; | ||
|
||
img.onerror = function (e) { | ||
console.error("ERROR", e); // temporary... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about onerrorCalled = 0
, onerrorCalled += 1
and assert.strictEqual(onerrorCalled, 0)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@LinusU Missed your post ;-) I'll prep a fresh PR based on latest master when I find some time. Probably somewhere later this week.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you 💌
|
||
describe('Image', function () { | ||
this.timeout(5000); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is quite a long time, is it really needed?
just curious, how come there need to be changes to the way JPEGs are loaded from a file on Windows? I was able to get JPEG support on Windows by only modifying the build and not the source, using MSYS2 |
@chearon see reason in my first comment and code comment. To me, the minor change to the source is preferable to changing the build chain to use msys, which is a much less common tool set. (Although your precompiled binaries make that invisible for users of them.) |
Oh sorry, did not realize that was the entire discussion...interesting problem, and it seems like the MSYS2 build would have the same problem since it links with |
@LinusU @zbjornson Please check #841. I'm closing this one. |
This PR adds JPEG support on windows.
Basically a duplicate of #458, but this one needs explicit options to be be set on
npm install
andnode-gyp rebuild
. The explicit options make sure nothing breaks.It needs libjpeg-turbo or libjpeg-turbo64 installed.
Added the
jpeg_root
variable to binding.gyp (default:c:/libjpeg-turbo64
).Also
jpeg62.dll
will be copied tobuild/Release
Install:
node-gyp rebuild --jpeg_root=C:\libjpeg-turbo64 --with_jpeg
npm install --jpeg_root=C:\libjpeg-turbo64 --with_jpeg
Tested on win8.1 x64 node 6.2.1, Visual Studio 2015