<commit_before>/* 
 * File:   ImageServiceImpl.cpp
 * Author: mamad
 * 
 * Created on 22 September 2013, 23:09
 */

#include <stdlib.h>
#include "ImageServiceImpl.h"
#include "service_types.h"

#if !defined(LEPTONICA_ALLHEADERS_H)
#   include <leptonica/allheaders.h>
#include <string.h>
#endif

using namespace std;

ImageServiceImpl::ImageServiceImpl(const int threads) {
}

ImageServiceImpl::~ImageServiceImpl() {
}

int8_t ImageServiceImpl::handlePing() {
    cout << "ping\n";
    return 0;
}

void ImageServiceImpl::handleResize(TImageResponse& _return, const TImage& request) {
    if (request.data.length() < 1) {
        _return.__set_error("Invalid data");
        return;
    }
    cout << "resize request, w:"<< request.width << ", h:" << request.height <<"\n";
    l_uint8* data = (l_uint8*)request.data.data();
    PIX* pix = pixReadMem(data, request.data.length());
    if (pix != NULL) {
        cout<< "Resizing image\n";
        l_float32 pw = pixGetWidth(pix);
        l_float32 ph = pixGetHeight(pix);
        l_float32 s = min(request.width / pw, request.height / ph);
        PIX* scaledPix = pixScale(pix, s, s); 
        if (scaledPix != NULL) {
            l_uint8 *bytes = NULL;
            size_t size = 0;
            
            if (0 == pixWriteMem(&bytes, &size, scaledPix, pix->informat)) {
                TImage result;
                result.__set_width(scaledPix->w);
                result.__set_height(scaledPix->h);
                result.__set_data(std::string((char*)bytes, size));
                _return.__set_result(result);
                cout<<"new size:"<<_return.result.data.length()<<", original size:"<< request.data.length() <<"\n";
            }
            pixDestroy(&scaledPix);
        }        
        pixDestroy(&pix);
    } else {
        _return.error = "Could not create image from data";
    }
}


<commit_msg>fixed thrift reply in image-service handler, updated client<commit_after>/* 
 * File:   ImageServiceImpl.cpp
 * Author: mamad
 * 
 * Created on 22 September 2013, 23:09
 */

#include <stdlib.h>
#include "ImageServiceImpl.h"
#include "service_types.h"

#if !defined(LEPTONICA_ALLHEADERS_H)
#   include <leptonica/allheaders.h>
#include <string.h>
#endif

using namespace std;

ImageServiceImpl::ImageServiceImpl(const int threads) {
}

ImageServiceImpl::~ImageServiceImpl() {
}

int8_t ImageServiceImpl::handlePing() {
    cout << "ping\n";
    return 0;
}

void ImageServiceImpl::handleResize(TImageResponse& _return, const TImage& request) {
    if (request.data.length() < 1) {
        _return.__set_error("Invalid data");
        return;
    }
    cout << "resize request, w:"<< request.width << ", h:" << request.height <<"\n";
    l_uint8* data = (l_uint8*)request.data.data();
    PIX* pix = pixReadMem(data, request.data.length());
    if (pix != NULL) {
        cout<< "Resizing image\n";
        l_float32 pw = pixGetWidth(pix);
        l_float32 ph = pixGetHeight(pix);
        l_float32 s = min(request.width / pw, request.height / ph);
        PIX* scaledPix = pixScale(pix, s, s); 
        if (scaledPix != NULL) {
            l_uint8 *bytes = NULL;
            size_t size = 0;
            
            if (0 == pixWriteMem(&bytes, &size, scaledPix, pix->informat)) {
                TImage result;
                result.__set_width(scaledPix->w);
                result.__set_height(scaledPix->h);
                result.__set_data(std::string((char*)bytes, size));
                _return.__set_result(result);
                cout<<"new size:"<<_return.result.data.length()<<", original size:"<< request.data.length() <<"\n";
            }
            pixDestroy(&scaledPix);
        }        
        pixDestroy(&pix);
    } else {
        _return.__set_error("Could not create image from data");
    }
}



{'fraction_non_alphanumeric': 0.1449618521441726, 'fraction_numerical': 0.012628255722178374, 'mean_word_length': 2.5367441860465116, 'pattern_counts': {'":': 0, '<': 59, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4718951', 'n_tokens_mistral': 1293, 'n_tokens_neox': 1205, 'n_words': 256}