Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fixes to tiff.js to work in Chrome #10

Merged
merged 2 commits into from

2 participants

@city41

Thanks for making tiff.js, it's been a great help for a project I am working on. I had to make some minor changes to get it to work in Chrome. Chrome does not like const in strict mode (since it's not yet part of the standard), and Chrome does not support default parameters (which is a Firefox proprietary feature).

city41 added some commits
@city41 city41 made tiff.js Chrome compatible
-- got rid of default parameters (as cool as they are)
-- got rid of const (as nice as it is)
80c9069
@city41 city41 Fixed test.html to only load tiff once one is chosen 9a9291f
@GPHemsley GPHemsley merged commit 240644a into from
@GPHemsley
Owner

Great, thanks!

@GPHemsley
Owner

I've pretty much undone commit 9a9291f with commit 9d6e3c5.

I generally test the script with by refreshing with a file already loaded, so having the onload trigger would prompt the image to be reparsed on refresh, instead of me having to manually reload the image.

I also changed the default background color to something that is a little more obvious (#FFEEFF). Having it solid black could lead to confusion as whether an image was parsed correctly, if an image actually has a lot of black in it. Along those lines, I've also (in commit f1ad327) made it so that the canvas border changes from dashed to solid when the image is loaded.

Hopefully these changes will satisfy the same usecase requirements as your original commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 21, 2012
  1. @city41

    made tiff.js Chrome compatible

    city41 authored
    -- got rid of default parameters (as cool as they are)
    -- got rid of const (as nice as it is)
  2. @city41
This page is out of date. Refresh to see the latest.
Showing with 14 additions and 8 deletions.
  1. +3 −3 test.html
  2. +11 −5 tiff.js
View
6 test.html
@@ -33,7 +33,7 @@
}
</script>
</head>
-<body onload="prepareTIFF();">
+<body>
<form name="tiff-parser" method="post" enctype="multipart/form-data" style="margin: 10% auto auto; text-align: center;">
@@ -42,7 +42,7 @@
</form>
-<canvas id="tiff-image" style="display: block; max-width: 95%; margin: 2em auto; border: 1px dashed magenta; padding: 0px;"></canvas>
+<canvas id="tiff-image" style="display: block; max-width: 95%; margin: 2em auto; border: 1px dashed magenta; padding: 0px; background-color: black"></canvas>
</body>
-</html>
+</html>
View
16 tiff.js
@@ -41,7 +41,7 @@ TIFFParser.prototype = {
getFieldTagName: function (fieldTag) {
// See: http://www.digitizationguidelines.gov/guidelines/TIFF_Metadata_Final.pdf
// See: http://www.digitalpreservation.gov/formats/content/tiff_tags.shtml
- const fieldTagNames = {
+ var fieldTagNames = {
// TIFF Baseline
0x013B: 'Artist',
0x0102: 'BitsPerSample',
@@ -164,7 +164,7 @@ TIFFParser.prototype = {
},
getFieldTypeName: function (fieldType) {
- const fieldTypeNames = {
+ var fieldTypeNames = {
0x0001: 'BYTE',
0x0002: 'ASCII',
0x0003: 'SHORT',
@@ -204,7 +204,8 @@ TIFFParser.prototype = {
return fieldTypeLength;
},
- getBits: function (numBits, byteOffset, bitOffset = 0) {
+ getBits: function (numBits, byteOffset, bitOffset) {
+ bitOffset = bitOffset || 0;
var extraBytes = Math.floor(bitOffset / 8);
var newByteOffset = byteOffset + extraBytes;
var totalBits = bitOffset + numBits;
@@ -304,7 +305,10 @@ TIFFParser.prototype = {
return Math.floor((colorSample * multiplier) + (multiplier - 1));
},
- makeRGBAFillValue: function(r, g, b, a = 1.0) {
+ makeRGBAFillValue: function(r, g, b, a) {
+ if(typeof a === 'undefined') {
+ a = 1.0;
+ }
return "rgba(" + r + ", " + g + ", " + b + ", " + a + ")";
},
@@ -338,7 +342,9 @@ TIFFParser.prototype = {
}
},
- parseTIFF: function (tiffArrayBuffer, canvas = document.createElement("canvas")) {
+ parseTIFF: function (tiffArrayBuffer, canvas) {
+ canvas = canvas || document.createElement('canvas');
+
this.tiffDataView = new DataView(tiffArrayBuffer);
this.canvas = canvas;
Something went wrong with that request. Please try again.