11const test = require ( 'tape' )
2+ const PromiseFileReader = require ( 'promise-file-reader' )
23
4+ const readImageArrayBuffer = require ( 'itkreadImageArrayBuffer.js' )
5+ const readImageBlob = require ( 'itkreadImageBlob.js' )
36const readImageFile = require ( 'itkreadImageFile.js' )
47
58const IntTypes = require ( 'itkIntTypes.js' )
@@ -17,6 +20,53 @@ for (let ii = 0; ii < byteString.length; ++ii) {
1720const cthead1SmallBlob = new window . Blob ( [ intArray ] , { type : mimeString } )
1821const cthead1SmallFile = new window . File ( [ cthead1SmallBlob ] , 'cthead1Small.png' )
1922
23+ test ( 'readImageArrayBuffer reads an ArrayBuffer' , t => {
24+ return PromiseFileReader . readAsArrayBuffer ( cthead1SmallFile )
25+ . then ( arrayBuffer => {
26+ return readImageArrayBuffer ( arrayBuffer , 'cthead1Small.png' ) . then ( function ( image ) {
27+ t . is ( image . imageType . dimension , 2 , 'dimension' )
28+ t . is ( image . imageType . componentType , IntTypes . UInt8 , 'componentType' )
29+ t . is ( image . imageType . pixelType , PixelTypes . Scalar , 'pixelType' )
30+ t . is ( image . imageType . components , 1 , 'components' )
31+ t . is ( image . origin [ 0 ] , 0.0 , 'origin[0]' )
32+ t . is ( image . origin [ 1 ] , 0.0 , 'origin[1]' )
33+ t . is ( image . spacing [ 0 ] , 1.0 , 'spacing[0]' )
34+ t . is ( image . spacing [ 1 ] , 1.0 , 'spacing[1]' )
35+ t . is ( getMatrixElement ( image . direction , 0 , 0 ) , 1.0 , 'direction (0, 0)' )
36+ t . is ( getMatrixElement ( image . direction , 0 , 1 ) , 0.0 , 'direction (0, 1)' )
37+ t . is ( getMatrixElement ( image . direction , 1 , 0 ) , 0.0 , 'direction (1, 0)' )
38+ t . is ( getMatrixElement ( image . direction , 1 , 1 ) , 1.0 , 'direction (1, 1)' )
39+ t . is ( image . size [ 0 ] , 32 , 'size[0]' )
40+ t . is ( image . size [ 1 ] , 32 , 'size[1]' )
41+ t . is ( image . buffer . length , 1024 , 'buffer.length' )
42+ t . is ( image . buffer [ 512 ] , 12 , 'buffer[512]' )
43+ t . end ( )
44+ } )
45+ } )
46+ } )
47+
48+ test ( 'readImageBlob reads an Blob' , t => {
49+ return readImageBlob ( cthead1SmallBlob , 'cthead1Small.png' ) . then ( function ( image ) {
50+ t . is ( image . imageType . dimension , 2 , 'dimension' )
51+ t . is ( image . imageType . componentType , IntTypes . UInt8 , 'componentType' )
52+ t . is ( image . imageType . pixelType , PixelTypes . Scalar , 'pixelType' )
53+ t . is ( image . imageType . components , 1 , 'components' )
54+ t . is ( image . origin [ 0 ] , 0.0 , 'origin[0]' )
55+ t . is ( image . origin [ 1 ] , 0.0 , 'origin[1]' )
56+ t . is ( image . spacing [ 0 ] , 1.0 , 'spacing[0]' )
57+ t . is ( image . spacing [ 1 ] , 1.0 , 'spacing[1]' )
58+ t . is ( getMatrixElement ( image . direction , 0 , 0 ) , 1.0 , 'direction (0, 0)' )
59+ t . is ( getMatrixElement ( image . direction , 0 , 1 ) , 0.0 , 'direction (0, 1)' )
60+ t . is ( getMatrixElement ( image . direction , 1 , 0 ) , 0.0 , 'direction (1, 0)' )
61+ t . is ( getMatrixElement ( image . direction , 1 , 1 ) , 1.0 , 'direction (1, 1)' )
62+ t . is ( image . size [ 0 ] , 32 , 'size[0]' )
63+ t . is ( image . size [ 1 ] , 32 , 'size[1]' )
64+ t . is ( image . buffer . length , 1024 , 'buffer.length' )
65+ t . is ( image . buffer [ 512 ] , 12 , 'buffer[512]' )
66+ t . end ( )
67+ } )
68+ } )
69+
2070test ( 'readImageFile reads a File' , t => {
2171 return readImageFile ( cthead1SmallFile ) . then ( function ( image ) {
2272 t . is ( image . imageType . dimension , 2 , 'dimension' )
0 commit comments