Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
openbis
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
sispub
openbis
Commits
31b33d1d
Commit
31b33d1d
authored
14 years ago
by
tpylak
Browse files
Options
Downloads
Patches
Plain Diff
LMS-2051 small refactoring
SVN: 20240
parent
16ca6279
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/shared/utils/ImageUtil.java
+49
-16
49 additions, 16 deletions
...emsx/cisd/openbis/dss/generic/shared/utils/ImageUtil.java
with
49 additions
and
16 deletions
datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/shared/utils/ImageUtil.java
+
49
−
16
View file @
31b33d1d
...
...
@@ -79,20 +79,7 @@ public class ImageUtil
inputStream
.
mark
(
MAX_READ_AHEAD
);
try
{
final
ImageDecoder
dec
=
ImageCodec
.
createImageDecoder
(
"tiff"
,
inputStream
,
null
);
Raster
raster
;
try
{
raster
=
dec
.
decodeAsRaster
(
page
);
}
catch
(
IOException
ex
)
{
throw
EnvironmentFailureException
.
fromTemplate
(
"Cannot decode image."
,
ex
);
}
final
BufferedImage
image
=
new
BufferedImage
(
raster
.
getWidth
(),
raster
.
getHeight
(),
BufferedImage
.
TYPE_INT_RGB
);
image
.
setData
(
raster
);
return
image
;
return
loadJavaAdvancedImagingTiff
(
inputStream
,
page
,
false
);
}
catch
(
RuntimeException
ex
)
{
if
(
page
==
0
)
...
...
@@ -106,13 +93,54 @@ public class ImageUtil
}
// There are some TIFF files which cannot be opened by JIA, try ImageJ
// instead...
return
new
Opener
().
openTiff
(
inputStream
,
""
).
getBufferedImage
(
);
return
loadWithImageJ
(
inputStream
);
}
else
{
throw
ex
;
}
}
}
private
BufferedImage
loadWithImageJ
(
InputStream
inputStream
)
{
return
new
Opener
().
openTiff
(
inputStream
,
""
).
getBufferedImage
();
}
}
/**
* For experts only! Loads some kinds of TIFF images handled by JAI library.
*
* @param allow16BitGrayscaleModel if true and the image is 16 bit grayscale, then the
* appropriate buffered imaged type will be used, otherwise the image will be
* converted to 24 bits RGB. Useful if access to original pixel values is needed.
*/
public
static
BufferedImage
loadJavaAdvancedImagingTiff
(
InputStream
inputStream
,
Integer
pageOrNull
,
boolean
allow16BitGrayscaleModel
)
throws
EnvironmentFailureException
{
int
page
=
getPageNumber
(
pageOrNull
);
final
ImageDecoder
dec
=
ImageCodec
.
createImageDecoder
(
"tiff"
,
inputStream
,
null
);
Raster
raster
;
try
{
raster
=
dec
.
decodeAsRaster
(
page
);
}
catch
(
IOException
ex
)
{
throw
EnvironmentFailureException
.
fromTemplate
(
"Cannot decode image."
,
ex
);
}
int
bufferType
=
findBestImageBufferType
(
raster
,
allow16BitGrayscaleModel
);
final
BufferedImage
image
=
new
BufferedImage
(
raster
.
getWidth
(),
raster
.
getHeight
(),
bufferType
);
image
.
setData
(
raster
);
return
image
;
}
private
static
int
findBestImageBufferType
(
Raster
raster
,
boolean
allow16BitGrayscaleModel
)
{
boolean
is16BitGrayscale
=
raster
.
getNumBands
()
==
1
&&
raster
.
getSampleModel
().
getSampleSize
()[
0
]
==
16
;
return
is16BitGrayscale
&&
allow16BitGrayscaleModel
?
BufferedImage
.
TYPE_USHORT_GRAY
:
BufferedImage
.
TYPE_INT_RGB
;
}
private
static
final
class
JavaImageLoader
implements
ImageLoader
...
...
@@ -199,7 +227,7 @@ public class ImageUtil
*/
public
static
BufferedImage
loadImage
(
IContent
content
,
Integer
pageOrNull
)
{
int
page
=
pageOrNull
==
null
?
0
:
pageOrNull
.
intValue
(
);
int
page
=
getPageNumber
(
pageOrNull
);
InputStream
markSupportingInputStream
=
content
.
getInputStream
();
if
(
markSupportingInputStream
.
markSupported
()
==
false
)
{
...
...
@@ -209,6 +237,11 @@ public class ImageUtil
return
loadImage
(
markSupportingInputStream
,
fileType
,
page
);
}
private
static
int
getPageNumber
(
Integer
pageOrNull
)
{
return
pageOrNull
==
null
?
0
:
pageOrNull
.
intValue
();
}
/**
* Loads the specified <var>page</var> from the image from the tiven </var>inputStream</var>.
* Supported images formats are GIF, JPG, PNG, and TIFF. The input stream will be closed after
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment