You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
86 lines
1.8 KiB
86 lines
1.8 KiB
11 years ago
|
#include <includes.hpp>
|
||
11 years ago
|
#include <utilities.hpp>
|
||
11 years ago
|
|
||
11 years ago
|
#include "jcmp_image.hpp"
|
||
|
|
||
11 years ago
|
namespace jcmp{
|
||
11 years ago
|
inline bool operator==(coefficient const & lhs, coefficient const & rhs){
|
||
11 years ago
|
return lhs.c == rhs.c && lhs.x == rhs.x && lhs.y == rhs.y;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
struct gen{
|
||
|
jcmp::uint width, x, y;
|
||
|
|
||
|
jcmp::coefficient operator()(){
|
||
|
++x;
|
||
|
if(x > width){
|
||
|
x = 0;
|
||
|
++y;
|
||
|
}
|
||
|
// only for testing purpose :D
|
||
11 years ago
|
return {uint8_t(rand()), x, y};
|
||
11 years ago
|
}
|
||
|
};
|
||
|
|
||
11 years ago
|
static void test_correctness(){
|
||
11 years ago
|
const int w = 1024, h = 512;
|
||
|
std::vector<jcmp::coefficient> v(w*h / 100);
|
||
|
std::generate(v.begin(), v.end(), gen{w, 0, 0});
|
||
|
|
||
11 years ago
|
{ // iterator method
|
||
11 years ago
|
jcmp::write_to_file({w, h, 0, {0.0, 0.0}}, v.begin(), v.end(), "test.jcmp");
|
||
11 years ago
|
auto j = jcmp::read_from_file("test.jcmp");
|
||
|
|
||
|
assert(w == j.header.width);
|
||
|
assert(h == j.header.height);
|
||
|
assert(v == j.data);
|
||
|
}
|
||
|
|
||
|
{ // copy method
|
||
11 years ago
|
jcmp::image i(w, h, {0.0, 0.0}, std::move(v));
|
||
11 years ago
|
|
||
|
jcmp::write_to_file(i, "test.jcmp");
|
||
|
auto j = jcmp::read_from_file("test.jcmp");
|
||
|
|
||
|
assert(w == j.header.width);
|
||
|
assert(h == j.header.height);
|
||
|
assert(i.data == j.data);
|
||
|
}
|
||
|
}
|
||
|
|
||
11 years ago
|
static void test_speed(){
|
||
11 years ago
|
const int w = 4000, h = 8000;
|
||
|
std::vector<jcmp::coefficient> input(w*h / 20);
|
||
|
std::generate(input.begin(), input.end(), gen{w, 0, 0});
|
||
11 years ago
|
|
||
11 years ago
|
for(int i = 0; i < 10; ++i){
|
||
|
{ timer t("stream");
|
||
11 years ago
|
jcmp::write_to_file({w, h, 0, {0.0, 0.0}}, input.begin(), input.end(), "stream.jcmp");
|
||
11 years ago
|
}
|
||
|
|
||
|
std::vector<jcmp::coefficient> copy(w*h / 20);
|
||
|
std::copy(input.begin(), input.end(), copy.begin());
|
||
11 years ago
|
|
||
11 years ago
|
{ timer t("move");
|
||
11 years ago
|
jcmp::image j(w, h, {0.0, 0.0}, std::move(copy));
|
||
|
jcmp::write_to_file(j, "move.jcmp");
|
||
11 years ago
|
}
|
||
11 years ago
|
|
||
11 years ago
|
{ timer t("copy");
|
||
11 years ago
|
jcmp::image j(w, h, {0.0, 0.0}, input);
|
||
|
jcmp::write_to_file(j, "copy.jcmp");
|
||
11 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
int main(){
|
||
|
srand(time(0));
|
||
|
|
||
|
test_correctness();
|
||
11 years ago
|
std::cout << "Test succeeded" << std::endl;
|
||
11 years ago
|
|
||
|
test_speed();
|
||
|
std::cout << "Test completed" << std::endl;
|
||
11 years ago
|
}
|