/// <summary> /// Maps image pixels to lat-long values. /// </summary> /// <param name="tileMap">Tile mapper.</param> /// <param name="hasData">Boolean indicates whether the coordinates maps to valid color.</param> /// <returns>List of color values.</returns> private List <Color> MapToColors(OctTileMap tileMap, out bool hasData) { List <Color> colors = new List <Color>(Constants.TileSize * Constants.TileSize); Vector2d point = new Vector2d(); hasData = false; for (int pixelY = 0; pixelY < Constants.TileSize; pixelY++) { point.Y = ((double)pixelY + 0.5) / Constants.TileSize; for (int pixelX = 0; pixelX < Constants.TileSize; pixelX++) { point.X = ((double)pixelX + 0.5) / Constants.TileSize; var v = tileMap.PointToRaDec(point); Color color = (this.colorMap.GetColor(v.X, v.Y)); if (color != Color.Transparent) { hasData = true; } colors.Add(color); } } return(colors); }
public Task <Stream> GetOctTileAsync(int level, int tileX, int tileY, bool enforceBoundary, CancellationToken token) { var map = new OctTileMap(level, tileX, tileY); // SDSS boundaries // RA: 105 deg <-> 270 deg // DEC: -3 deg <-> + 75 deg if (enforceBoundary) { if (map.raMin > 270 | map.decMax < -3 | map.raMax < 105 | map.decMin > 75) { return(null); } } Int32 sqSide = 256; using Bitmap bmpOutput = new Bitmap(sqSide, sqSide); FastBitmap bmpOutputFast = new FastBitmap(bmpOutput); SdssImage sdim = new SdssImage(map.raMin, map.decMax, map.raMax, map.decMin, true); sdim.LoadImage(); if (sdim.image != null) { sdim.Lock(); bmpOutputFast.LockBitmap(); // Fill up bmp from sdim Vector2d vxy, vradec; unsafe { PixelData *pPixel; for (int y = 0; y < sqSide; y++) { pPixel = bmpOutputFast[0, y]; vxy.Y = (y / 255.0); for (int x = 0; x < sqSide; x++) { vxy.X = (x / 255.0); vradec = map.PointToRaDec(vxy); *pPixel = sdim.GetPixelDataAtRaDec(vradec); pPixel++; } } } sdim.Unlock(); sdim.image.Dispose(); bmpOutputFast.UnlockBitmap(); } var result = bmpOutput.SaveToStream(ImageFormat.Png); return(Task.FromResult(result)); }
/// <summary> /// Creates the tile specified by level. /// </summary> /// <param name="level"> /// Zoom level. /// </param> /// <param name="tileX"> /// X tile coordinate. /// </param> /// <param name="tileY"> /// Y tile coordinate. /// </param> public void Create(int level, int tileX, int tileY) { // Map to convert from pixel position to global (longitude, latitude). OctTileMap tileMap = new OctTileMap(level, tileX, tileY); int[] colors = new int[Constants.TileSize * Constants.TileSize]; bool hasData = false; int position = -1; for (int pixelY = 0; pixelY < Constants.TileSize; pixelY++) { for (int pixelX = 0; pixelX < Constants.TileSize; pixelX++) { // Map pixel (u, v) position to (longitude, latitude). double u = (0.5 + pixelX) / ((double)Constants.TileSize); double v = (0.5 + pixelY) / ((double)Constants.TileSize); Vector2d location = tileMap.PointToRaDec(new Vector2d(u, v)); double latitude = location.Y; double longitude = location.X; if (this.LookAtOutsideSurface) { longitude -= 180.0; } // Map geo location to an ARGB value. Color color = this.ColorMap.GetColor(longitude, latitude); // Store and update bit indicating whether actual data is present or not. position++; colors[position] = color.ToArgb(); if (hasData == false) { hasData = (color != Color.Transparent); } } } if (hasData) { TileHelper.ToBitmap(level, tileX, tileY, colors, this.TileSerializer, this.ReferenceTileSerializer); } }
public override void Run(IWwtContext context) { string query = context.Request.Params["Q"]; string[] values = query.Split(','); int level = Convert.ToInt32(values[0]); int tileX = Convert.ToInt32(values[1]); int tileY = Convert.ToInt32(values[2]); string filename; string path; string wwtTilesDir = ConfigurationManager.AppSettings["WWTTilesDir"]; string DSSTileCache = WWTUtil.GetCurrentConfigShare("DSSTileCache", true); filename = String.Format(DSSTileCache + "\\SDSSToast\\{0}\\{2}\\{2}_{1}.png", level, tileX, tileY); path = String.Format(DSSTileCache + "\\SDSSToast\\{0}\\{2}", level, tileX, tileY); if (level > 14) { context.Response.Write("No image"); context.Response.Close(); return; } if (level < 9) { context.Response.ContentType = "image/png"; Stream s = PlateTilePyramid.GetFileStream(wwtTilesDir + "\\sdss_8.plate", level, tileX, tileY); int length = (int)s.Length; byte[] data = new byte[length]; s.Read(data, 0, length); context.Response.OutputStream.Write(data, 0, length); context.Response.Flush(); context.Response.End(); return; } /* * if (!sdssTile ) * { * // todo return black tile * using (Bitmap bmp = Bitmap(256, 256)) * { * using (Graphics g = Graphics.FromImage(bmp)) * { * g.Clear(Color.Black); * } * bmp.Save(filename); * context.Response.WriteFile(filename); * } * return; * } */ if (File.Exists(filename)) { try { context.Response.WriteFile(filename); return; } catch { } } else { OctTileMap map = new OctTileMap(level, tileX, tileY); Int32 sqSide = 256; //Vector2d topLeft = map.PointToRaDec(new Vector2d(0, 0)) //map.PointToRaDec(new Vector2d(0, 1)) //map.PointToRaDec(new Vector2d(1, 0)) //map.PointToRaDec(new Vector2d(1, 1)) // SDSS boundaries // RA: 105 deg <-> 270 deg // DEC: -3 deg <-> + 75 deg if (!(map.raMin > 270 | map.decMax < -3 | map.raMax < 105 | map.decMin > 75)) { Bitmap bmpOutput = new Bitmap(sqSide, sqSide); FastBitmap bmpOutputFast = new FastBitmap(bmpOutput); SdssImage sdim = new SdssImage(map.raMin, map.decMax, map.raMax, map.decMin); sdim.LoadImage(); sdim.Lock(); bmpOutputFast.LockBitmap(); // Fill up bmp from sdim Vector2d vxy, vradec; unsafe { PixelData *pPixel; for (int y = 0; y < sqSide; y++) { pPixel = bmpOutputFast[0, y]; vxy.Y = (y / 255.0); for (int x = 0; x < sqSide; x++) { vxy.X = (x / 255.0); vradec = map.PointToRaDec(vxy); *pPixel = sdim.GetPixelDataAtRaDec(vradec); pPixel++; } } } bmpOutputFast.UnlockBitmap(); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } bmpOutput.Save(filename, ImageFormat.Png); bmpOutput.Dispose(); try { context.Response.WriteFile(filename); } catch { } } else { //context.Response.WriteFile(@"c:\inetpub\cache\empty.png"); context.Response.Write("No Image"); } } context.Response.End(); }
public override void Run(IWwtContext context) { if (context.Request.UserAgent.ToLower().Contains("wget")) { context.Response.Write("You are not allowed to bulk download imagery thru the tile service. Please contact [email protected] for more information."); context.Response.End(); return; } string query = context.Request.Params["Q"]; string[] values = query.Split(','); //++ // 2014-09-26 security fix. // int level = 0; int tileX = 0; int tileY = 0; try { level = Convert.ToInt32(values[0]); tileX = Convert.ToInt32(values[1]); tileY = Convert.ToInt32(values[2]); } catch { context.Response.Write("Invalid query string."); context.Response.End(); return; } string filename; string path; string wwtTilesDir = ConfigurationManager.AppSettings["WWTTilesDir"]; string DSSTileCache = WWTUtil.GetCurrentConfigShare("DSSTileCache", true); filename = String.Format(DSSTileCache + "\\SDSSToast12\\{0}\\{2}\\{2}_{1}.png", level, tileX, tileY); path = String.Format(DSSTileCache + "\\SDSSToast12\\{0}\\{2}", level, tileX, tileY); if (level > 14) { context.Response.Write("No image"); context.Response.End(); return; } if (level < 8) { context.Response.ContentType = "image/png"; Stream s = PlateTilePyramid.GetFileStream(wwtTilesDir + "\\sdssdr12_7.plate", level, tileX, tileY); int length = (int)s.Length; if (length == 0) { context.Response.Clear(); context.Response.ContentType = "text/plain"; context.Response.Write("No image"); context.Response.End(); return; } byte[] data = new byte[length]; s.Read(data, 0, length); context.Response.OutputStream.Write(data, 0, length); context.Response.Flush(); context.Response.End(); return; } if (File.Exists(filename)) { try { context.Response.WriteFile(filename); return; } catch { } } else { OctTileMap map = new OctTileMap(level, tileX, tileY); Int32 sqSide = 256; Bitmap bmpOutput = new Bitmap(sqSide, sqSide); FastBitmap bmpOutputFast = new FastBitmap(bmpOutput); SdssImage sdim = new SdssImage(map.raMin, map.decMax, map.raMax, map.decMin, true); sdim.LoadImage(); if (sdim.image != null) { sdim.Lock(); bmpOutputFast.LockBitmap(); // Fill up bmp from sdim Vector2d vxy, vradec; unsafe { PixelData *pPixel; for (int y = 0; y < sqSide; y++) { pPixel = bmpOutputFast[0, y]; vxy.Y = (y / 255.0); for (int x = 0; x < sqSide; x++) { vxy.X = (x / 255.0); vradec = map.PointToRaDec(vxy); *pPixel = sdim.GetPixelDataAtRaDec(vradec); pPixel++; } } } sdim.Unlock(); sdim.image.Dispose(); bmpOutputFast.UnlockBitmap(); } if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } bmpOutput.Save(filename, ImageFormat.Png); bmpOutput.Dispose(); try { context.Response.WriteFile(filename); } catch { } } context.Response.End(); }