GED 2006 (C++)
File detail
Source code
/*
* File: meshscreen.cc - Plugin Mesh screen
* Project: GED - bitmap editor (ICP)
* Author: Lukas Hefka, xhefka00
* Team: xdudka00, xfilak01, xhefka00, xhradi08
* Created: 2006-04-04
*/
#include <iostream>
#include <string>
#include <vector>
#include "gedplugin.h"
using std::string;
using std::vector;
/**
* 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;
const int nPixels= fb.select().size.nPixels();
// Average pixel
unsigned sumRed= 0;
unsigned sumGreen= 0;
unsigned sumBlue= 0;
for (int y= yMin; y< yMax; y++)
for (int x= xMin; x< xMax; x++)
{
Pixel &now= fb[y][x];
sumRed+= now.red;
sumGreen+= now.green;
sumBlue+= now.blue;
}
Pixel avgPixel = {
sumRed/nPixels,
sumGreen/nPixels,
sumBlue/nPixels,
UCHAR_MAX // Alpha
};
// Apply mesh screen
for (int y= yMin; y< yMax; y++) {
bool bFillRows = y & 1;
for (int x= xMin; x< xMax; x++, bFillRows ^=1)
if (bFillRows)
// Fill pixel
fb [y][x]= avgPixel;
}
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 = "Mesh screen"; // Plugin name
desc.pCore = core; // Plugin core function (!!)
myPlugin.set (desc);
// Execute plugin (if needed)
return myPlugin.exec();
}