Skip to content

Commit 5e3652b

Browse files
committed
fix difference of colormap behavior across different GPUs
1 parent 93bf2e3 commit 5e3652b

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

examples/webgl-single-image.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
raw.setStretch('linear');
5151
window.raw = raw;
5252
// Optionally set colormap. WebFITS defaults to grayscale mapping.
53-
// raw.setColorMap('Spectral');
53+
raw.setColorMap('binary');
5454
}
5555

5656
function main() {

rawimage.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ rawimage = (function(){
714714

715715
rawimage.prototype.setColorMap = function(cmap) {
716716
var cmaps, index, name, program, uColorIndex;
717-
717+
718718
cmaps = Object.keys(rawimage.colormaps);
719719
index = cmaps.indexOf('base64');
720720
cmaps.splice(index, 1);
@@ -729,7 +729,10 @@ rawimage = (function(){
729729
this.gl.useProgram(program);
730730

731731
uColorIndex = this.uniforms[name].uColorIndex;
732-
this.gl.uniform1f(uColorIndex, rawimage.colormaps[cmap]);
732+
733+
// The color index must be offset by 0.5 since graphics cards
734+
// approximate the pixel coordinate differently.
735+
this.gl.uniform1f(uColorIndex, rawimage.colormaps[cmap] - 0.5);
733736
};
734737

735738
// Switch back to current program
@@ -815,6 +818,6 @@ rawimage = (function(){
815818

816819
this.draw();
817820
};
818-
rawimage.version = "0.4.3";
821+
rawimage.version = "0.5.0";
819822
return rawimage;
820823
})();

rawimage.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/api.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ rawimage.prototype.loadImage = function(id, arr, width, height) {
3535

3636
rawimage.prototype.setColorMap = function(cmap) {
3737
var cmaps, index, name, program, uColorIndex;
38-
38+
3939
cmaps = Object.keys(rawimage.colormaps);
4040
index = cmaps.indexOf('base64');
4141
cmaps.splice(index, 1);
@@ -50,7 +50,10 @@ rawimage.prototype.setColorMap = function(cmap) {
5050
this.gl.useProgram(program);
5151

5252
uColorIndex = this.uniforms[name].uColorIndex;
53-
this.gl.uniform1f(uColorIndex, rawimage.colormaps[cmap]);
53+
54+
// The color index must be offset by 0.5 since graphics cards
55+
// approximate the pixel coordinate differently.
56+
this.gl.uniform1f(uColorIndex, rawimage.colormaps[cmap] - 0.5);
5457
};
5558

5659
// Switch back to current program

0 commit comments

Comments
 (0)