Mercurial > mercurial > hgweb_kaigo.hg.cgi
comparison 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 |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:aaaa401818a1 |
|---|---|
| 1 /* eraline.cpp | |
| 2 * Last Change: 2021-02-10 水 12:00:54. | |
| 3 * by T.Mutoh | |
| 4 * | |
| 5 * > eraline y h in.tif out.tif | |
| 6 * > eraline -v x h in.tif out.tif | |
| 7 */ | |
| 8 #include "wx/wxprec.h" | |
| 9 | |
| 10 #include <wx/wx.h> | |
| 11 #include <wx/app.h> | |
| 12 #include <wx/cmdline.h> | |
| 13 | |
| 14 wxString inimg; | |
| 15 wxString outimg; | |
| 16 | |
| 17 static const wxCmdLineEntryDesc cmdLineDesc[] = { | |
| 18 {wxCMD_LINE_SWITCH, "h", "help", "show this help message", wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP}, | |
| 19 {wxCMD_LINE_SWITCH, "d", "dummy", "a dummy switch", wxCMD_LINE_VAL_NONE, 0}, | |
| 20 {wxCMD_LINE_SWITCH, "v", "vertical", "a secret switch", wxCMD_LINE_VAL_NONE, wxCMD_LINE_HIDDEN}, | |
| 21 // ... your other command line options here... | |
| 22 | |
| 23 wxCMD_LINE_DESC_END | |
| 24 }; | |
| 25 | |
| 26 void erase(int y, int h) { | |
| 27 wxImage img(inimg, wxBITMAP_TYPE_TIFF); | |
| 28 | |
| 29 int r, g, b; | |
| 30 int th = 38; | |
| 31 int p = 0; | |
| 32 /* | |
| 33 for (int x = 0; x < img.GetWidth(); x++) { | |
| 34 r = (int)img.GetRed(x, y); | |
| 35 g = (int)img.GetGreen(x, y); | |
| 36 b = (int)img.GetBlue(x, y); | |
| 37 //wxString buf = wxString::Format("%d %d %d -> ", r, g, b); | |
| 38 //wxPrintf(buf); | |
| 39 | |
| 40 r += (int)img.GetRed(x, y - 1); | |
| 41 g += (int)img.GetGreen(x, y - 1); | |
| 42 b += (int)img.GetBlue(x, y - 1); | |
| 43 | |
| 44 r += (int)img.GetRed(x, y + 1); | |
| 45 g += (int)img.GetGreen(x, y + 1); | |
| 46 b += (int)img.GetBlue(x, y + 1); | |
| 47 | |
| 48 r /= 3; | |
| 49 g /= 3; | |
| 50 b /= 3; | |
| 51 img.SetRGB(x, y, (unsigned char)r, (unsigned char)g, (unsigned char)b); | |
| 52 | |
| 53 //buf = wxString::Format("%d %d %d\n", r, g, b); | |
| 54 //wxPrintf(buf); | |
| 55 } | |
| 56 */ | |
| 57 /* | |
| 58 switch (h) { | |
| 59 case 1: | |
| 60 break; | |
| 61 | |
| 62 case 2: | |
| 63 break; | |
| 64 | |
| 65 case 3: | |
| 66 break; | |
| 67 | |
| 68 case 4: | |
| 69 for (int x = 0; x < img.GetWidth(); x++) { | |
| 70 r = (int)img.GetRed(x, y - 1); | |
| 71 g = (int)img.GetGreen(x, y - 1); | |
| 72 b = (int)img.GetBlue(x, y - 1); | |
| 73 if (r > th && g > th && b > th - 1) p++; | |
| 74 | |
| 75 for (int d = 0; d < 4; d++) { | |
| 76 r = (int)img.GetRed(x, y + d); | |
| 77 g = (int)img.GetGreen(x, y + d); | |
| 78 b = (int)img.GetBlue(x, y + d); | |
| 79 if (r < th && g < th && b < th - 1) p++; | |
| 80 } | |
| 81 | |
| 82 r = (int)img.GetRed(x, y + 4); | |
| 83 g = (int)img.GetGreen(x, y + 4); | |
| 84 b = (int)img.GetBlue(x, y + 4); | |
| 85 if (r > th && g > th && b > th - 4) p++; | |
| 86 | |
| 87 if (p == 6) { | |
| 88 for (int d = 0; d < 4; d++) | |
| 89 img.SetRGB(x, y + d, 0, 0, 0); | |
| 90 } | |
| 91 } | |
| 92 break; | |
| 93 | |
| 94 default: | |
| 95 break; | |
| 96 } | |
| 97 */ | |
| 98 for (int x = 0; x < img.GetWidth(); x++) { | |
| 99 bool bt, bb; | |
| 100 r = (int)img.GetRed(x, y - 1); | |
| 101 g = (int)img.GetGreen(x, y - 1); | |
| 102 b = (int)img.GetBlue(x, y - 1); | |
| 103 if (r > th && g > th && b > th - 1) bt = true; | |
| 104 | |
| 105 r = (int)img.GetRed(x, y + h); | |
| 106 g = (int)img.GetGreen(x, y + h); | |
| 107 b = (int)img.GetBlue(x, y + h); | |
| 108 if (r > th && g > th && b > th - 1) bb = true; | |
| 109 | |
| 110 if (bt && bb) { | |
| 111 for (int d = 0; d < h; d++) | |
| 112 img.SetRGB(x, y + d, 0, 0, 0); | |
| 113 } | |
| 114 } | |
| 115 | |
| 116 img.SetOption(wxIMAGE_OPTION_TIFF_COMPRESSION, 5); | |
| 117 img.SetOption(wxIMAGE_OPTION_TIFF_BITSPERSAMPLE, 1); | |
| 118 img.SaveFile(outimg); | |
| 119 } | |
| 120 | |
| 121 int main(int argc, char **argv) { | |
| 122 wxApp::CheckBuildOptions(WX_BUILD_OPTIONS_SIGNATURE, "program"); | |
| 123 | |
| 124 wxInitializer initializer; | |
| 125 if (!initializer) { | |
| 126 fprintf(stderr, "Failed to initialize the wxWidgets library, aborting."); | |
| 127 return -1; | |
| 128 } | |
| 129 | |
| 130 wxCmdLineParser parser(cmdLineDesc, argc, argv); | |
| 131 | |
| 132 wxImage::AddHandler(new wxTIFFHandler); | |
| 133 | |
| 134 /* | |
| 135 switch (parser.Parse()) { | |
| 136 case -1: | |
| 137 // help was given, terminating | |
| 138 wxPuts("help"); | |
| 139 break; | |
| 140 | |
| 141 case 0: | |
| 142 // everything is ok; proceed | |
| 143 if (parser.Found("d")) { | |
| 144 wxPrintf("Dummy switch was given...\n"); | |
| 145 } | |
| 146 if (parser.Found("v")) { | |
| 147 wxPrintf("Vertical switch was given... %s\n", argv[0]); | |
| 148 int t = wxAtoi(argv[2]); | |
| 149 int d = wxAtoi(argv[3]); | |
| 150 inimg = argv[4]; | |
| 151 outimg = argv[5]; | |
| 152 //v1(t); | |
| 153 } | |
| 154 break; | |
| 155 | |
| 156 default: | |
| 157 wxPrintf("??? switch was given... \n"); | |
| 158 break; | |
| 159 } | |
| 160 */ | |
| 161 | |
| 162 int y = wxAtoi(argv[1]); | |
| 163 int h = wxAtoi(argv[2]); | |
| 164 inimg = argv[3]; | |
| 165 outimg = argv[4]; | |
| 166 | |
| 167 erase(y, h); | |
| 168 | |
| 169 return 0; | |
| 170 } | |
| 171 | |
| 172 |
