Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
elphel-web-393
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Elphel
elphel-web-393
Commits
88e2352a
Commit
88e2352a
authored
May 20, 2020
by
Oleg Dzhimiev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
changes for TIFF files (synced to rocko)
parent
4f2579ba
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
88 additions
and
101 deletions
+88
-101
jquery-jp4.js
src/jp4-canvas/jquery-jp4.js
+88
-101
No files found.
src/jp4-canvas/jquery-jp4.js
View file @
88e2352a
...
@@ -227,142 +227,129 @@
...
@@ -227,142 +227,129 @@
this
.
getFormat
=
()
=>
this
.
format
;
this
.
getFormat
=
()
=>
this
.
format
;
this
.
getSrc
=
()
=>
settings
.
src
;
this
.
getSrc
=
()
=>
settings
.
src
;
function
process_image_tiff
(
blob
){
function
process_image_tiff
(
imagedata
){
IMAGE_FORMAT
=
"TIFF"
;
IMAGE_FORMAT
=
"TIFF"
;
obj
.
format
=
IMAGE_FORMAT
;
obj
.
format
=
IMAGE_FORMAT
;
var
arrayBuffer
;
// tiff.js which is limited in capabilities
var
fileReader
=
new
FileReader
(
);
//var tiff = new Tiff({buffer: arrayBuffer}
);
fileReader
.
onload
=
function
(
event
){
//var canvas = tiff.toCanvas();
arrayBuffer
=
event
.
target
.
result
;
// UTIF.js
var
ifds
=
UTIF
.
decode
(
imagedata
);
UTIF
.
decodeImage
(
imagedata
,
ifds
[
0
]);
// tiff.js which is limited in capabilities
if
(
ifds
[
0
].
t258
==
16
){
//var tiff = new Tiff({buffer: arrayBuffer}
);
rgba_16bit
=
new
Float32Array
(
ifds
[
0
].
data
.
filter
((
x
,
i
)
=>
i
%
2
==
0
)
);
//var canvas = tiff.toCanvas(
);
rgba_16bit
=
rgba_16bit
.
map
((
x
,
i
)
=>
x
+
(
ifds
[
0
].
data
[
2
*
i
+
1
]
<<
8
)
);
// UTIF.js
/*
var
ifds
=
UTIF
.
decode
(
arrayBuffer
);
if (ifds[0].height==122){
UTIF
.
decodeImage
(
arrayBuffer
,
ifds
[
0
]);
// cut off telemetry
ifds[0].height = 120;
if
(
ifds
[
0
].
t258
==
16
){
rgba_16bit = rgba_16bit.slice(0,ifds[0].height*ifds[0].width);
}
rgba_16bit
=
new
Float32Array
(
ifds
[
0
].
data
.
filter
((
x
,
i
)
=>
i
%
2
==
0
));
*/
rgba_16bit
=
rgba_16bit
.
map
((
x
,
i
)
=>
x
+
(
ifds
[
0
].
data
[
2
*
i
+
1
]
<<
8
));
/*
if (ifds[0].height==122){
// cut off telemetry
ifds[0].height = 120;
rgba_16bit = rgba_16bit.slice(0,ifds[0].height*ifds[0].width);
}
*/
// convert to C
// convert to C
rgba_16bit
=
rgba_16bit
.
map
(
x
=>
x
/
100
-
273.15
);
rgba_16bit
=
rgba_16bit
.
map
(
x
=>
x
/
100
-
273.15
);
// display based on histogram
// display based on histogram
function
get_t_lo
(
a
,
p
=
0.05
,
bins
=
1024
){
function
get_t_lo
(
a
,
p
=
0.05
,
bins
=
1024
){
let
min
=
Math
.
min
(...
a
);
let
min
=
Math
.
min
(...
a
);
let
max
=
Math
.
max
(...
a
);
let
max
=
Math
.
max
(...
a
);
let
bin_height
=
(
max
-
min
)
/
bins
;
let
bin_height
=
(
max
-
min
)
/
bins
;
for
(
let
i
=
0
;
i
<
bins
;
i
++
){
for
(
let
i
=
0
;
i
<
bins
;
i
++
){
let
bin_lo
=
min
+
(
i
+
0
)
*
bin_height
;
let
bin_lo
=
min
+
(
i
+
0
)
*
bin_height
;
let
bin_hi
=
min
+
(
i
+
1
)
*
bin_height
;
let
bin_hi
=
min
+
(
i
+
1
)
*
bin_height
;
let
a_f
=
a
.
filter
(
x
=>
x
<
bin_hi
);
let
a_f
=
a
.
filter
(
x
=>
x
<
bin_hi
);
if
(
a_f
.
length
>=
p
*
a
.
length
){
if
(
a_f
.
length
>=
p
*
a
.
length
){
return
(
bin_lo
+
bin_hi
)
/
2
;
return
(
bin_lo
+
bin_hi
)
/
2
;
}
}
}
return
0
;
}
}
return
0
;
// display based on histogram
}
function
get_t_hi
(
a
,
p
=
0.01
,
bins
=
1024
){
let
min
=
Math
.
min
(...
a
);
// display based on histogram
let
max
=
Math
.
max
(...
a
);
function
get_t_hi
(
a
,
p
=
0.01
,
bins
=
1024
){
let
bin_height
=
(
max
-
min
)
/
bins
;
for
(
let
i
=
0
;
i
<
bins
;
i
++
){
let
min
=
Math
.
min
(...
a
);
let
bin_lo
=
max
-
(
i
+
1
)
*
bin_height
;
let
max
=
Math
.
max
(...
a
);
let
bin_hi
=
max
-
(
i
+
0
)
*
bin_height
;
let
bin_height
=
(
max
-
min
)
/
bins
;
let
a_f
=
a
.
filter
(
x
=>
x
>
bin_lo
);
if
(
a_f
.
length
>=
p
*
a
.
length
){
return
(
bin_lo
+
bin_hi
)
/
2
;
}
}
return
0
;
for
(
let
i
=
0
;
i
<
bins
;
i
++
){
let
bin_lo
=
max
-
(
i
+
1
)
*
bin_height
;
let
bin_hi
=
max
-
(
i
+
0
)
*
bin_height
;
let
a_f
=
a
.
filter
(
x
=>
x
>
bin_lo
);
if
(
a_f
.
length
>=
p
*
a
.
length
){
return
(
bin_lo
+
bin_hi
)
/
2
;
}
}
}
return
0
;
// scale - 0.0-1.0
}
t_lo
=
get_t_lo
(
rgba_16bit
);
t_hi
=
get_t_hi
(
rgba_16bit
);
t_lo
=
t_lo
.
toFixed
(
2
);
// scale - 0.0-1.0
t_hi
=
t_hi
.
toFixed
(
2
);
t_lo
=
get_t_lo
(
rgba_16bit
);
t_hi
=
get_t_hi
(
rgba_16bit
);
//console.log(t_lo+" "+t_hi);
t_lo
=
t_lo
.
toFixed
(
2
);
t_hi
=
t_hi
.
toFixed
(
2
);
rgba_16bit
=
rgba_16bit
.
map
(
x
=>
(
x
-
t_lo
)
/
(
t_hi
-
t_lo
)
);
//console.log(t_lo+" "+t_hi
);
// get index
rgba_16bit
=
rgba_16bit
.
map
(
x
=>
(
x
-
t_lo
)
/
(
t_hi
-
t_lo
));
//rgba_16bit = rgba_16bit.map(x => iron_palette[Math.round(x*(iron_palette.length-1))]);
// this is for linear black n white
// get index
//rgba_16bit = rgba_16bit.map(x => 255*x*x
);
//rgba_16bit = rgba_16bit.map(x => iron_palette[Math.round(x*(iron_palette.length-1))]
);
}
// this is for linear black n white
//rgba_16bit = rgba_16bit.map(x => 255*x*x);
var
rgba_clamped
=
new
Uint8ClampedArray
(
rgba_16bit
.
length
*
4
);
//rgba_clamped = rgba_clamped.map((x,i) => rgba_16bit[(i-i%4)/4]);
rgba_clamped
=
rgba_clamped
.
map
((
x
,
i
)
=>
{
let
v
=
rgba_16bit
[(
i
-
i
%
4
)
/
4
];
v
=
(
v
>
1
)?
1
:
v
;
v
=
(
v
<
0
)?
0
:
v
;
v
=
get_palette_color
(
v
);
if
(
i
%
4
==
0
){
v
=
v
.
slice
(
1
,
3
);
}
else
if
(
i
%
4
==
1
){
v
=
v
.
slice
(
3
,
5
);
}
else
if
(
i
%
4
==
2
){
v
=
v
.
slice
(
5
,
7
);
}
else
{
return
255
;
}
v
=
parseInt
(
v
,
16
);
}
return
v
;
});
rgba_clamped
=
rgba_clamped
.
map
((
x
,
i
)
=>
(
i
%
4
==
3
)?
255
:
x
);
var
rgba_clamped
=
new
Uint8ClampedArray
(
rgba_16bit
.
length
*
4
);
//rgba_clamped = rgba_clamped.map((x,i) => rgba_16bit[(i-i%4)/4]);
rgba_clamped
=
rgba_clamped
.
map
((
x
,
i
)
=>
{
let
v
=
rgba_16bit
[(
i
-
i
%
4
)
/
4
];
v
=
(
v
>
1
)?
1
:
v
;
v
=
(
v
<
0
)?
0
:
v
;
v
=
get_palette_color
(
v
);
if
(
i
%
4
==
0
){
v
=
v
.
slice
(
1
,
3
);
}
else
if
(
i
%
4
==
1
){
v
=
v
.
slice
(
3
,
5
);
}
else
if
(
i
%
4
==
2
){
v
=
v
.
slice
(
5
,
7
);
}
else
{
return
255
;
}
var
rgba_idata
=
new
ImageData
(
rgba_clamped
,
ifds
[
0
].
width
,
ifds
[
0
].
height
);
v
=
parseInt
(
v
,
16
);
var
canvas
=
cnv_working
[
0
];
return
v
;
});
canvas
.
width
=
ifds
[
0
].
width
;
rgba_clamped
=
rgba_clamped
.
map
((
x
,
i
)
=>
(
i
%
4
==
3
)?
255
:
x
);
canvas
.
height
=
ifds
[
0
].
height
;
var
ctx
=
canvas
.
getContext
(
'2d'
);
var
rgba_idata
=
new
ImageData
(
rgba_clamped
,
ifds
[
0
].
width
,
ifds
[
0
].
height
);
ctx
.
putImageData
(
rgba_idata
,
0
,
0
)
;
var
canvas
=
cnv_working
[
0
]
;
cnv_working
.
trigger
(
"canvas_ready"
)
;
canvas
.
width
=
ifds
[
0
].
width
;
obj
.
busy
=
false
;
canvas
.
height
=
ifds
[
0
].
height
;
//Elphel.Canvas.drawScaled($(canvas),cnv_display,settings.width
);
var
ctx
=
canvas
.
getContext
(
'2d'
);
Elphel
.
Canvas
.
drawScaled
(
cnv_working
,
cnv_display
,
settings
.
width
);
ctx
.
putImageData
(
rgba_idata
,
0
,
0
);
}
Elphel
.
Canvas
.
drawScaled
(
cnv_working
,
cnv_display
,
settings
.
width
);
fileReader
.
readAsArrayBuffer
(
blob
);
conclude_processing
();
}
}
function
process_image
(
imagedata
){
function
process_image
(
imagedata
){
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment