Get slice.
182 {
184 cache =
new TileCache(
this);
185 var curLevel =
Image.BioImage.LevelFromResolution(sliceInfo.Resolution);
187 var tileInfos =
Schema.GetTileInfos(sliceInfo.Extent, curLevel);
188 List<Tuple<Extent, byte[]>> tiles = new List<Tuple<Extent, byte[]>>();
189 foreach (BruTile.TileInfo t in tileInfos)
190 {
191 TileInformation tf = new TileInformation();
192 tf.Extent = t.Extent;
193 tf.Coordinate = App.viewer.GetCoordinate();
194 tf.Index = t.Index;
196 if(c!=null)
197 tiles.Add(Tuple.Create(t.Extent.WorldToPixelInvertedY(
curUnitsPerPixel), c));
198 }
199 var srcPixelExtent = sliceInfo.Extent.WorldToPixelInvertedY(
curUnitsPerPixel);
200 var dstPixelExtent = sliceInfo.Extent.WorldToPixelInvertedY(sliceInfo.Resolution);
201 var dstPixelHeight = sliceInfo.Parame.DstPixelHeight > 0 ? sliceInfo.Parame.DstPixelHeight : dstPixelExtent.Height;
202 var dstPixelWidth = sliceInfo.Parame.DstPixelWidth > 0 ? sliceInfo.Parame.DstPixelWidth : dstPixelExtent.Width;
203 destExtent =
new Extent(0, 0, dstPixelWidth, dstPixelHeight);
206 {
207 try
208 {
209 NetVips.Image im = null;
210 if (this.
Image.BioImage.Resolutions[curLevel].PixelFormat == PixelFormat.Format16bppGrayScale)
211 im = ImageUtil.JoinVips16(tiles, srcPixelExtent, new Extent(0, 0, dstPixelWidth, dstPixelHeight));
212 else if(this.
Image.BioImage.Resolutions[curLevel].PixelFormat == PixelFormat.Format24bppRgb)
213 im = ImageUtil.JoinVipsRGB24(tiles, srcPixelExtent, new Extent(0, 0, dstPixelWidth, dstPixelHeight));
214 return im.WriteToMemory();
215 }
216 catch (Exception e)
217 {
219 Console.WriteLine("Failed to use LibVips please install Libvips for your platform.");
220 Console.WriteLine(e.Message);
221 }
222 }
223 try
224 {
226 if (this.
Image.BioImage.Resolutions[curLevel].PixelFormat == PixelFormat.Format16bppGrayScale)
227 {
228 im = ImageUtil.Join16(tiles, srcPixelExtent, new Extent(0, 0, dstPixelWidth, dstPixelHeight));
230 im.Dispose();
231 return bts;
232 }
233 else if (this.
Image.BioImage.Resolutions[curLevel].PixelFormat == PixelFormat.Format24bppRgb)
234 {
235 im = ImageUtil.JoinRGB24(tiles, srcPixelExtent, new Extent(0, 0, dstPixelWidth, dstPixelHeight));
237 im.Dispose();
238 return bts;
239 }
240 }
241 catch (Exception er)
242 {
243 Console.WriteLine(er.Message);
244 return null;
245 }
246 return null;
247 }
SixLabors.ImageSharp.Image Image
Definition ISlideSource.cs:11
TileCache cache
Definition ISlideSource.cs:180
static double curUnitsPerPixel
Definition ISlideSource.cs:178
static Extent destExtent
Definition ISlideSource.cs:176
static bool UseVips
Definition ISlideSource.cs:179
ITileSchema Schema
Definition ISlideSource.cs:291
byte[] GetRgb24Bytes(Image< Rgb24 > image)
Definition ISlideSource.cs:248
static Extent sourceExtent
Definition ISlideSource.cs:177
byte[] Get16Bytes(Image< L16 > image)
Definition ISlideSource.cs:268
async Task< byte[]> GetTile(TileInformation info)
Definition ISlideSource.cs:87