diff options
| author | cjd24 | 2018-04-23 08:43:10 +0100 |
|---|---|---|
| committer | cjd24 | 2018-04-23 08:43:10 +0100 |
| commit | f1e8003fd621a40e2386c310a2189bb9a13b0c9d (patch) | |
| tree | a0323aa44d4e9ee87bc9b5fb98e769c4af79265d /src/conversion/czi/pyramidWorker.ts | |
| parent | Add tabular functionality (except cols) (diff) | |
| download | medicine-f1e8003fd621a40e2386c310a2189bb9a13b0c9d.tar.gz medicine-f1e8003fd621a40e2386c310a2189bb9a13b0c9d.zip | |
BIG FILTHY COMMIT OF SCARY STUFF
Diffstat (limited to 'src/conversion/czi/pyramidWorker.ts')
| -rw-r--r-- | src/conversion/czi/pyramidWorker.ts | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/conversion/czi/pyramidWorker.ts b/src/conversion/czi/pyramidWorker.ts index 5e6911c..6b12409 100644 --- a/src/conversion/czi/pyramidWorker.ts +++ b/src/conversion/czi/pyramidWorker.ts @@ -1,8 +1,11 @@ -import { CZIHeightMap, CZITile, CZITileRequest } from '../types/customPyramidIndex'; +import { WholeCZIHierarchy, CZIHeightMap, CZITile, CZITileRequest } from '../types/customPyramidIndex'; import { TileBounds, execpaths } from '../types/helpers'; import * as sharp from 'sharp'; import { isTileRelated } from './tileExtraction'; import { uuid } from '../../uuid' +import * as fs from 'fs'; +import { RequestError } from '../../errors' +const readFile = require('util').promisify(fs.readFile); const findRelatedTiles: Function = function(plane: CZIHeightMap, desired: TileBounds): CZITile[][] { @@ -32,6 +35,20 @@ const findRelatedTiles: Function = function(plane: CZIHeightMap, desired: TileBo return relatedTiles; }; +export const getTile: Function = async function(imageDir: string, cVal: string, x:number = 0, y:number = 0, w:number = 1024, h:number = 1024, zoom: number = 1): Promise<Buffer> { + let layout: WholeCZIHierarchy = JSON.parse(await readFile(imageDir + "/layout.json", 'utf8')); + + let bound: TileBounds = new TileBounds(x, x + w, y, y + h); + let map: CZIHeightMap; + try { + map = layout.c_values[Number(cVal)].height_map[Math.floor(Math.log2(zoom))] + } catch { + throw new RequestError(400, "bad_zoom_index") + } + + return readFile((await getFinalTile(imageDir, map, cVal, bound)).file_path); +} + const getFinalTile: Function = async function(imageDir: string, imageTier: CZIHeightMap, cVal: string, desiredRegion: TileBounds): Promise<CZITileRequest> { console.error("Has the calling function checked that the image has completed processing in WholeCZIHierarchy??"); |
