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
ab2e9b94
There was a problem fetching the pipeline summary.
Commit
ab2e9b94
authored
7 years ago
by
André Anjos
Browse files
Options
Downloads
Patches
Plain Diff
Allow garbage at the end of PNM iaimages not affect readout (closes
#30
)
parent
c4d84efd
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!36
Add tests to detect the problem reported on this issue
Pipeline
#
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
bob/io/image/cpp/netpbm.cpp
+6
-14
6 additions, 14 deletions
bob/io/image/cpp/netpbm.cpp
bob/io/image/cpp/pnmio.cpp
+4
-4
4 additions, 4 deletions
bob/io/image/cpp/pnmio.cpp
with
10 additions
and
18 deletions
bob/io/image/cpp/netpbm.cpp
+
6
−
14
View file @
ab2e9b94
...
@@ -117,16 +117,8 @@ pm_openw(const char * const name) {
...
@@ -117,16 +117,8 @@ pm_openw(const char * const name) {
void
void
pm_close
(
FILE
*
const
f
)
{
pm_close
(
FILE
*
const
f
)
{
// fprintf(stderr, "I am closing a file\n");
fflush
(
f
);
fflush
(
f
);
if
(
f
!=
stdin
)
fclose
(
f
);
// if ( ferror( f ) )
// boost::format m("a file read or write error occurred at some point");
// throw std::runtime_error(m.str());
if
(
f
!=
stdin
)
fclose
(
f
);
// if ( fclose( f ) != 0 )
// boost::format m("cannot close file.");
// throw std::runtime_error(m.str());
}
}
static
boost
::
shared_ptr
<
std
::
FILE
>
make_cfile
(
const
char
*
filename
,
const
char
*
flags
)
static
boost
::
shared_ptr
<
std
::
FILE
>
make_cfile
(
const
char
*
filename
,
const
char
*
flags
)
...
@@ -168,12 +160,12 @@ static void pnm_readpaminit(FILE *file, struct pam * const pamP, const int size)
...
@@ -168,12 +160,12 @@ static void pnm_readpaminit(FILE *file, struct pam * const pamP, const int size)
if
(
img_colors
>>
8
==
0
)
pamP
->
bytes_per_sample
=
1
;
if
(
img_colors
>>
8
==
0
)
pamP
->
bytes_per_sample
=
1
;
else
if
(
img_colors
>>
16
==
0
)
pamP
->
bytes_per_sample
=
2
;
else
if
(
img_colors
>>
16
==
0
)
pamP
->
bytes_per_sample
=
2
;
}
else
{
}
else
{
boost
::
format
m
(
"Unknown PNM/PFM image format."
);
boost
::
format
m
(
"
pnm_readpaminit():
Unknown PNM/PFM image format."
);
throw
std
::
runtime_error
(
m
.
str
());
throw
std
::
runtime_error
(
m
.
str
());
}
}
if
(
read_err
!=
0
)
{
if
(
read_err
!=
0
)
{
boost
::
format
m
(
"Something went wrong when reading the image file."
);
boost
::
format
m
(
"
pnm_readpaminit():
Something went wrong when reading the image file."
);
throw
std
::
runtime_error
(
m
.
str
());
throw
std
::
runtime_error
(
m
.
str
());
}
}
...
@@ -214,7 +206,7 @@ static void pnm_readpam(struct pam * const pamP, int *img_data) {
...
@@ -214,7 +206,7 @@ static void pnm_readpam(struct pam * const pamP, int *img_data) {
}
}
if
(
read_err
!=
0
)
{
if
(
read_err
!=
0
)
{
boost
::
format
m
(
"Something went wrong when reading the image file."
);
boost
::
format
m
(
"
pnm_readpam():
Something went wrong when reading the image file."
);
throw
std
::
runtime_error
(
m
.
str
());
throw
std
::
runtime_error
(
m
.
str
());
}
}
}
}
...
@@ -240,7 +232,7 @@ static void pnm_writepam(struct pam * const pamP, int *img_data) {
...
@@ -240,7 +232,7 @@ static void pnm_writepam(struct pam * const pamP, int *img_data) {
}
}
if
(
write_err
!=
0
)
{
if
(
write_err
!=
0
)
{
boost
::
format
m
(
"Something went wrong when writing the image file."
);
boost
::
format
m
(
"
pnm_writepam():
Something went wrong when writing the image file."
);
throw
std
::
runtime_error
(
m
.
str
());
throw
std
::
runtime_error
(
m
.
str
());
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
bob/io/image/cpp/pnmio.cpp
+
4
−
4
View file @
ab2e9b94
...
@@ -309,13 +309,13 @@ int read_pbm_data(FILE *f, int *img_in, int img_size, int is_ascii, int img_widt
...
@@ -309,13 +309,13 @@ int read_pbm_data(FILE *f, int *img_in, int img_size, int is_ascii, int img_widt
if
(
is_ascii
==
1
)
{
if
(
is_ascii
==
1
)
{
read_count
=
fscanf
(
f
,
"%d"
,
&
lum_val
);
read_count
=
fscanf
(
f
,
"%d"
,
&
lum_val
);
if
(
read_count
<
1
)
return
-
1
;
if
(
read_count
<
1
)
return
-
1
;
if
(
i
>=
img_size
)
re
turn
-
1
;
if
(
i
>=
img_size
)
b
re
ak
;
img_in
[
i
++
]
=
lum_val
;
img_in
[
i
++
]
=
lum_val
;
}
else
{
}
else
{
lum_val
=
fgetc
(
f
);
lum_val
=
fgetc
(
f
);
/* Decode the image contents byte-by-byte. */
/* Decode the image contents byte-by-byte. */
for
(
k
=
0
;
k
<
8
;
k
++
)
{
for
(
k
=
0
;
k
<
8
;
k
++
)
{
if
(
i
>=
img_size
)
re
turn
-
1
;
if
(
i
>=
img_size
)
b
re
ak
;
img_in
[
i
++
]
=
(
lum_val
>>
(
7
-
k
))
&
0x1
;
img_in
[
i
++
]
=
(
lum_val
>>
(
7
-
k
))
&
0x1
;
// fprintf(stderr, "i: %d, %d\n", i, img_in[i]);
// fprintf(stderr, "i: %d, %d\n", i, img_in[i]);
row_position
++
;
row_position
++
;
...
@@ -355,7 +355,7 @@ int read_pgm_data(FILE *f, int *img_in, int img_size, int is_ascii,
...
@@ -355,7 +355,7 @@ int read_pgm_data(FILE *f, int *img_in, int img_size, int is_ascii,
lum_val
|=
fgetc
(
f
);
lum_val
|=
fgetc
(
f
);
}
}
}
}
if
(
i
>=
img_size
)
re
turn
-
1
;
if
(
i
>=
img_size
)
b
re
ak
;
img_in
[
i
++
]
=
lum_val
;
img_in
[
i
++
]
=
lum_val
;
}
}
// fclose(f);
// fclose(f);
...
@@ -397,7 +397,7 @@ int read_ppm_data(FILE *f, int *img_in, int img_size, int is_ascii,
...
@@ -397,7 +397,7 @@ int read_ppm_data(FILE *f, int *img_in, int img_size, int is_ascii,
b_val
|=
fgetc
(
f
);
b_val
|=
fgetc
(
f
);
}
}
}
}
if
(
i
>=
img_size
)
re
turn
-
1
;
if
(
i
>=
img_size
)
b
re
ak
;
img_in
[
i
++
]
=
r_val
;
img_in
[
i
++
]
=
r_val
;
img_in
[
i
++
]
=
g_val
;
img_in
[
i
++
]
=
g_val
;
img_in
[
i
++
]
=
b_val
;
img_in
[
i
++
]
=
b_val
;
...
...
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