Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bob.io.image
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
bob
bob.io.image
Commits
eb181e0c
Commit
eb181e0c
authored
8 years ago
by
Manuel Günther
Browse files
Options
Downloads
Patches
Plain Diff
Implemented a way of handling CMYK jpeg images
parent
a5d1b6ae
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!31
Resolve "Cannot read CMYK jpeg images"
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
bob/io/image/cpp/jpeg.cpp
+30
-11
30 additions, 11 deletions
bob/io/image/cpp/jpeg.cpp
bob/io/image/data/cmyk.jpg
+0
-0
0 additions, 0 deletions
bob/io/image/data/cmyk.jpg
bob/io/image/test.py
+1
-1
1 addition, 1 deletion
bob/io/image/test.py
with
31 additions
and
12 deletions
bob/io/image/cpp/jpeg.cpp
+
30
−
11
View file @
eb181e0c
...
...
@@ -94,16 +94,6 @@ static void im_peek(const std::string& path, bob::io::base::array::typeinfo& inf
// 5. Start decompression and get information
jpeg_start_decompress
(
&
cinfo
);
if
(
cinfo
.
output_components
!=
1
&&
cinfo
.
output_components
!=
3
)
{
// 6. clean up
jpeg_destroy_decompress
(
&
cinfo
);
boost
::
format
m
(
"unsupported number of planes (%d) when reading file. Image depth must be 1 or 3."
);
m
%
cinfo
.
output_components
;
throw
std
::
runtime_error
(
m
.
str
());
}
// Set depth and number of dimensions
info
.
dtype
=
bob
::
io
::
base
::
array
::
t_uint8
;
info
.
nd
=
(
cinfo
.
output_components
==
1
?
2
:
3
);
...
...
@@ -147,6 +137,27 @@ void imbuffer_to_rgb(size_t size, const T* im, T* r, T* g, T* b) {
}
}
template
<
typename
T
>
static
void
cmyk_imbuffer_to_rgb
(
size_t
size
,
const
T
*
im
,
T
*
r
,
T
*
g
,
T
*
b
,
bool
adobe_marker
)
{
T
C
,
M
,
Y
,
K
;
for
(
size_t
k
=
0
;
k
<
size
;
++
k
)
{
if
(
adobe_marker
){
C
=
*
im
++
;
M
=
*
im
++
;
Y
=
*
im
++
;
K
=
*
im
++
;
}
else
{
C
=
255
-*
im
++
;
M
=
255
-*
im
++
;
Y
=
255
-*
im
++
;
K
=
255
-*
im
++
;
}
*
r
++
=
C
*
K
/
255
;
*
g
++
=
M
*
K
/
255
;
*
b
++
=
Y
*
K
/
255
;
}
}
template
<
typename
T
>
static
void
im_load_color
(
struct
jpeg_decompress_struct
*
cinfo
,
bob
::
io
::
base
::
array
::
interface
&
b
)
{
const
bob
::
io
::
base
::
array
::
typeinfo
&
info
=
b
.
type
();
...
...
@@ -162,7 +173,11 @@ void im_load_color(struct jpeg_decompress_struct *cinfo, bob::io::base::array::i
buffer_pptr
[
0
]
=
buffer
.
get
();
while
(
cinfo
->
output_scanline
<
cinfo
->
output_height
)
{
jpeg_read_scanlines
(
cinfo
,
buffer_pptr
,
1
);
imbuffer_to_rgb
<
T
>
(
info
.
shape
[
2
],
reinterpret_cast
<
T
*>
(
buffer_pptr
[
0
]),
element_r
,
element_g
,
element_b
);
if
(
cinfo
->
output_components
==
3
)
imbuffer_to_rgb
<
T
>
(
info
.
shape
[
2
],
reinterpret_cast
<
T
*>
(
buffer_pptr
[
0
]),
element_r
,
element_g
,
element_b
);
else
cmyk_imbuffer_to_rgb
<
T
>
(
info
.
shape
[
2
],
reinterpret_cast
<
T
*>
(
buffer_pptr
[
0
]),
element_r
,
element_g
,
element_b
,
cinfo
->
saw_Adobe_marker
);
element_r
+=
cinfo
->
output_width
;
element_g
+=
cinfo
->
output_width
;
element_b
+=
cinfo
->
output_width
;
...
...
@@ -188,6 +203,10 @@ static void im_load(const std::string& filename, bob::io::base::array::interface
jpeg_read_header
(
&
cinfo
,
TRUE
);
// 4. Set parameters for decompression
if
(
cinfo
.
output_components
==
4
){
// assure to get CMYK output
cinfo
.
out_color_space
=
JCS_CMYK
;
}
// 5. Start decompression and get information
jpeg_start_decompress
(
&
cinfo
);
...
...
This diff is collapsed.
Click to expand it.
bob/io/image/data/cmyk.jpg
0 → 100644
+
0
−
0
View file @
eb181e0c
255 B
This diff is collapsed.
Click to expand it.
bob/io/image/test.py
+
1
−
1
View file @
eb181e0c
...
...
@@ -107,7 +107,7 @@ def test_netpbm():
def
test_image_load
():
# test that the generic bob.io.image.load function works as expected
for
filename
in
(
'
test.jpg
'
,
'
test.pbm
'
,
'
test.pgm
'
,
'
test.ppm
'
,
'
img_rgba_color.png
'
):
for
filename
in
(
'
test.jpg
'
,
'
cmyk.jpg
'
,
'
test.pbm
'
,
'
test.pgm
'
,
'
test.ppm
'
,
'
img_rgba_color.png
'
):
full_file
=
test_utils
.
datafile
(
filename
,
__name__
)
# load with just image name
i1
=
bob
.
io
.
image
.
load
(
full_file
)
...
...
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