We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent d4c3c41 commit 6683378Copy full SHA for 6683378
src/TheRestOfYourLife/rtw_stb_image.h
@@ -102,6 +102,14 @@ class rtw_image {
102
return high - 1;
103
}
104
105
+ static unsigned char float_to_byte(float value) {
106
+ if (value <= 0.0)
107
+ return 0;
108
+ if (1.0 <= value)
109
+ return 255;
110
+ return static_cast< unsigned char >(256.0 * value);
111
+ }
112
+
113
void convert_to_bytes() {
114
// Convert the linear floating point pixel data to bytes, storing the resulting byte
115
// data in the `bdata` member.
@@ -115,7 +123,7 @@ class rtw_image {
123
auto *bptr = bdata;
116
124
auto *fptr = fdata;
117
125
for (auto i=0; i < total_bytes; i++, fptr++, bptr++)
118
- *bptr = static_cast<unsigned char>(*fptr * 256.0);
126
+ *bptr = float_to_byte(*fptr);
119
127
120
128
};
121
129
0 commit comments