<commit_before>#include "SkCanvas.h"
#include "SkCommandLineFlags.h"
#include "SkData.h"
#include "SkDocument.h"
#include "SkGraphics.h"
#include "SkSurface.h"
#include "SkImage.h"
#include "SkImageFilter.h"
#include "SkStream.h"
#include "SkString.h"
#include "SkPaint.h"
#include "SkImageGenerator.h"

#include <boost/python.hpp>
#include <stdexcept>

#define IMAGE_QUALITY 70

#ifdef SIPSKIA_BGRA
#define SIPSKIA_COLORTYPE kBGRA_8888_SkColorType
#else
#define SIPSKIA_COLORTYPE kN32_SkColorType
#endif


boost::python::object convert_original(char* data, long size, bool is_gallery_card) {
	SkBitmap bm;
	sk_sp<SkData> skdata(SkData::MakeWithoutCopy((void*)data, size));
	if(!data) return boost::python::object();
	std::unique_ptr<SkImageGenerator> gen = SkImageGenerator::MakeFromEncoded(skdata);
	if(!gen) return boost::python::object();

	SkImageInfo bmInfo = gen->getInfo();
	gen->tryGenerateBitmap(&bm, bmInfo, nullptr);

	float width = 720.0f;
	float height = 720.0f;
	if(is_gallery_card){
	height = 1120.0f;
	}

	SkPaint paint;
	paint.setAntiAlias(true);
	paint.setStyle(SkPaint::kFill_Style);
	paint.setFilterQuality(kHigh_SkFilterQuality);

	sk_sp<SkSurface> surface(SkSurface::MakeRaster(SkImageInfo::Make(width, height, SIPSKIA_COLORTYPE, kPremul_SkAlphaType, nullptr)).release());
	SkCanvas* canvas = surface->getCanvas();
	canvas->drawBitmapRect(bm, SkRect::MakeLTRB(0, 0, width, height), SkRect::MakeXYWH(0.0f, 0.0f, width, height), &paint);
	sk_sp<SkImage> img(surface->makeImageSnapshot());
	if(!img) return boost::python::object();
	sk_sp<SkData> jpg(img->encode(SkEncodedImageFormat::kJPEG, IMAGE_QUALITY));
	if(!jpg) return boost::python::object();

	return boost::python::object(boost::python::handle<>(PyString_FromStringAndSize((char*)jpg->data(), jpg->size())));
}

boost::python::object convert_list(char* data, long size) {
	SkBitmap bm;
	sk_sp<SkData> skdata(SkData::MakeWithoutCopy((void*)data, size));
	if(!data) return boost::python::object();
	std::unique_ptr<SkImageGenerator> gen = SkImageGenerator::MakeFromEncoded(skdata);
	if(!gen) return boost::python::object();

	SkImageInfo bmInfo = gen->getInfo();<commit_msg>convert_original 함수에서 원본 이미지 사이즈가 변환하고자 하는 사이즈와 동일할 경우 그냥 리턴하도록 변경<commit_after>#include "SkCanvas.h"
#include "SkCommandLineFlags.h"
#include "SkData.h"
#include "SkDocument.h"
#include "SkGraphics.h"
#include "SkSurface.h"
#include "SkImage.h"
#include "SkImageFilter.h"
#include "SkStream.h"
#include "SkString.h"
#include "SkPaint.h"
#include "SkImageGenerator.h"

#include <boost/python.hpp>
#include <stdexcept>

#define IMAGE_QUALITY 70

#ifdef SIPSKIA_BGRA
#define SIPSKIA_COLORTYPE kBGRA_8888_SkColorType
#else
#define SIPSKIA_COLORTYPE kN32_SkColorType
#endif


boost::python::object convert_original(char* data, long size, bool is_gallery_card) {
	SkBitmap bm;
	sk_sp<SkData> skdata(SkData::MakeWithoutCopy((void*)data, size));
	if(!data) return boost::python::object();
	std::unique_ptr<SkImageGenerator> gen = SkImageGenerator::MakeFromEncoded(skdata);
	if(!gen) return boost::python::object();

	SkImageInfo bmInfo = gen->getInfo();
	gen->tryGenerateBitmap(&bm, bmInfo, nullptr);

	float width = 720.0f;
	float height = 720.0f;
	if(is_gallery_card){
		height = 1120.0f;
	}

	if(bm.width() == (int)width && bm.height() == (int)height) {
		return boost::python::object(boost::python::handle<>(PyString_FromStringAndSize(data, size)));
	}

	SkPaint paint;
	paint.setAntiAlias(true);
	paint.setStyle(SkPaint::kFill_Style);
	paint.setFilterQuality(kHigh_SkFilterQuality);

	sk_sp<SkSurface> surface(SkSurface::MakeRaster(SkImageInfo::Make(width, height, SIPSKIA_COLORTYPE, kPremul_SkAlphaType, nullptr)).release());
	SkCanvas* canvas = surface->getCanvas();
	canvas->drawBitmapRect(bm, SkRect::MakeLTRB(0, 0, width, height), SkRect::MakeXYWH(0.0f, 0.0f, width, height), &paint);
	sk_sp<SkImage> img(surface->makeImageSnapshot());
	if(!img) return boost::python::object();
	sk_sp<SkData> jpg(img->encode(SkEncodedImageFormat::kJPEG, IMAGE_QUALITY));
	if(!jpg) return boost::python::object();

	return boost::python::object(boost::python::handle<>(PyString_FromStringAndSize((char*)jpg->data(), jpg->size())));
}

boost::python::object convert_list(char* data, long size) {
	SkBitmap bm;
	sk_sp<SkData> skdata(SkData::MakeWithoutCopy((void*)data, size));
	if(!data) return boost::python::object();
	std::unique_ptr<SkImageGenerator> gen = SkImageGenerator::MakeFromEncoded(skdata);
	if(!gen) return boost::python::object();

	SkImageInfo bmInfo = gen->getInfo();
{'fraction_non_alphanumeric': 0.16014156160141563, 'fraction_numerical': 0.011944260119442602, 'mean_word_length': 8.480083857442349, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 42, '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': '7336544', 'n_tokens_mistral': 1728, 'n_tokens_neox': 1690, 'n_words': 292}