mirror of
https://github.com/cds-astro/aladin-lite.git
synced 2025-12-12 15:49:18 -08:00
wip parse the header inside xmp
This commit is contained in:
committed by
Matthieu Baumann
parent
c42002db8f
commit
dcf3bb360a
@@ -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) => {
|
||||
|
||||
@@ -90,7 +90,6 @@ pub struct App {
|
||||
_fbo_view: FrameBufferObject,
|
||||
_fbo_ui: FrameBufferObject,
|
||||
//line_renderer: RasterizedLineRenderer,
|
||||
|
||||
colormaps: Colormaps,
|
||||
|
||||
pub projection: ProjectionType,
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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 {
|
||||
|
||||
@@ -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...`)
|
||||
|
||||
@@ -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<iEntries;i++) {
|
||||
|
||||
Reference in New Issue
Block a user