-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.cpp
64 lines (55 loc) · 1.7 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "jpeg.h"
#include <iostream>
void display( uint8_t luma )
{
static std::vector<char> ascii{
' ', '.', ',', ':', '-', '=', '+', '*', '#', '%', '@'
};
int val = luma / 24;
std::cout << ascii[val] << ascii[val];
}
int main( int argc, char* argv[] )
{
if ( argc < 2 )
{
std::cout << "No jpeg file specified\n";
return 1;
}
try
{
using namespace marengo::jpeg;
// Constructor expects a filename to load:
Image imgOriginal( argv[1] );
// Copy construct a second version so we can
// shrink non-destructively. Not really necessary
// here, but just to show it can be done :)
Image img = imgOriginal;
// Shrink proportionally to a specific width (in px)
img.shrink( 60 );
// Display the image in ASCII, just for fun.
std::size_t height = img.getHeight();
std::size_t width = img.getWidth();
for ( std::size_t y = 0; y < height; ++y )
{
for ( std::size_t x = 0; x < width; ++x )
{
uint8_t luma = img.getLuminance( x, y );
display( luma );
}
std::cout << "\n";
}
std::cout << "\nImage height: " << img.getHeight();
std::cout << "\nImage width : " << img.getWidth();
// Pixel "Size" is 3 bytes for colour images (i.e. R,G, & B)
// and 1 byte for monochrome.
std::cout << "\nImage px sz : " << img.getPixelSize();
std::cout << std::endl;
return 0;
}
catch( const std::exception& e )
{
std::cout << "Main() error handler: ";
std::cout << e.what() << std::endl;
return 1;
}
}