-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cf785ca
commit 6889dc6
Showing
281 changed files
with
902,683 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include "pgm16.h" | ||
|
||
int main(int argc, char** argv) { | ||
|
||
if (argc != 2) { | ||
return 1; | ||
} | ||
mat<uint16_t> img; | ||
uint16_t maxvalue; | ||
std::string filename(argv[1]); | ||
bool ret=load(filename, img, maxvalue); | ||
return ret; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#pragma once | ||
|
||
#include <vector> | ||
#include <cassert> | ||
|
||
template <typename T> | ||
class mat { | ||
int rows_, cols_; | ||
std::vector<T> data_; | ||
public: | ||
mat(int rows = 0, int cols = 0) { | ||
resize(rows, cols); | ||
} | ||
|
||
void resize(int rows, int cols) { | ||
assert(rows >= 0 && cols >= 0); | ||
rows_ = rows; | ||
cols_ = cols; | ||
data_.resize(rows*cols); | ||
} | ||
|
||
int rows() const { return rows_; } | ||
int cols() const { return cols_; } | ||
|
||
T& operator()(int r, int c) { | ||
assert(r >= 0 && c >= 0 && r < rows_ && c < cols_); | ||
return data_[r*cols_ + c]; | ||
} | ||
const T& operator()(int r, int c) const { | ||
assert(r >= 0 && c >= 0 && r < rows_ && c < cols_); | ||
return data_[r*cols_ + c]; | ||
} | ||
|
||
T* data() { return data_.data(); } | ||
const T* data() const { return data_.data(); } | ||
int size() const { return rows_ * cols_; } | ||
|
||
char* rawdata() { return reinterpret_cast<char*>(data_.data()); } | ||
const char* rawdata() const { return reinterpret_cast<const char*>(data_.data()); } | ||
int rawsize() const { return rows_ * cols_ * sizeof(T); } | ||
|
||
auto begin() { return data_.begin(); } | ||
auto begin() const { return data_.begin(); } | ||
auto end() { return data_.end(); } | ||
auto end() const { return data_.end(); } | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#include "pgm16.h" | ||
#include <sstream> | ||
#include <intrin.h> | ||
#include <fstream> | ||
bool load(const std::string& filename, mat<uint16_t>& img, uint16_t& maxvalue) { | ||
|
||
if (filename.empty()) | ||
{ | ||
return 1; | ||
} | ||
|
||
int H, W; | ||
uint16_t ch; | ||
std::string comment, magic_number,line; | ||
//std::ifstream is(filename, std::ios::binary); | ||
std::ifstream is(filename, std::ios::binary); | ||
if (!is) | ||
{ | ||
return false; | ||
} | ||
|
||
std::getline(is, magic_number); | ||
|
||
if (magic_number != "P5") | ||
{ | ||
return false; | ||
} | ||
std::getline(is, line); //commento | ||
if (line[0] != '#') | ||
{ | ||
return false; | ||
} | ||
if (!(is >> W)) | ||
{ | ||
return false; | ||
} | ||
if (!(is >> H)) | ||
{ | ||
return false; | ||
} | ||
if (!(is >> maxvalue)) | ||
{ | ||
return false; | ||
} | ||
|
||
img.resize(H, W); | ||
is.get(); | ||
for (int r = 0; r < img.rows(); r++) | ||
{ | ||
for (int c = 0; c < img.cols(); c++) | ||
{ | ||
if (maxvalue < 256) { | ||
|
||
img(r, c) = is.get(); | ||
} | ||
else | ||
{ | ||
is.read(reinterpret_cast<char*>(&ch),sizeof(uint16_t)); | ||
uint8_t b1 = (ch >> 8) & 0xFF; | ||
uint8_t b2 = ch & 0xFF; | ||
img(r, c) = (b2<<8)+b1; | ||
//oppure | ||
//img(r, c) = _byteswap_ushort(ch); | ||
|
||
|
||
} | ||
|
||
} | ||
} | ||
|
||
return true; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#pragma once | ||
#include <string> | ||
#include "mat.h" | ||
bool load(const std::string& filename, mat<uint16_t>& img, uint16_t& maxvalue); |
Oops, something went wrong.