mirror of
https://github.com/cds-astro/aladin-lite.git
synced 2025-12-12 15:49:18 -08:00
remove tiff dep
This commit is contained in:
committed by
Matthieu Baumann
parent
3c4ec3a0c1
commit
d8ff8aa41e
@@ -7,17 +7,10 @@
|
||||
<script type="module">
|
||||
import A from '../src/js/A.js';
|
||||
A.init.then(() => {
|
||||
let aladin = A.aladin('#aladin-lite-div', {fov: 30, survey: "CDS/P/PanSTARRS/DR1/color-z-zg-g", target: "280 +0", projection: "AIT", showShareControl:true, showSettingsControl: true, showContextMenu:true});
|
||||
let aladin = A.aladin('#aladin-lite-div', {fov: 30, survey: "CDS/P/DSS2/color", target: "280 +0", projection: "AIT", showShareControl:true, showSettingsControl: true, showContextMenu:true});
|
||||
|
||||
aladin.setOverlayImageLayer(A.image(
|
||||
//"https://www.virtualastronomy.org/images/sig05-013.jpg",
|
||||
//"https://www.eso.org/public/archives/images/original/eso1137_hubble_dark.tif",
|
||||
//"images/eso1137_hubble_dark.jpg",
|
||||
//"https://nova.astrometry.net/new_fits_file/11015534",
|
||||
//"https://chandra.harvard.edu/photo/2024/25th/25th_gcenter.jpg",
|
||||
//"https://www.astropix.org/archive/spitzer/ssc2008-14b/spitzer_ssc2008-14b_original.jpg",
|
||||
//"https://chandra.harvard.edu/photo/2024/25th/25th_crab.jpg",
|
||||
"https://www.eso.org/public/archives/images/original/eso1023d.tif",
|
||||
"https://www.virtualastronomy.org/images/sig05-013.jpg",
|
||||
{
|
||||
name: "sig05-017",
|
||||
successCallback: (ra, dec, fov, image) => {
|
||||
|
||||
@@ -27,9 +27,9 @@
|
||||
CUNIT1: 'deg', // X pixel scale units
|
||||
CUNIT2: 'deg', // Y pixel scale units
|
||||
CD1_1: -0.000223666022989, // Transformation matrix
|
||||
CD1_2: 0.000296578064584, // no comment
|
||||
CD1_2: -0.000296578064584, // no comment
|
||||
CD2_1: -0.000296427555509, // no comment
|
||||
CD2_2: -0.000223774308964, // no comment
|
||||
CD2_2: 0.000223774308964, // no comment
|
||||
NAXIS1: 1080, // Image width, in pixels.
|
||||
NAXIS2: 705 // Image height, in pixels.
|
||||
},
|
||||
|
||||
@@ -58,8 +58,5 @@
|
||||
"vite-plugin-wasm": "^3.2.2",
|
||||
"vite-plugin-wasm-pack": "^0.1.12",
|
||||
"vitest": "^0.32.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"tiff": "^6.1.0"
|
||||
}
|
||||
}
|
||||
|
||||
150
src/js/Image.js
150
src/js/Image.js
@@ -30,7 +30,6 @@ import { ColorCfg } from "./ColorCfg.js";
|
||||
import { Aladin } from "./Aladin.js";
|
||||
import { Utils } from "./Utils";
|
||||
import { AVM } from "./libs/avm.js";
|
||||
import * as tiff from "tiff";
|
||||
|
||||
/**
|
||||
* @typedef {Object} ImageOptions
|
||||
@@ -51,7 +50,7 @@ import * as tiff from "tiff";
|
||||
* @property {number} [contrast=0.0] - The contrast value for the color configuration.
|
||||
* @property {Object} [wcs] - an object describing the WCS of the image. In case of a fits image
|
||||
* this property will be ignored as the WCS taken will be the one present in the fits file.
|
||||
* @property {string} [imgFormat] - Optional image format. Giving it will prevent the auto extension determination algorithm to be triggered. Possible values are 'jpeg', 'png' or 'fits'.
|
||||
* @property {string} [imgFormat] - Optional image format. Giving it will prevent the auto extension determination algorithm to be triggered. Possible values are 'jpeg', 'png' or 'fits'. tiff files are not supported. You can convert your tiff files to jpg ones by using the fantastic image magick suite.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
@@ -60,24 +59,24 @@ import * as tiff from "tiff";
|
||||
* {
|
||||
* name: "M61",
|
||||
* wcs: {
|
||||
* NAXIS: 0, // Minimal header
|
||||
* CTYPE1: 'RA---TAN', // TAN (gnomic) projection + SIP distortions
|
||||
* CTYPE2: 'DEC--TAN', // TAN (gnomic) projection + SIP distortions
|
||||
* EQUINOX: 2000.0, // Equatorial coordinates definition (yr)
|
||||
* LONPOLE: 180.0, // no comment
|
||||
* LATPOLE: 0.0, // no comment
|
||||
* CRVAL1: 185.445488837, // RA of reference point
|
||||
* CRVAL2: 4.47896032431, // DEC of reference point
|
||||
* CRPIX1: 588.995094299, // X reference pixel
|
||||
* CRPIX2: 308.307905197, // Y reference pixel
|
||||
* CUNIT1: 'deg', // X pixel scale units
|
||||
* CUNIT2: 'deg', // Y pixel scale units
|
||||
* CD1_1: -0.000223666022989, // Transformation matrix
|
||||
* CD1_2: 0.000296578064584, // no comment
|
||||
* CD2_1: -0.000296427555509, // no comment
|
||||
* CD2_2: -0.000223774308964, // no comment
|
||||
* NAXIS1: 1080, // Image width, in pixels.
|
||||
* NAXIS2: 705 // Image height, in pixels.
|
||||
NAXIS: 0, // Minimal header
|
||||
CTYPE1: 'RA---TAN', // TAN (gnomic) projection
|
||||
CTYPE2: 'DEC--TAN', // TAN (gnomic) projection
|
||||
EQUINOX: 2000.0, // Equatorial coordinates definition (yr)
|
||||
LONPOLE: 180.0, // no comment
|
||||
LATPOLE: 0.0, // no comment
|
||||
CRVAL1: 185.445488837, // RA of reference point
|
||||
CRVAL2: 4.47896032431, // DEC of reference point
|
||||
CRPIX1: 588.995094299, // X reference pixel
|
||||
CRPIX2: 308.307905197, // Y reference pixel
|
||||
CUNIT1: 'deg', // X pixel scale units
|
||||
CUNIT2: 'deg', // Y pixel scale units
|
||||
CD1_1: -0.000223666022989, // Transformation matrix
|
||||
CD1_2: -0.000296578064584, // no comment
|
||||
CD2_1: -0.000296427555509, // no comment
|
||||
CD2_2: 0.000223774308964, // no comment
|
||||
NAXIS1: 1080, // Image width, in pixels.
|
||||
NAXIS2: 705 // Image height, in pixels.
|
||||
* },
|
||||
* successCallback: (ra, dec, fov, image) => {
|
||||
* aladin.gotoRaDec(ra, dec);
|
||||
@@ -254,14 +253,7 @@ export let Image = (function () {
|
||||
imgFormat: 'fits',
|
||||
},
|
||||
layer
|
||||
).catch(e => {
|
||||
//console.log(e)
|
||||
console.log('jj')
|
||||
const reader = stream.getReader();
|
||||
reader.releaseLock();
|
||||
console.log("jjjjj")
|
||||
return Promise.reject(e);
|
||||
});
|
||||
)
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -273,96 +265,6 @@ export let Image = (function () {
|
||||
})
|
||||
}
|
||||
|
||||
Image.prototype._addTiff = function(layer) {
|
||||
let self = this;
|
||||
const url = Aladin.JSONP_PROXY + '?url=' + self.url;
|
||||
console.log("parse through proxy", url)
|
||||
console.log("test tiff")
|
||||
|
||||
return Utils.fetch({
|
||||
url,
|
||||
dataType: "blob",
|
||||
cors: "Anonymous"
|
||||
})
|
||||
.then((blob) => {
|
||||
return blob.arrayBuffer()
|
||||
})
|
||||
.then((arrayBuffer) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
var ifds = tiff.decode(arrayBuffer);
|
||||
//var rgba = UTIF.toRGBA8(ifds[0]); // Uint8Array with RGBA pixels
|
||||
console.log(ifds[0].width, ifds[0].height, ifds[0]);
|
||||
|
||||
let try2FindAVM = [];
|
||||
for(var v of ifds[0].fields.values()) {
|
||||
try2FindAVM.push(new Promise((resolve, reject) => {
|
||||
let string = new TextDecoder().decode(v)
|
||||
console.log(string, v)
|
||||
let avm = new AVM(v);
|
||||
avm.load((obj) => {
|
||||
// obj contains the following information:
|
||||
// obj.id (string) = The ID provided for the image
|
||||
// obj.img (object) = The image object
|
||||
// obj.xmp (string) = The raw XMP header
|
||||
// obj.wcsdata (Boolean) = If WCS have been loaded
|
||||
// obj.tags (object) = An array containing all the loaded tags e.g. obj.tags['Headline']
|
||||
// obj.wcs (object) = The wcs parsed from the image
|
||||
console.log(obj)
|
||||
if (obj.wcsdata) {
|
||||
if (img.width !== obj.wcs.NAXIS1) {
|
||||
obj.wcs.NAXIS1 = img.width;
|
||||
}
|
||||
|
||||
if (img.height !== obj.wcs.NAXIS2) {
|
||||
obj.wcs.NAXIS2 = img.height;
|
||||
}
|
||||
|
||||
self.options.wcs = obj.wcs;
|
||||
|
||||
const blob = new Blob([ifds[0]]);
|
||||
const stream = blob.stream(1024);
|
||||
resolve(stream)
|
||||
} else {
|
||||
// no tags found
|
||||
reject('No WCS have been found in the image')
|
||||
}
|
||||
})
|
||||
}))
|
||||
}
|
||||
|
||||
return Promise.any(try2FindAVM);
|
||||
})
|
||||
})
|
||||
.then((readableStream) => {
|
||||
console.log("blob", readableStream)
|
||||
let wcs = self.options && self.options.wcs;
|
||||
wcs.NAXIS1 = wcs.NAXIS1 || img.width;
|
||||
wcs.NAXIS2 = wcs.NAXIS2 || img.height;
|
||||
|
||||
return self.view.wasm
|
||||
.addImageWithWCS(
|
||||
readableStream,
|
||||
wcs,
|
||||
{
|
||||
...self.colorCfg.get(),
|
||||
longitudeReversed: false,
|
||||
imgFormat: 'jpeg',
|
||||
},
|
||||
layer
|
||||
)
|
||||
})
|
||||
.then((imageParams) => {
|
||||
self.imgFormat = 'tiff';
|
||||
return Promise.resolve(imageParams);
|
||||
})
|
||||
.catch(e => {
|
||||
console.error(e)
|
||||
console.log("aaa", e)
|
||||
|
||||
return Promise.reject(e)
|
||||
})
|
||||
}
|
||||
|
||||
Image.prototype._addJPGOrPNG = function(layer) {
|
||||
let self = this;
|
||||
let img = document.createElement('img');
|
||||
@@ -482,26 +384,16 @@ export let Image = (function () {
|
||||
console.error(`Image located at ${this.url} could not be parsed as a ${this.imgFormat} file. Is the imgFormat specified correct?`);
|
||||
return Promise.reject(e)
|
||||
})
|
||||
} else if (this.imgFormat === 'tiff') {
|
||||
promise = this._addTiff(layer)
|
||||
.catch(e => {
|
||||
console.error(`Image located at ${this.url} could not be parsed as a ${this.imgFormat} file. Is the imgFormat specified correct?`);
|
||||
return Promise.reject(e)
|
||||
})
|
||||
} else {
|
||||
// imgformat not defined we will try first supposing it is a fits file and then use the jpg heuristic
|
||||
promise = this._addTiff(layer)
|
||||
promise = self._addFITS(layer)
|
||||
.catch(e => {
|
||||
console.warn(`Image located at ${self.url} could not be parsed as fits file. Try as a jpg/png image...:`, e)
|
||||
return self._addJPGOrPNG(layer)
|
||||
.catch(e => {
|
||||
return self._addFITS(layer)
|
||||
.catch(e => {
|
||||
console.error(`Image located at ${self.url} could not be parsed as jpg/png/tif image file. Aborting...`)
|
||||
return Promise.reject(e);
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
promise = promise.then((imageParams) => {
|
||||
|
||||
@@ -85,7 +85,6 @@ export let AVM = (function() {
|
||||
if(!this.img && this.id) {
|
||||
this.img = document.getElementById(this.id);
|
||||
}
|
||||
console.log("jksjdk2f")
|
||||
|
||||
if (this.img instanceof ArrayBuffer) {
|
||||
this.getData(fnCallback);
|
||||
@@ -105,8 +104,6 @@ export let AVM = (function() {
|
||||
}
|
||||
|
||||
AVM.prototype.getData = function(fnCallback){
|
||||
console.log("jksjdk2f")
|
||||
|
||||
if(!this.imageHasData()){
|
||||
this.getImageData(this.img, fnCallback);
|
||||
}else{
|
||||
@@ -128,7 +125,6 @@ export let AVM = (function() {
|
||||
if (typeof fnCallback=="function") fnCallback(_obj);
|
||||
};
|
||||
if (oImg instanceof ArrayBuffer) {
|
||||
console.log("jksjdkf")
|
||||
findAVM(oImg)
|
||||
} else {
|
||||
let reqwst = new Request(oImg.src, {
|
||||
@@ -188,7 +184,6 @@ export let AVM = (function() {
|
||||
|
||||
if (tags) {
|
||||
this.tags = tags;
|
||||
console.log(tags)
|
||||
|
||||
let unwindTag = (tag) => {
|
||||
if (Array.isArray(tag)) {
|
||||
@@ -210,7 +205,7 @@ export let AVM = (function() {
|
||||
wcs.NAXIS2 = tags['Spatial.ReferenceDimension'] && +tags['Spatial.ReferenceDimension'][1];
|
||||
|
||||
if (tags['Spatial.CDMatrix']) {
|
||||
console.warn("Spatial.CDMatrix is deprecated");
|
||||
console.warn("Spatial.CDMatrix is deprecated in favor of Spatial.Scale + Spatial.Rotation");
|
||||
|
||||
wcs.CD1_1 = +tags['Spatial.CDMatrix'][0];
|
||||
wcs.CD1_2 = +tags['Spatial.CDMatrix'][1];
|
||||
@@ -257,8 +252,6 @@ export let AVM = (function() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log(wcs)
|
||||
}
|
||||
}
|
||||
return wcs;
|
||||
@@ -266,7 +259,6 @@ export let AVM = (function() {
|
||||
|
||||
AVM.prototype.readXMP = function(oFile) {
|
||||
var iEntries = oFile.byteLength;
|
||||
var bBigEnd = false;
|
||||
var prev_n_hex = '';
|
||||
var record = false;
|
||||
var recordn = 0;
|
||||
@@ -334,7 +326,7 @@ export let AVM = (function() {
|
||||
final = str.indexOf('</'+key+'>',start);
|
||||
// Parse out the HTML tags and build an array of the resulting values
|
||||
var tmps = str.substring(start-1,final);
|
||||
console.log(tmps)
|
||||
|
||||
var tmparr = new Array(0);
|
||||
var tmpstr = tmps.replace(/[\n\r]/g,"");
|
||||
tmpstr = tmpstr.replace(/ +/g," ");
|
||||
|
||||
Reference in New Issue
Block a user