Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CppRaytracer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
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
Show more breadcrumbs
Yoel
CppRaytracer
Commits
61136405
Commit
61136405
authored
4 years ago
by
Yoel
Browse files
Options
Downloads
Patches
Plain Diff
New readImage-method
parent
8e693c75
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
RayTracer/sampling/Image.cpp
+21
-0
21 additions, 0 deletions
RayTracer/sampling/Image.cpp
RayTracer/sampling/Image.h
+1
-0
1 addition, 0 deletions
RayTracer/sampling/Image.h
with
22 additions
and
0 deletions
RayTracer/sampling/Image.cpp
+
21
−
0
View file @
61136405
...
@@ -5,6 +5,8 @@
...
@@ -5,6 +5,8 @@
#include
"../tools/Threadpool.h"
#include
"../tools/Threadpool.h"
#include
"StratifiedSampler.h"
#include
"StratifiedSampler.h"
#define STB_IMAGE_IMPLEMENTATION
#include
"../tools/stb_image.h"
namespace
util
{
namespace
util
{
Image
::
Image
(
int
width
,
int
height
)
:
width
(
width
),
height
(
height
)
{
Image
::
Image
(
int
width
,
int
height
)
:
width
(
width
),
height
(
height
)
{
...
@@ -150,4 +152,23 @@ void writeBmp(const char* filename, Image img) {
...
@@ -150,4 +152,23 @@ void writeBmp(const char* filename, Image img) {
ofile
.
close
();
ofile
.
close
();
}
}
Image
readImage
(
const
char
*
filename
)
{
int
width
,
height
,
channels
;
unsigned
char
*
img
=
stbi_load
(
filename
,
&
width
,
&
height
,
&
channels
,
0
);
Image
result
(
width
,
height
);
if
(
channels
!=
3
)
std
::
cout
<<
"Careful! Loaded image has "
<<
channels
<<
" channels"
<<
std
::
endl
;
size_t
img_size
=
width
*
height
*
channels
;
int
i
=
0
;
for
(
unsigned
char
*
p
=
img
;
p
!=
img
+
img_size
;
p
+=
channels
)
{
float
x
=
(
float
)
*
(
p
+
0
)
/
255
;
float
y
=
(
float
)
*
(
p
+
1
)
/
255
;
float
z
=
(
float
)
*
(
p
+
2
)
/
255
;
result
[{
i
,
0
}]
=
Vec3
(
x
,
y
,
z
);
i
++
;
}
return
result
;
}
}
// namespace util
}
// namespace util
\ No newline at end of file
This diff is collapsed.
Click to expand it.
RayTracer/sampling/Image.h
+
1
−
0
View file @
61136405
...
@@ -30,5 +30,6 @@ class Image {
...
@@ -30,5 +30,6 @@ class Image {
Image
raytrace
(
size_t
threadcount
,
const
cam
::
CamObs
&
cam
,
Image
raytrace
(
size_t
threadcount
,
const
cam
::
CamObs
&
cam
,
const
std
::
shared_ptr
<
Sampler
>&
sampler
,
size_t
n
);
const
std
::
shared_ptr
<
Sampler
>&
sampler
,
size_t
n
);
void
writeBmp
(
const
char
*
filename
,
Image
img
);
void
writeBmp
(
const
char
*
filename
,
Image
img
);
Image
readImage
(
const
char
*
filename
);
}
// namespace util
}
// namespace util
\ No newline at end of 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