<commit_before>#include "Image.h"


Image::Image(){
	hasMaxSize			= false;
	changed				= false;
    isUpdateReal		= false;
    img					= new ofImage();
    loaded				= false;
	loadingAsync		= false;
	loadingPlaceholder	= NULL;
	mode				= OF_RECTMODE_CORNER;

	tmpResizeCounter	= 0;
	tmpFilepath			= "";
}


Image::~Image(){
	img->clear();
}


void Image::update(){
	if (img) {
		if (loadingAsync) {
			if (img->getWidth() > 0) {
				loaded		= true;
				loadingAsync= false;
				changed		= true;
				BasicScreenObject::setSize(img->getWidth(), img->getHeight());
				if (loadingPlaceholder != NULL) {
					loadingPlaceholder->isVisible(false);
				}
				ofNotifyEvent(imageLoadedEvent, myEventArgs, this);
			}
		}
		if(changed){
			updateSize();
		}
	}
}


void Image::_draw(){
	if (img == NULL || loadingAsync) return;
	
	
	if (img->getWidth() > 0) {
		ofPushStyle();
		
		ofSetRectMode(mode);
        img->draw(0, 0, width, height);
		ofPopStyle();
	}
	/*
	 if (tmpResizeCounter>1) {
	 ofLog(OF_LOG_NOTICE, "resized more than once (" + ofToString(tmpResizeCounter) + "): " + tmpFilepath);
	 }
	 */
	tmpResizeCounter = 0;
}


void Image::load(string _filename){
	img->clear();
	img->loadImage(_filename);
	setSize(img->getWidth(), img->getHeight());
	changed = true;
	loaded  = true;
	ofNotifyEvent(imageLoadedEvent, myEventArgs, this);
	tmpFilepath = _filename;
}


void Image::loadAsyncFromDisk(string _filename, ofxThreadedImageLoader* loader) {
	loadingAsync = true;
	loaded		 = false;
	if (loadingPlaceholder != NULL) {
		loadingPlaceholder->isVisible(true);
	}
	img->clear();
	loader->loadFromDisk(img, _filename);
	tmpFilepath = _filename;
}


void Image::loadAsyncFromURL(string _url, ofxThreadedImageLoader* loader) {
	loadingAsync = true;
	loaded		 = false;
	if (loadingPlaceholder != NULL) {
		loadingPlaceholder->isVisible(true);
	}
	img->clear();
	loader->loadFromURL(img, _url);
}


void Image::setLoadingPlaceholder(BasicScreenObject* _loadingPlaceholder) {
	if (loadingPlaceholder != NULL) {
		removeChild(loadingPlaceholder);
	}
	loadingPlaceholder = _loadingPlaceholder;
	addChild(loadingPlaceholder);
	loadingPlaceholder->setPosition((width - loadingPlaceholder->getWidth())/2.0, (height - loadingPlaceholder->getHeight())/2.0);
	loadingPlaceholder->isVisible(false);
}


ofImage* Image::getImagePointer(){
	return img;
}


void Image::setSize(float _width, float _height){
	BasicScreenObject::setSize(_width, _height);
	if(isUpdateReal){
        updateRealImageSize();
	}
}


void Image::updateRealImageSize(){
    if(img) img->resize(width, height);	// heavy lifting here... causes lags
	//ofLog(OF_LOG_NOTICE, tmpFilepath + " resizing to (" + ofToString(tmpResizeCounter) + "): " + ofToString(width) + ", " + ofToString(height));
	tmpResizeCounter++;
}


void Image::crop(int x, int y, int w, int h) {
	BasicScreenObject::setSize(w,h);
	if (img==NULL) return;
	img->crop(x, y, w, h);
}


void Image::clone(Image* _srcImage) {
	img->clone(*_srcImage->getImagePointer());
}


void Image::setMaxSize(float _maxwidth, float _maxheight){
	hasMaxSize	= true;
	maxWidth	= _maxwidth;
	maxHeight	= _maxheight;<commit_msg>Image::clone() now copies image dimensions too<commit_after>#include "Image.h"


Image::Image(){
	hasMaxSize			= false;
	changed				= false;
    isUpdateReal		= false;
    img					= new ofImage();
    loaded				= false;
	loadingAsync		= false;
	loadingPlaceholder	= NULL;
	mode				= OF_RECTMODE_CORNER;

	tmpResizeCounter	= 0;
	tmpFilepath			= "";
}


Image::~Image(){
	img->clear();
}


void Image::update(){
	if (img) {
		if (loadingAsync) {
			if (img->getWidth() > 0) {
				loaded		= true;
				loadingAsync= false;
				changed		= true;
				BasicScreenObject::setSize(img->getWidth(), img->getHeight());
				if (loadingPlaceholder != NULL) {
					loadingPlaceholder->isVisible(false);
				}
				ofNotifyEvent(imageLoadedEvent, myEventArgs, this);
			}
		}
		if(changed){
			updateSize();
		}
	}
}


void Image::_draw(){
	if (img == NULL || loadingAsync) return;
	
	
	if (img->getWidth() > 0) {
		ofPushStyle();
		
		ofSetRectMode(mode);
        img->draw(0, 0, width, height);
		ofPopStyle();
	}
	/*
	 if (tmpResizeCounter>1) {
	 ofLog(OF_LOG_NOTICE, "resized more than once (" + ofToString(tmpResizeCounter) + "): " + tmpFilepath);
	 }
	 */
	tmpResizeCounter = 0;
}


void Image::load(string _filename){
	img->clear();
	img->loadImage(_filename);
	setSize(img->getWidth(), img->getHeight());
	changed = true;
	loaded  = true;
	ofNotifyEvent(imageLoadedEvent, myEventArgs, this);
	tmpFilepath = _filename;
}


void Image::loadAsyncFromDisk(string _filename, ofxThreadedImageLoader* loader) {
	loadingAsync = true;
	loaded		 = false;
	if (loadingPlaceholder != NULL) {
		loadingPlaceholder->isVisible(true);
	}
	img->clear();
	loader->loadFromDisk(img, _filename);
	tmpFilepath = _filename;
}


void Image::loadAsyncFromURL(string _url, ofxThreadedImageLoader* loader) {
	loadingAsync = true;
	loaded		 = false;
	if (loadingPlaceholder != NULL) {
		loadingPlaceholder->isVisible(true);
	}
	img->clear();
	loader->loadFromURL(img, _url);
}


void Image::setLoadingPlaceholder(BasicScreenObject* _loadingPlaceholder) {
	if (loadingPlaceholder != NULL) {
		removeChild(loadingPlaceholder);
	}
	loadingPlaceholder = _loadingPlaceholder;
	addChild(loadingPlaceholder);
	loadingPlaceholder->setPosition((width - loadingPlaceholder->getWidth())/2.0, (height - loadingPlaceholder->getHeight())/2.0);
	loadingPlaceholder->isVisible(false);
}


ofImage* Image::getImagePointer(){
	return img;
}


void Image::setSize(float _width, float _height){
	BasicScreenObject::setSize(_width, _height);
	if(isUpdateReal){
        updateRealImageSize();
	}
}


void Image::updateRealImageSize(){
    if(img) img->resize(width, height);	// heavy lifting here... causes lags
	//ofLog(OF_LOG_NOTICE, tmpFilepath + " resizing to (" + ofToString(tmpResizeCounter) + "): " + ofToString(width) + ", " + ofToString(height));
	tmpResizeCounter++;
}


void Image::crop(int x, int y, int w, int h) {
	BasicScreenObject::setSize(w,h);
	if (img==NULL) return;
	img->crop(x, y, w, h);
}


void Image::clone(Image* _srcImage) {
	setSize(_srcImage->getWidth(), _srcImage->getHeight());
	img->clone(*_srcImage->getImagePointer());
}


void Image::setMaxSize(float _maxwidth, float _maxheight){
	hasMaxSize	= true;
	maxWidth	= _maxwidth;
	maxHeight	= _maxheight;
{'fraction_non_alphanumeric': 0.15188679245283018, 'fraction_numerical': 0.003459119496855346, 'mean_word_length': 4.62422634836428, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 61, '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': '5259437', 'n_tokens_mistral': 2351, 'n_tokens_neox': 2195, 'n_words': 420}