From dcf3bb360ac6da54497f05bc50c1c873a1bc04a2 Mon Sep 17 00:00:00 2001 From: Matthieu Baumann Date: Fri, 26 Jul 2024 09:39:29 +0200 Subject: [PATCH] wip parse the header inside xmp --- examples/al-image-with-AVM-tags.html | 7 +++- src/core/src/app.rs | 1 - src/core/src/camera/mod.rs | 4 ++- src/glsl/webgl2/image/sampler.frag | 2 +- src/glsl/webgl2/projection/ait.glsl | 2 +- src/js/Image.js | 53 +++++++++++++--------------- src/js/libs/avm.js | 43 ++++++++++++++++++---- 7 files changed, 72 insertions(+), 40 deletions(-) diff --git a/examples/al-image-with-AVM-tags.html b/examples/al-image-with-AVM-tags.html index a219001d..c5ac087c 100644 --- a/examples/al-image-with-AVM-tags.html +++ b/examples/al-image-with-AVM-tags.html @@ -11,7 +11,12 @@ aladin.setOverlayImageLayer(A.image( //"https://www.virtualastronomy.org/images/sig05-013.jpg", - "https://www.astropix.org/archive/eso/eso0755a/eso_eso0755a_1280.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", { name: "sig05-017", successCallback: (ra, dec, fov, image) => { diff --git a/src/core/src/app.rs b/src/core/src/app.rs index c6723db7..b451c24a 100644 --- a/src/core/src/app.rs +++ b/src/core/src/app.rs @@ -90,7 +90,6 @@ pub struct App { _fbo_view: FrameBufferObject, _fbo_ui: FrameBufferObject, //line_renderer: RasterizedLineRenderer, - colormaps: Colormaps, pub projection: ProjectionType, diff --git a/src/core/src/camera/mod.rs b/src/core/src/camera/mod.rs index 8a4e9932..cc37623c 100644 --- a/src/core/src/camera/mod.rs +++ b/src/core/src/camera/mod.rs @@ -55,8 +55,10 @@ pub fn build_fov_coverage( moc } } else { + let center_xyzw = crate::coosys::apply_coo_system(camera_frame, frame, camera_center); + let biggest_fov_rad = proj.aperture_start().to_radians(); - let lonlat = camera_center.lonlat(); + let lonlat = center_xyzw.lonlat(); HEALPixCoverage::from_cone(&lonlat, biggest_fov_rad * 0.5, depth) } } diff --git a/src/glsl/webgl2/image/sampler.frag b/src/glsl/webgl2/image/sampler.frag index 4005d66d..5e0ab3b4 100644 --- a/src/glsl/webgl2/image/sampler.frag +++ b/src/glsl/webgl2/image/sampler.frag @@ -11,6 +11,6 @@ uniform float opacity; #include ../hips/color.glsl; void main() { - out_frag_color = texture(tex, frag_uv); + out_frag_color = texture(tex, vec2(frag_uv.x, 1.0 - frag_uv.y)); out_frag_color.a = out_frag_color.a * opacity; } \ No newline at end of file diff --git a/src/glsl/webgl2/projection/ait.glsl b/src/glsl/webgl2/projection/ait.glsl index 8b18713d..b9494bd6 100644 --- a/src/glsl/webgl2/projection/ait.glsl +++ b/src/glsl/webgl2/projection/ait.glsl @@ -6,7 +6,7 @@ vec2 w2c_ait(vec3 p) { float y2d = p.y / w; float x2d = 0.0; - if (abs(p.x) < 1e-3) { + if (abs(p.x) < 5e-3) { float x_over_r = p.x/r; x2d = -p.x * (1.0 - x_over_r*x_over_r/21.0) / w; } else { diff --git a/src/js/Image.js b/src/js/Image.js index c89c6cd9..2410c191 100644 --- a/src/js/Image.js +++ b/src/js/Image.js @@ -237,6 +237,26 @@ export let Image = (function () { }, layer ); + }, + error: (e) => { + // try as cors + const url = Aladin.JSONP_PROXY + '?url=' + self.url; + + return Utils.fetch({ + url: url, + dataType: 'readableStream', + success: (stream) => { + return self.view.wasm.addImageFITS( + stream, + { + ...self.colorCfg.get(), + longitudeReversed: false, + imgFormat: 'fits', + }, + layer + ); + }, + }); } }) .then((imageParams) => { @@ -278,7 +298,7 @@ export let Image = (function () { if (!self.options.wcs) { /* look for avm tags if no wcs is given */ let avm = new AVM(img); - console.log(img.complete) + avm.load((obj) => { // obj contains the following information: // obj.id (string) = The ID provided for the image @@ -289,31 +309,9 @@ export let Image = (function () { console.log(obj) if (obj.avmdata) { - let wcs = {}; - wcs.CTYPE1 = obj.tags['Spatial.CoordinateFrame'] === 'ICRS' ? 'RA---' : 'GLON-'; - wcs.CTYPE1 += obj.tags['Spatial.CoordsystemProjection']; - wcs.CTYPE2 = obj.tags['Spatial.CoordinateFrame'] === 'ICRS' ? 'DEC--' : 'GLAT-'; - wcs.CTYPE2 += obj.tags['Spatial.CoordsystemProjection']; + self.options.wcs = obj.oTags; - if (obj.tags['Spatial.Equinox']) - wcs.EQUINOX = +obj.tags['Spatial.Equinox']; - - wcs.NAXIS1 = +obj.tags['Spatial.ReferenceDimension'][0]; - wcs.NAXIS2 = +obj.tags['Spatial.ReferenceDimension'][1]; - - wcs.CDELT1 = +obj.tags['Spatial.Scale'][0]; - wcs.CDELT2 = +obj.tags['Spatial.Scale'][1]; - - wcs.CRPIX1 = +obj.tags['Spatial.ReferencePixel'][0]; - wcs.CRPIX2 = +obj.tags['Spatial.ReferencePixel'][1]; - - wcs.CRVAL1 = +obj.tags['Spatial.ReferenceValue'][0]; - wcs.CRVAL2 = +obj.tags['Spatial.ReferenceValue'][1]; - - if (obj.tags['Spatial.Rotation'] !== undefined) - wcs.CROTA2 = +obj.tags['Spatial.Rotation']; - - self.options.wcs = wcs; + console.log(wcs) img2Blob() } else { @@ -321,7 +319,6 @@ export let Image = (function () { reject('No AVM tags have been found in the image') return; } - }) } else { img2Blob() @@ -387,8 +384,8 @@ export let Image = (function () { } else { // imgformat not defined we will try first supposing it is a fits file and then use the jpg heuristic promise = this._addFITS(layer) - .catch(_ => { - console.warn(`Image located at ${self.url} could not be parsed as fits file. Try as a jpg/png image...`) + .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 => { console.error(`Image located at ${self.url} could not be parsed as jpg/png image file. Aborting...`) diff --git a/src/js/libs/avm.js b/src/js/libs/avm.js index 49b9511b..af57f85f 100644 --- a/src/js/libs/avm.js +++ b/src/js/libs/avm.js @@ -117,6 +117,7 @@ export let AVM = (function() { var oAVM = _obj.findAVMinJPEG(view); _obj.avmdata = true; _obj.tags = oAVM || {}; + if (typeof fnCallback=="function") fnCallback(_obj); }) } @@ -137,18 +138,16 @@ export let AVM = (function() { var iLength = oFile.byteLength; while (iOffset < iLength) { if (oFile.getUint8(iOffset) != 0xFF) return false; // not a valid marker, something is wrong - var iMarker = oFile.getUint8(iOffset+1)+1; - + var iMarker = oFile.getUint8(iOffset+1); // we could implement handling for other markers here, // but we're only looking for 0xFFE1 for AVM data if (iMarker == 22400) { return this.readAVMData(oFile, iOffset + 4, oFile.getUint16(iOffset+2, false)-2); - iOffset += 2 + oFile.getUint16(iOffset+2, false); + //iOffset += 2 + oFile.getUint16(iOffset+2, false); } else if (iMarker == 225) { // 0xE1 = Application-specific 1 (for AVM) - console.log("jkjk") var oTags = this.readAVMData(oFile, iOffset + 4, oFile.getUint16(iOffset+2, false)-2); return oTags; } else { @@ -157,11 +156,42 @@ export let AVM = (function() { } } - AVM.prototype.readAVMData = function(oFile, iStart, iLength){ + AVM.prototype.readAVMData = function(oFile) { var oTags = {}; this.xmp = this.readXMP(oFile); console.log("xmp read", this.xmp) - if (this.xmp) oTags = this.readAVM(this.xmp); + if (this.xmp) { + oTags = this.readAVM(this.xmp); + let wcs = {}; + + if (oTags) { + wcs.CTYPE1 = obj.tags['Spatial.CoordinateFrame'] === 'ICRS' ? 'RA---' : 'GLON-'; + wcs.CTYPE1 += obj.tags['Spatial.CoordsystemProjection']; + wcs.CTYPE2 = obj.tags['Spatial.CoordinateFrame'] === 'ICRS' ? 'DEC--' : 'GLAT-'; + wcs.CTYPE2 += obj.tags['Spatial.CoordsystemProjection']; + + if (obj.tags['Spatial.Equinox']) + wcs.EQUINOX = +obj.tags['Spatial.Equinox']; + + wcs.NAXIS1 = obj.tags['Spatial.ReferenceDimension'] && +obj.tags['Spatial.ReferenceDimension'][0] || img.width; + wcs.NAXIS2 = obj.tags['Spatial.ReferenceDimension'] && +obj.tags['Spatial.ReferenceDimension'][1] || img.height; + + wcs.CDELT1 = obj.tags['Spatial.Scale'] && +obj.tags['Spatial.Scale'][0]; + wcs.CDELT2 = obj.tags['Spatial.Scale'] && +obj.tags['Spatial.Scale'][1]; + wcs.CRPIX1 = obj.tags['Spatial.ReferencePixel'] && +obj.tags['Spatial.ReferencePixel'][0]; + wcs.CRPIX2 = obj.tags['Spatial.ReferencePixel'] && +obj.tags['Spatial.ReferencePixel'][1]; + + wcs.CRVAL1 = obj.tags['Spatial.ReferenceValue'] && +obj.tags['Spatial.ReferenceValue'][0]; + wcs.CRVAL2 = obj.tags['Spatial.ReferenceValue'] && +obj.tags['Spatial.ReferenceValue'][1]; + + if (obj.tags['Spatial.Rotation'] !== undefined) + wcs.CROTA2 = +obj.tags['Spatial.Rotation']; + + + } else { + // try to read directly the WCS + } + } return oTags; } @@ -178,7 +208,6 @@ export let AVM = (function() { var byteStr = ''; var iEntryOffset = -1; console.log(iEntryOffset) - // Here we want to search for the XMP packet starting string // There is probably a more efficient way to search for a byte string for (var i=0;i