Česky
Kamil Dudka

GED 2006 (C++)

File detail

Name:Downloadpostlevels.cc [Download]
Location: ged2006 > src
Size:1.7 KB
Last modification:2007-08-29 02:16

Source code

/*
 * File: postlevels.cc - Plugin Post levels
 * Project: GED - bitmap editor (ICP)
 * Author: Lukas Hefka, xhefka00
 * Team: xdudka00, xfilak01, xhefka00, xhradi08
 * Created: 2006-04-04
 */
 
#include <string>
#include <vector>
 
#include "gedplugin.h"
 
using std::string;
using std::vector;
 
/**
 * Return minumum from a and b.
 */
unsigned min (unsigned a, unsigned b) {
	return (a<b) ? a:b;
}
 
/**
 * Return maximum from a and b.
 */
unsigned max (unsigned a, unsigned b) {
	return (a>b) ? a:b;
}
 
/**
 * Process one pixel.
 * \param pixel Pixel to process.
 */
void processPixel (Pixel &pixel)
{
	const int levels= 3;
	const int iStep= UCHAR_MAX / levels;
 
	unsigned char &red= pixel.red;
	unsigned char &green= pixel.green;
	unsigned char &blue= pixel.blue;
 
	red-= red % iStep;
	green-= green % iStep;
	blue-= blue % iStep;
}
 
/**
 * Plugin core function
 * \param fb Reference to frambe buffer to work with.
 * \return Return error-code, 0 if success.
 */
int core (FrameBuffer &fb, vector<string>) {
	// Selected area range
	const int xMin= fb.select().at.x;
	const int yMin= fb.select().at.y;
	const int xMax= xMin + fb.select().size.width;
	const int yMax= yMin + fb.select().size.height;
 
	for (int y= yMin; y< yMax; y++)
		for (int x= xMin; x< xMax; x++)
			processPixel (fb [y][x]);
 
	return 0;	// success
}
 
// plugin main() - read the manual if available
int main (int argc, char *argv[]) {
	using namespace GedPlugin;
 
	// Create plugin object
	Plugin myPlugin (argc, argv);
 
	// Set object properties
	PluginDescription desc;
	desc.type = TYPE_FILTER;	// Plugin category: filter
	desc.name = "Post levels";	// Plugin name
	desc.pCore = core;		// Plugin core function (!!)
	myPlugin.set (desc);
 
	// Execute plugin (if needed)
	return myPlugin.exec();	
}