view horori/eraline/src/eraline.cpp @ 0:aaaa401818a1 draft

first commit.
author pyon <pyon@macmini>
date Mon, 24 May 2021 21:32:58 +0900
parents
children
line wrap: on
line source

/* eraline.cpp
 *  Last Change: 2021-02-10 水 12:00:54.
 *                            by T.Mutoh
 *
 *  > eraline y h in.tif out.tif
 *  > eraline -v x h in.tif out.tif
 */
#include "wx/wxprec.h"

#include <wx/wx.h>
#include <wx/app.h>
#include <wx/cmdline.h>

wxString inimg;	
wxString outimg;	

static const wxCmdLineEntryDesc cmdLineDesc[] = {
	{wxCMD_LINE_SWITCH, "h", "help", "show this help message", wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP},
	{wxCMD_LINE_SWITCH, "d", "dummy", "a dummy switch", wxCMD_LINE_VAL_NONE, 0},
	{wxCMD_LINE_SWITCH, "v", "vertical", "a secret switch", wxCMD_LINE_VAL_NONE, wxCMD_LINE_HIDDEN},
	// ... your other command line options here...

	wxCMD_LINE_DESC_END
};

void erase(int y, int h) {
    wxImage img(inimg, wxBITMAP_TYPE_TIFF);

	int r, g, b;
	int th = 38;
	int p = 0;
	/*
	for (int x = 0; x < img.GetWidth(); x++) {
		r = (int)img.GetRed(x, y);
		g = (int)img.GetGreen(x, y);
		b = (int)img.GetBlue(x, y);
		//wxString buf = wxString::Format("%d %d %d -> ", r, g, b);
		//wxPrintf(buf);

		r += (int)img.GetRed(x, y - 1);
		g += (int)img.GetGreen(x, y - 1);
		b += (int)img.GetBlue(x, y - 1);

		r += (int)img.GetRed(x, y + 1);
		g += (int)img.GetGreen(x, y + 1);
		b += (int)img.GetBlue(x, y + 1);

		r /= 3;
		g /= 3;
		b /= 3;
		img.SetRGB(x, y, (unsigned char)r, (unsigned char)g, (unsigned char)b);

		//buf = wxString::Format("%d %d %d\n", r, g, b);
		//wxPrintf(buf);
	}
	*/
	/*
	switch (h) {
		case 1:
			break;

		case 2:
			break;

		case 3:
			break;

		case 4:
			for (int x = 0; x < img.GetWidth(); x++) {
				r = (int)img.GetRed(x, y - 1);
				g = (int)img.GetGreen(x, y - 1);
				b = (int)img.GetBlue(x, y - 1);
				if (r > th && g > th && b > th - 1) p++;

				for (int d = 0; d < 4; d++) {
					r = (int)img.GetRed(x, y + d);
					g = (int)img.GetGreen(x, y + d);
					b = (int)img.GetBlue(x, y + d);
					if (r < th && g < th && b < th - 1) p++;
				}

				r = (int)img.GetRed(x, y + 4);
				g = (int)img.GetGreen(x, y + 4);
				b = (int)img.GetBlue(x, y + 4);
				if (r > th && g > th && b > th - 4) p++;

				if (p == 6) {
					for (int d = 0; d < 4; d++)
						img.SetRGB(x, y + d, 0, 0, 0);
				}
			}
			break;

		default:
			break;
	}
	*/
	for (int x = 0; x < img.GetWidth(); x++) {
		bool bt, bb;
		r = (int)img.GetRed(x, y - 1);
		g = (int)img.GetGreen(x, y - 1);
		b = (int)img.GetBlue(x, y - 1);
		if (r > th && g > th && b > th - 1) bt = true;

		r = (int)img.GetRed(x, y + h);
		g = (int)img.GetGreen(x, y + h);
		b = (int)img.GetBlue(x, y + h);
		if (r > th && g > th && b > th - 1) bb = true;

		if (bt && bb) {
			for (int d = 0; d < h; d++)
				img.SetRGB(x, y + d, 0, 0, 0);
		}
	}

	img.SetOption(wxIMAGE_OPTION_TIFF_COMPRESSION, 5);
	img.SetOption(wxIMAGE_OPTION_TIFF_BITSPERSAMPLE, 1);
    img.SaveFile(outimg);
}

int main(int argc, char **argv) {
	wxApp::CheckBuildOptions(WX_BUILD_OPTIONS_SIGNATURE, "program");

	wxInitializer initializer;
	if (!initializer) {
		fprintf(stderr, "Failed to initialize the wxWidgets library, aborting.");
		return -1;
	}

	wxCmdLineParser parser(cmdLineDesc, argc, argv);

    wxImage::AddHandler(new wxTIFFHandler);

	/*
	switch (parser.Parse()) {
		case -1:
			// help was given, terminating
			wxPuts("help");
			break;

		case 0:
			// everything is ok; proceed
			if (parser.Found("d")) {
				wxPrintf("Dummy switch was given...\n");
			}
			if (parser.Found("v")) {
				wxPrintf("Vertical switch was given... %s\n", argv[0]);
				int t = wxAtoi(argv[2]);
				int d = wxAtoi(argv[3]);
				inimg = argv[4];	
				outimg = argv[5];	
				//v1(t);
			}
			break;

		default:
			wxPrintf("??? switch was given... \n");
			break;
	}
	*/

	int y = wxAtoi(argv[1]);
	int h = wxAtoi(argv[2]);
	inimg = argv[3];	
	outimg = argv[4];	

	erase(y, h);

	return 0;
}