cpp: fix whitespaces
- strip trailing WS - 8-char tabs -> 8 spaces - use 2 spaces for indentation consistently
This commit is contained in:
parent
e79df170f5
commit
92ecfa55f2
1 changed files with 75 additions and 75 deletions
|
@ -147,7 +147,7 @@ CharData getCharData(const cimg_library::CImg<unsigned char> & image, int x0, in
|
|||
bg_count++;
|
||||
}
|
||||
for (int i = 0; i < 3; i++) {
|
||||
avg[i] += image(x0 + x, y0 + y, 0, i);
|
||||
avg[i] += image(x0 + x, y0 + y, 0, i);
|
||||
}
|
||||
mask = mask >> 1;
|
||||
}
|
||||
|
@ -177,10 +177,10 @@ CharData getCharData(const cimg_library::CImg<unsigned char> & image, int x0, in
|
|||
for (int x = 0; x < 4; x++) {
|
||||
long color = 0;
|
||||
for (int i = 0; i < 3; i++) {
|
||||
int d = image(x0 + x, y0 + y, 0, i);
|
||||
min[i] = std::min(min[i], d);
|
||||
max[i] = std::max(max[i], d);
|
||||
color = (color << 8) | d;
|
||||
int d = image(x0 + x, y0 + y, 0, i);
|
||||
min[i] = std::min(min[i], d);
|
||||
max[i] = std::max(max[i], d);
|
||||
color = (color << 8) | d;
|
||||
}
|
||||
count_per_color[color]++;
|
||||
}
|
||||
|
@ -207,19 +207,19 @@ CharData getCharData(const cimg_library::CImg<unsigned char> & image, int x0, in
|
|||
for (int y = 0; y < 8; y++) {
|
||||
for (int x = 0; x < 4; x++) {
|
||||
bits = bits << 1;
|
||||
int d1 = 0;
|
||||
int d2 = 0;
|
||||
for (int i = 0; i < 3; i++) {
|
||||
int shift = 16 - 8 * i;
|
||||
int c1 = (max_count_color_1 >> shift) & 255;
|
||||
int c2 = (max_count_color_2 >> shift) & 255;
|
||||
int c = image(x0 + x, y0 + y, 0, i);
|
||||
d1 += (c1-c) * (c1-c);
|
||||
d2 += (c2-c) * (c2-c);
|
||||
int d1 = 0;
|
||||
int d2 = 0;
|
||||
for (int i = 0; i < 3; i++) {
|
||||
int shift = 16 - 8 * i;
|
||||
int c1 = (max_count_color_1 >> shift) & 255;
|
||||
int c2 = (max_count_color_2 >> shift) & 255;
|
||||
int c = image(x0 + x, y0 + y, 0, i);
|
||||
d1 += (c1-c) * (c1-c);
|
||||
d2 += (c2-c) * (c2-c);
|
||||
}
|
||||
if (d1 > d2) {
|
||||
if (d1 > d2) {
|
||||
bits |= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -242,7 +242,7 @@ CharData getCharData(const cimg_library::CImg<unsigned char> & image, int x0, in
|
|||
for (int x = 0; x < 4; x++) {
|
||||
bits = bits << 1;
|
||||
if (image(x0 + x, y0 + y, 0, splitIndex) > splitValue) {
|
||||
bits |= 1;
|
||||
bits |= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -259,10 +259,10 @@ CharData getCharData(const cimg_library::CImg<unsigned char> & image, int x0, in
|
|||
for (int j = 0; j < 2; j++) {
|
||||
int diff = (std::bitset<32>(pattern ^ bits)).count();
|
||||
if (diff < best_diff) {
|
||||
best_pattern = BITMAPS[i]; // pattern might be inverted.
|
||||
codepoint = BITMAPS[i + 1];
|
||||
best_diff = diff;
|
||||
inverted = best_pattern != pattern;
|
||||
best_pattern = BITMAPS[i]; // pattern might be inverted.
|
||||
codepoint = BITMAPS[i + 1];
|
||||
best_diff = diff;
|
||||
inverted = best_pattern != pattern;
|
||||
}
|
||||
pattern = ~pattern;
|
||||
}
|
||||
|
@ -389,10 +389,10 @@ void emit_image(const cimg_library::CImg<unsigned char> & image, int flags) {
|
|||
|
||||
struct size {
|
||||
size(unsigned int in_width, unsigned int in_height) :
|
||||
width(in_width), height(in_height) {
|
||||
width(in_width), height(in_height) {
|
||||
}
|
||||
size(cimg_library::CImg<unsigned int> img) :
|
||||
width(img.width()), height(img.height()) {
|
||||
width(img.width()), height(img.height()) {
|
||||
}
|
||||
unsigned int width;
|
||||
unsigned int height;
|
||||
|
@ -431,17 +431,17 @@ enum Mode {AUTO, THUMBNAILS, FULL_SIZE};
|
|||
/* Wrapper around CImg<T>(const char*) to ensure the result has 3 channels as RGB
|
||||
*/
|
||||
cimg_library::CImg<unsigned char> load_rgb_CImg(const char * const filename) {
|
||||
cimg_library::CImg<unsigned char> image(filename);
|
||||
if(image.spectrum() == 1) {
|
||||
// Greyscale. Just copy greyscale data to all channels
|
||||
cimg_library::CImg<unsigned char> rgb_image(image.width(), image.height(), image.depth(), 3);
|
||||
for(unsigned int chn = 0; chn < 3; chn++) {
|
||||
rgb_image.draw_image(0, 0, 0,chn, image);
|
||||
}
|
||||
return rgb_image;
|
||||
}
|
||||
cimg_library::CImg<unsigned char> image(filename);
|
||||
if(image.spectrum() == 1) {
|
||||
// Greyscale. Just copy greyscale data to all channels
|
||||
cimg_library::CImg<unsigned char> rgb_image(image.width(), image.height(), image.depth(), 3);
|
||||
for(unsigned int chn = 0; chn < 3; chn++) {
|
||||
rgb_image.draw_image(0, 0, 0,chn, image);
|
||||
}
|
||||
return rgb_image;
|
||||
}
|
||||
|
||||
return image;
|
||||
return image;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
|
@ -501,7 +501,7 @@ int main(int argc, char* argv[]) {
|
|||
if (std::experimental::filesystem::is_regular_file(p.path())) {
|
||||
file_names.push_back(p.path().string());
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
file_names.push_back(arg);
|
||||
}
|
||||
|
@ -512,16 +512,16 @@ int main(int argc, char* argv[]) {
|
|||
if (mode == FULL_SIZE || (mode == AUTO && file_names.size() == 1)) {
|
||||
for (unsigned int i = 0; i < file_names.size(); i++) {
|
||||
try {
|
||||
cimg_library::CImg<unsigned char> image = load_rgb_CImg(file_names[i].c_str());
|
||||
cimg_library::CImg<unsigned char> image = load_rgb_CImg(file_names[i].c_str());
|
||||
|
||||
if (image.width() > maxWidth || image.height() > maxHeight) {
|
||||
size new_size = size(image).fitted_within(size(maxWidth,maxHeight));
|
||||
image.resize(new_size.width, new_size.height, -100, -100, 5);
|
||||
}
|
||||
emit_image(image, flags);
|
||||
if (image.width() > maxWidth || image.height() > maxHeight) {
|
||||
size new_size = size(image).fitted_within(size(maxWidth,maxHeight));
|
||||
image.resize(new_size.width, new_size.height, -100, -100, 5);
|
||||
}
|
||||
emit_image(image, flags);
|
||||
} catch(cimg_library::CImgIOException & e) {
|
||||
error = 1;
|
||||
std::cerr << "File format is not recognized for '" << file_names[i] << "'" << std::endl;
|
||||
error = 1;
|
||||
std::cerr << "File format is not recognized for '" << file_names[i] << "'" << std::endl;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -538,21 +538,21 @@ int main(int argc, char* argv[]) {
|
|||
int count = 0;
|
||||
std::string sb;
|
||||
while (index < file_names.size() && count < columns) {
|
||||
std::string name = file_names[index++];
|
||||
try {
|
||||
cimg_library::CImg<unsigned char> original = load_rgb_CImg(name.c_str());
|
||||
auto cut = name.find_last_of("/");
|
||||
sb += cut == std::string::npos ? name : name.substr(cut + 1);
|
||||
size newSize = size(original).fitted_within(maxThumbSize);
|
||||
original.resize(newSize.width, newSize.height, 1, -100, 5);
|
||||
image.draw_image(count * (tw + 8) + (tw - newSize.width) / 2, (tw - newSize.height) / 2, 0, 0, original);
|
||||
count++;
|
||||
unsigned int sl = count * (cw + 2);
|
||||
sb.resize(sl - 2, ' ');
|
||||
sb += " ";
|
||||
} catch (std::exception & e) {
|
||||
// Probably no image; ignore.
|
||||
}
|
||||
std::string name = file_names[index++];
|
||||
try {
|
||||
cimg_library::CImg<unsigned char> original = load_rgb_CImg(name.c_str());
|
||||
auto cut = name.find_last_of("/");
|
||||
sb += cut == std::string::npos ? name : name.substr(cut + 1);
|
||||
size newSize = size(original).fitted_within(maxThumbSize);
|
||||
original.resize(newSize.width, newSize.height, 1, -100, 5);
|
||||
image.draw_image(count * (tw + 8) + (tw - newSize.width) / 2, (tw - newSize.height) / 2, 0, 0, original);
|
||||
count++;
|
||||
unsigned int sl = count * (cw + 2);
|
||||
sb.resize(sl - 2, ' ');
|
||||
sb += " ";
|
||||
} catch (std::exception & e) {
|
||||
// Probably no image; ignore.
|
||||
}
|
||||
}
|
||||
if (count) emit_image(image, flags);
|
||||
std::cout << sb << std::endl << std::endl;
|
||||
|
|
Loading…
Reference in a new issue