Skip to content

Commit

Permalink
indentation fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
RonnyldoSilva authored Mar 22, 2019
1 parent a0e3305 commit 2ef0991
Showing 1 changed file with 41 additions and 41 deletions.
82 changes: 41 additions & 41 deletions ConvertImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,42 @@ static const std::string base64_chars =
"abcdefghijklmnopqrstuvwxyz"
"0123456789+/";

static inline bool is_base64( unsigned char c ) {

static inline bool is_base64( unsigned char c )
{
return (isalnum(c) || (c == '+') || (c == '/'));
}

std::string ImagemConverter::base64_encode(uchar const* bytes_to_encode, unsigned int in_len) {
std::string ImagemConverter::base64_encode(uchar const* bytes_to_encode, unsigned int in_len)
{
std::string ret;

int i = 0;
int j = 0;
unsigned char char_array_3[3];
unsigned char char_array_4[4];

while (in_len--) {

while (in_len--)
{
char_array_3[i++] = *(bytes_to_encode++);
if (i == 3) {

if (i == 3)
{
char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
char_array_4[3] = char_array_3[2] & 0x3f;

for (i = 0; (i <4); i++) {
for (i = 0; (i <4); i++)
{
ret += base64_chars[char_array_4[i]];

}
i = 0;
}
}

if (i) {

for (j = i; j < 3; j++) {

if (i)
{
for (j = i; j < 3; j++)
{
char_array_3[j] = '\0';
}

Expand All @@ -51,12 +51,12 @@ std::string ImagemConverter::base64_encode(uchar const* bytes_to_encode, unsigne
char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
char_array_4[3] = char_array_3[2] & 0x3f;

for (j = 0; (j < i + 1); j++) {

for (j = 0; (j < i + 1); j++)
{
ret += base64_chars[char_array_4[j]];
}
while ((i++ < 3)) {

while ((i++ < 3))
{
ret += '=';
}
}
Expand All @@ -74,63 +74,63 @@ std::string ImagemConverter::base64_decode(std::string const& encoded_string) {
unsigned char char_array_4[4], char_array_3[3];
std::string ret;

while (in_len-- && (encoded_string[in_] != '=') && is_base64(encoded_string[in_])) {

while (in_len-- && (encoded_string[in_] != '=') && is_base64(encoded_string[in_]))
{
char_array_4[i++] = encoded_string[in_]; in_++;

if (i == 4) {

for (i = 0; i < 4; i++) {

if (i == 4)
{
for (i = 0; i < 4; i++)
{
char_array_4[i] = base64_chars.find(char_array_4[i]);
}

char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];

for (i = 0; (i < 3); i++) {

for (i = 0; (i < 3); i++)
{
ret += char_array_3[i];
}

i = 0;
}
}

if (i) {

for (j = i; j < 4; j++) {

if (i)
{
for (j = i; j < 4; j++)
{
char_array_4[j] = 0;
}

for (j = 0; j < 4; j++) {

for (j = 0; j < 4; j++)
{
char_array_4[j] = base64_chars.find(char_array_4[j]);
}

char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];

for (j = 0; (j < i - 1); j++) {

for (j = 0; (j < i - 1); j++)
{
ret += char_array_3[j];
}
}

return ret;
}

string ImagemConverter::mat2str(const Mat& m) {

string ImagemConverter::mat2str(const Mat& m)
{
int params[3] = {0};
params[0] = CV_IMWRITE_JPEG_QUALITY;
params[1] = 100;

vector<uchar> buf;
bool code = cv::imencode(".jpg", m, buf, std::vector<int>(params, params+2) );
bool code = cv::imencode(".jpg", m, buf, std::vector<int>(params, params+2));
uchar* result = reinterpret_cast<uchar*> (&buf[0]);

return base64_encode(result, buf.size());
Expand All @@ -139,8 +139,8 @@ string ImagemConverter::mat2str(const Mat& m) {



Mat ImagemConverter::str2mat(const string& s) {

Mat ImagemConverter::str2mat(const string& s)
{
// Decode data
string decoded_string = base64_decode(s);
vector<uchar> data(decoded_string.begin(), decoded_string.end());
Expand All @@ -149,7 +149,7 @@ Mat ImagemConverter::str2mat(const string& s) {
return img;
}

ImagemConverter::~ImagemConverter() {

ImagemConverter::~ImagemConverter()
{
// TODO Auto-generated destructor stub
}

0 comments on commit 2ef0991

Please sign in to comment.