changed everything to lowercase, made test3 simpler
This commit is contained in:
parent
7de30322a9
commit
27db4e00ee
4 changed files with 27 additions and 31 deletions
|
@ -18,6 +18,9 @@
|
|||
p(int v)
|
||||
p(double v)
|
||||
|
||||
The order in the ctor is rgb even though the internal structure may be
|
||||
different
|
||||
|
||||
It should be trivially writable with memcpy (TODO: check exact requirement)
|
||||
|
||||
Furthermore it should have a static constexpr size_t num_colors indicating the
|
||||
|
@ -30,35 +33,35 @@ namespace pixel_formats {
|
|||
return std::min(255, std::max(0, n));
|
||||
}
|
||||
|
||||
struct Gray {
|
||||
struct gray {
|
||||
static constexpr size_t num_colors = 1;
|
||||
static constexpr size_t bits_per_color = 8;
|
||||
|
||||
Gray() : value(0) {}
|
||||
Gray(double intensity) : value(clamp(255*intensity)) {}
|
||||
Gray(int intensity) : value(clamp(intensity)) {}
|
||||
gray() : value(0) {}
|
||||
gray(double intensity) : value(clamp(255*intensity)) {}
|
||||
gray(int intensity) : value(clamp(intensity)) {}
|
||||
|
||||
private:
|
||||
uint8_t value;
|
||||
};
|
||||
|
||||
struct RGB {
|
||||
struct rgb {
|
||||
static constexpr size_t num_colors = 3;
|
||||
static constexpr size_t bits_per_color = 8;
|
||||
|
||||
RGB()
|
||||
rgb()
|
||||
: red(0)
|
||||
, green(0)
|
||||
, blue(0)
|
||||
{}
|
||||
|
||||
RGB(double red, double green, double blue)
|
||||
rgb(double red, double green, double blue)
|
||||
: red(clamp(255*red))
|
||||
, green(clamp(255*green))
|
||||
, blue(clamp(255*blue))
|
||||
{}
|
||||
|
||||
RGB(int red, int green, int blue)
|
||||
rgb(int red, int green, int blue)
|
||||
: red(clamp(red))
|
||||
, green(clamp(green))
|
||||
, blue(clamp(blue))
|
||||
|
@ -70,23 +73,23 @@ namespace pixel_formats {
|
|||
uint8_t blue;
|
||||
};
|
||||
|
||||
struct BGR{
|
||||
struct bgr{
|
||||
static constexpr size_t num_colors = 3;
|
||||
static constexpr size_t bits_per_color = 8;
|
||||
|
||||
BGR()
|
||||
bgr()
|
||||
: blue(0)
|
||||
, green(0)
|
||||
, red(0)
|
||||
{}
|
||||
|
||||
BGR(double red, double green, double blue)
|
||||
bgr(double red, double green, double blue)
|
||||
: blue(clamp(255*blue))
|
||||
, green(clamp(255*green))
|
||||
, red(clamp(255*red))
|
||||
{}
|
||||
|
||||
BGR(int red, int green, int blue)
|
||||
bgr(int red, int green, int blue)
|
||||
: blue(clamp(blue))
|
||||
, green(clamp(green))
|
||||
, red(clamp(red))
|
||||
|
|
|
@ -15,6 +15,10 @@
|
|||
#include <algorithm>
|
||||
#include "basics.hpp"
|
||||
|
||||
/*
|
||||
Note that a bmp file is vertically flipped.
|
||||
*/
|
||||
|
||||
namespace bmp {
|
||||
// file header
|
||||
struct bitmap_file_header {
|
||||
|
@ -92,7 +96,7 @@ namespace bmp {
|
|||
struct default_color_table : public std::conditional<pixel_formats::traits<P>::bits_per_pixel <= 8, gray_color_table<pixel_formats::traits<P>::bits_per_pixel>, no_color_table>::type
|
||||
{};
|
||||
|
||||
template <typename P = pixel_formats::BGR, typename CT = default_color_table<P>>
|
||||
template <typename P = pixel_formats::bgr, typename CT = default_color_table<P>>
|
||||
struct bitmap_stream {
|
||||
typedef P pixel;
|
||||
typedef CT color_table;
|
||||
|
|
|
@ -43,7 +43,6 @@ void test2(std::string filename){
|
|||
}
|
||||
}
|
||||
|
||||
// because lambdas dont work yet...
|
||||
inline double nice_rand(){
|
||||
return rand() / double(RAND_MAX);
|
||||
}
|
||||
|
@ -51,31 +50,21 @@ inline double nice_rand(){
|
|||
template <typename ImageType>
|
||||
void test3(std::string filename){
|
||||
size_t size = 256;
|
||||
std::vector<double> arr(size*size);
|
||||
std::generate_n(arr.begin(), size*size, &nice_rand);
|
||||
std::vector<double> arr2(size*size, 0);
|
||||
|
||||
for(int i = 0; i < size*size; ++i){
|
||||
for (int j = i - 5; j <= i + 5; ++j) {
|
||||
if(j < 0 || j >= size*size) continue;
|
||||
arr2[i] += arr[j] * 0.1;
|
||||
}
|
||||
}
|
||||
|
||||
ImageType image(size, size, filename);
|
||||
|
||||
for(auto x : arr2)
|
||||
image << typename ImageType::pixel(x);
|
||||
for(int i = 0; i < size*size; ++i)
|
||||
image << typename ImageType::pixel(nice_rand());
|
||||
}
|
||||
|
||||
int main(int argc, const char * argv[]){
|
||||
test<png::png_stream<>>("test.png");
|
||||
test<bmp::bitmap_stream<>>("test.bmp");
|
||||
|
||||
test2<png::png_stream<pixel_formats::Gray>>("test_gray.png");
|
||||
test2<bmp::bitmap_stream<pixel_formats::Gray>>("test_gray.bmp");
|
||||
test2<png::png_stream<pixel_formats::gray>>("test_gray.png");
|
||||
test2<bmp::bitmap_stream<pixel_formats::gray>>("test_gray.bmp");
|
||||
|
||||
test3<png::png_stream<pixel_formats::Gray>>("test_3.png");
|
||||
test3<bmp::bitmap_stream<pixel_formats::Gray>>("test_3.bmp");
|
||||
test3<png::png_stream<pixel_formats::gray>>("test_3.png");
|
||||
test3<bmp::bitmap_stream<pixel_formats::gray>>("test_3.bmp");
|
||||
}
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ namespace png{
|
|||
}
|
||||
}
|
||||
|
||||
template <typename P = pixel_formats::RGB>
|
||||
template <typename P = pixel_formats::rgb>
|
||||
struct png_stream{
|
||||
typedef P pixel;
|
||||
|
||||
|
|
Reference in a new issue