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
dd93d802
Commit
dd93d802
authored
4 years ago
by
Yoel
Browse files
Options
Downloads
Patches
Plain Diff
WriteBmp now a static function of Image
parent
1279311c
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
+85
-0
85 additions, 0 deletions
RayTracer/sampling/Image.cpp
RayTracer/sampling/Image.h
+1
-0
1 addition, 0 deletions
RayTracer/sampling/Image.h
with
86 additions
and
0 deletions
RayTracer/sampling/Image.cpp
+
85
−
0
View file @
dd93d802
#include
"Image.h"
#include
"Image.h"
#include
<fstream>
#include
<iostream>
#include
"../tools/Threadpool.h"
#include
"../tools/Threadpool.h"
#include
"StratifiedSampler.h"
#include
"StratifiedSampler.h"
...
@@ -65,4 +68,86 @@ Image raytrace(size_t threadcount, const cam::CamObs& cam,
...
@@ -65,4 +68,86 @@ Image raytrace(size_t threadcount, const cam::CamObs& cam,
result
.
gammaCorrect
(
2.2
);
result
.
gammaCorrect
(
2.2
);
return
result
;
return
result
;
}
}
void
writeBmp
(
const
char
*
filename
,
Image
img
)
{
int
width
=
img
.
width
;
// Width of the image
int
height
=
img
.
height
;
// Height of the image
int
horizontalBytes
;
// Horizontal bytes to add, so the pixelarrays width
// is a multiple of 4
horizontalBytes
=
4
-
((
width
*
3
)
%
4
);
if
(
horizontalBytes
==
4
)
horizontalBytes
=
0
;
int
pixelArraySize
;
// The size of the pixelArray
pixelArraySize
=
((
width
*
3
)
+
horizontalBytes
)
*
height
;
// Headers
int
header
[
12
];
// Bitmap file header
char
bb
=
'B'
;
// bfType
char
mm
=
'M'
;
header
[
0
]
=
pixelArraySize
+
54
;
// bfSize
header
[
1
]
=
0
;
// bfReserved
header
[
2
]
=
54
;
// bfOffbits
// Bitmap information header
header
[
3
]
=
40
;
// biSize
header
[
4
]
=
width
;
// biWidth
header
[
5
]
=
height
;
// biHeight
short
biPLanes
=
1
;
// biPlanes
short
biBitCount
=
24
;
// biBitCount
header
[
6
]
=
0
;
// biCompression
header
[
7
]
=
pixelArraySize
;
// biSizeImage
header
[
8
]
=
0
;
// biXPelsPerMeter
header
[
9
]
=
0
;
// biYPelsPerMeter
header
[
10
]
=
0
;
// biClrUsed
header
[
11
]
=
0
;
// biClrImportant
std
::
ofstream
ofile
(
filename
,
std
::
ios
::
binary
);
// Write the header in the right order
// bfType, ...
ofile
.
write
(
&
bb
,
sizeof
(
bb
));
ofile
.
write
(
&
mm
,
sizeof
(
mm
));
// ... bfSize, BfReserved, bfOffbits, biSize, biWidth, bitHeight, ...
for
(
int
i
=
0
;
i
<
6
;
i
++
)
{
ofile
.
write
((
char
*
)
&
header
[
i
],
sizeof
(
header
[
i
]));
}
// ... biPlanes, bitBitCount, ...
ofile
.
write
((
char
*
)
&
biPLanes
,
sizeof
(
biPLanes
));
ofile
.
write
((
char
*
)
&
biBitCount
,
sizeof
(
biBitCount
));
// ... biCompression, biSizeImage, biXPelsPerMeter, biYPelsPerMeter,
// biClrUsed, biClrImportant
for
(
int
i
=
6
;
i
<
12
;
i
++
)
{
ofile
.
write
((
char
*
)
&
header
[
i
],
sizeof
(
header
[
i
]));
}
// The colors can only have a value from 0 to 255, so a char is enough to
// store them
char
blue
,
green
,
red
;
// Bmp is written from top to bottom
for
(
int
y
=
height
-
1
;
y
>=
0
;
y
--
)
{
for
(
int
x
=
0
;
x
<=
width
-
1
;
x
++
)
{
red
=
std
::
clamp
<
float
>
((
img
[{
x
,
y
}][
0
]),
0
,
1
)
*
255
;
green
=
std
::
clamp
<
float
>
((
img
[{
x
,
y
}][
1
]),
0
,
1
)
*
255
;
blue
=
std
::
clamp
<
float
>
((
img
[{
x
,
y
}][
2
]),
0
,
1
)
*
255
;
// bmp colors are bgr not rgb
char
bgr
[
3
]
=
{
blue
,
green
,
red
};
for
(
int
i
=
0
;
i
<
3
;
i
++
)
{
char
c0
=
(
bgr
[
i
]
&
0x00FF
);
// char c8 = ((bgr[i] & (unsigned int)0xFF00) >> 8);
ofile
.
write
(
&
c0
,
sizeof
(
c0
));
// ofile.write (&c8, sizeof (c8));
}
}
// If needed add extra bytes after each row
if
(
horizontalBytes
!=
0
)
{
char
null
;
for
(
int
n
=
0
;
n
<
horizontalBytes
;
n
++
)
{
ofile
.
write
(
&
null
,
sizeof
(
null
));
}
}
}
ofile
.
close
();
}
}
// 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 @
dd93d802
...
@@ -29,5 +29,6 @@ class Image {
...
@@ -29,5 +29,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
);
}
// 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