From 80f4afe96041638b474e87a2abc5777f3358aa9e Mon Sep 17 00:00:00 2001 From: Bruno Coudoin Date: Wed, 29 Aug 2007 21:41:58 +0000 Subject: Switched to GPL V3 svn path=/trunk/; revision=2909 --- (limited to 'tools') diff --git a/tools/gcompris_shapegame.py b/tools/gcompris_shapegame.py index 6c304aa..d6c4b03 100644 --- a/tools/gcompris_shapegame.py +++ b/tools/gcompris_shapegame.py @@ -4,7 +4,7 @@ # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or +# the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, @@ -13,15 +13,14 @@ # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# along with this program; if not, see . # ####################################################################### # # a Python-Fu Gimp script for GCompris Shapegame activities -# +# # Require: gimp-python -# +# # To install, copy this script in ~/.gimp-2.2/plug-ins/ and set it executable # cp gcompris_shapegame.py ~/.gimp-2.2/plug-ins/ # chmod +x ~/.gimp-2.2/plug-ins/gcompris_shapegame.py @@ -47,7 +46,7 @@ # a. Choice output directory and title (default based on image name) # b. Set the border size between regions (depend on the original map) # c. Choice if borders between region should be show -# +# # We can change color of a region by opening region file in gimp, # and fill it by a new color. # @@ -78,24 +77,24 @@ def gcompris_puzzle(img, sdrawable, x, y, dossier, title, puzzle_type): ptype = 0 -> normal, 1 -> rectanglular (grid) """ width, height = img.width, img.height - layer = gimp.Layer(img, "puzzle", width, height, RGB_IMAGE, + layer = gimp.Layer(img, "puzzle", width, height, RGB_IMAGE, 100, NORMAL_MODE) layer.fill(WHITE_FILL) img.add_layer(layer) if ptype: vspace = math.ceil(width / float(x)) hspace = math.ceil(height / float(y)) - pdb.plug_in_grid(img, layer, 1, hspace, 0, (0, 0, 0), 255, - 1, vspace, 0, (0, 0, 0), 255, + pdb.plug_in_grid(img, layer, 1, hspace, 0, (0, 0, 0), 255, + 1, vspace, 0, (0, 0, 0), 255, 0, 0, 0, (0, 0, 0), 255) else: pdb.plug_in_jigsaw(img, layer, x, y, 1, 0, 0) return layer if not gcompris_init(img): - return + return - # Init + # Init bg_layer = img.active_layer pdb.gimp_selection_none(img) width, height = img.width, img.height @@ -113,10 +112,10 @@ def gcompris_puzzle(img, sdrawable, x, y, dossier, title, puzzle_type): pdb.gimp_floating_sel_to_layer(pdb.gimp_edit_paste(bg_layer, 1)) img.active_layer.name = chr(ord('A')+ idx) + str(idy+1) layerlist.append(img.active_layer) - + pdb.gimp_selection_none(img) img.remove_layer(puzzle) - + d_title = dict(x=405, y=495, justification ="GTK_JUSTIFY_CENTER", color_skin="gcompris/text button") d_title[""] = title @@ -153,7 +152,7 @@ def gcompris_geography(img, sdrawable, dossier, title, bordersize, keepLimit): save_bg = gimp.get_background() save_fg = gimp.get_foreground() - + layer_map = img.layers[0] if not layer_map.has_alpha: layer_map.add_alpha() @@ -179,7 +178,7 @@ def gcompris_geography(img, sdrawable, dossier, title, bordersize, keepLimit): pdb.gimp_edit_fill(layer, BACKGROUND_FILL) layer.name = chan.name layerlist.append(layer) - + pdb.gimp_context_set_default_colors() # Fill country white pdb.gimp_selection_load(all_channel) @@ -188,12 +187,12 @@ def gcompris_geography(img, sdrawable, dossier, title, bordersize, keepLimit): pdb.gimp_selection_grow(img, bordersize) earth = pdb.gimp_selection_save(img) earth.name = "earth" - + # Fill limit black pdb.gimp_selection_combine(all_channel, CHANNEL_OP_SUBTRACT) pdb.gimp_edit_fill(layer_map, FOREGROUND_FILL) # Fill Black - - # Clear other + + # Clear other pdb.gimp_selection_load(earth) pdb.gimp_selection_invert(img) pdb.gimp_edit_clear(layer_map) @@ -206,7 +205,7 @@ def gcompris_geography(img, sdrawable, dossier, title, bordersize, keepLimit): gimp.set_background(94, 146, 229) pdb.gimp_edit_blend(layer_map, 0, 0, 0, 50, 0, 0, False, False, 0, 0, True, 0, 0, img.width, img.height) - + # Water 2 pdb.gimp_selection_load(earth) pdb.gimp_selection_grow(img, 20) @@ -215,7 +214,7 @@ def gcompris_geography(img, sdrawable, dossier, title, bordersize, keepLimit): gimp.set_background(137, 173, 225) pdb.gimp_edit_blend(layer_map, 0, 0, 0, 25, 0, 0, False, False, 0, 0, True, 0, 0, img.width, img.height) - + # Remove tmp channel img.remove_channel(earth) img.remove_channel(all_channel) @@ -223,7 +222,7 @@ def gcompris_geography(img, sdrawable, dossier, title, bordersize, keepLimit): gimp.set_background(save_bg) gimp.set_foreground(save_fg) pdb.gimp_selection_none(img) - + shape = dict() shape["sound"] = os.path.join("sounds", "$LOCALE", "geography", dossier, "%n.png") shape[""] = "%n" @@ -264,7 +263,7 @@ def gcompris_layer_to_board(layerlist, activity, subdir, title, background, shap def realbasename(f): """Return the basename without extension""" return os.path.splitext(os.path.basename(f))[0] - + def dict_to_str(name, dico): """ Convert a dictionnary to string of a xml element dictionnary'keys are convert to a property of the xml element with associate value @@ -283,7 +282,7 @@ def gcompris_layer_to_board(layerlist, activity, subdir, title, background, shap else: tmp += "/>\n" return tmp - + # Init img = layerlist[0].image width, height = img.width, img.height @@ -296,7 +295,7 @@ def gcompris_layer_to_board(layerlist, activity, subdir, title, background, shap if os.path.exists(out_dir): os.remove(out_dir) os.mkdir(out_dir) - + out_xml = os.path.join(out_dir, "board.xml") xml = file(out_xml, "w") xml.write(""" @@ -304,14 +303,14 @@ def gcompris_layer_to_board(layerlist, activity, subdir, title, background, shap if title: xml.write(dict_to_str("title", title)) - + if isinstance(background, dict): xml.write(dict_to_str("Shape", background)) elif isinstance(background, gimp.Layer): layerlist.append(background) deltax, deltay = (800-width)/2, (520-height)/2 - + for tile_layer in layerlist: tile_filename = tile_layer.name+".png" tile_filename_long = os.path.join(out_dir, tile_filename) @@ -334,6 +333,6 @@ def gcompris_layer_to_board(layerlist, activity, subdir, title, background, shap xml.write(dict_to_str("shape", shape_dict)) xml.write("\n") xml.close() - + main() diff --git a/tools/shapegame/dt/dt.cpp b/tools/shapegame/dt/dt.cpp index 214b14d..58e8d10 100644 --- a/tools/shapegame/dt/dt.cpp +++ b/tools/shapegame/dt/dt.cpp @@ -4,7 +4,7 @@ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or + * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, @@ -13,8 +13,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * along with this program; if not, see . */ #include diff --git a/tools/shapegame/dt/dt.h b/tools/shapegame/dt/dt.h index efe557e..9fee8dd 100644 --- a/tools/shapegame/dt/dt.h +++ b/tools/shapegame/dt/dt.h @@ -4,7 +4,7 @@ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or + * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, @@ -13,8 +13,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * along with this program; if not, see . */ /* distance transform */ diff --git a/tools/shapegame/dt/image.h b/tools/shapegame/dt/image.h index 4f385dc..1a84096 100644 --- a/tools/shapegame/dt/image.h +++ b/tools/shapegame/dt/image.h @@ -4,7 +4,7 @@ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or + * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, @@ -13,8 +13,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * along with this program; if not, see . */ /* a simple image class */ @@ -37,26 +36,26 @@ class image { /* copy an image */ image *copy() const; - + /* get the width of an image. */ int width() const { return w; } - + /* get the height of an image. */ int height() const { return h; } - + /* image data. */ T *data; - + /* row pointers. */ T **access; - + private: int w, h; }; /* use imRef to access image data. */ #define imRef(im, x, y) (im->access[y][x]) - + /* use imPtr to get pointer to image data. */ #define imPtr(im, x, y) &(im->access[y][x]) @@ -66,18 +65,18 @@ image::image(const int width, const int height, const bool init) { h = height; data = new T[w * h]; // allocate space for image data access = new T*[h]; // allocate space for row pointers - + // initialize row pointers for (int i = 0; i < h; i++) - access[i] = data + (i * w); - + access[i] = data + (i * w); + if (init) memset(data, 0, w * h * sizeof(T)); } template image::~image() { - delete [] data; + delete [] data; delete [] access; } @@ -98,4 +97,4 @@ image *image::copy() const { } #endif - + diff --git a/tools/shapegame/dt/imconv.h b/tools/shapegame/dt/imconv.h index 2ecbd0b..be8ea5b 100644 --- a/tools/shapegame/dt/imconv.h +++ b/tools/shapegame/dt/imconv.h @@ -4,7 +4,7 @@ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or + * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, @@ -13,8 +13,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * along with this program; if not, see . */ /* image conversion */ @@ -58,7 +57,7 @@ static image *imageGRAYtoRGB(image *input) { imRef(output, x, y).b = imRef(input, x, y); } } - return output; + return output; } static image *imageUCHARtoFLOAT(image *input) { @@ -71,7 +70,7 @@ static image *imageUCHARtoFLOAT(image *input) { imRef(output, x, y) = imRef(input, x, y); } } - return output; + return output; } static image *imageINTtoFLOAT(image *input) { @@ -84,10 +83,10 @@ static image *imageINTtoFLOAT(image *input) { imRef(output, x, y) = imRef(input, x, y); } } - return output; + return output; } -static image *imageFLOATtoUCHAR(image *input, +static image *imageFLOATtoUCHAR(image *input, float min, float max) { int width = input->width(); int height = input->height(); @@ -122,7 +121,7 @@ static image *imageUCHARtoLONG(image *input) { imRef(output, x, y) = imRef(input, x, y); } } - return output; + return output; } static image *imageLONGtoUCHAR(image *input, long min, long max) { @@ -149,7 +148,7 @@ static image *imageLONGtoUCHAR(image *input) { return imageLONGtoUCHAR(input, min, max); } -static image *imageSHORTtoUCHAR(image *input, +static image *imageSHORTtoUCHAR(image *input, short min, short max) { int width = input->width(); int height = input->height(); diff --git a/tools/shapegame/dt/imutil.h b/tools/shapegame/dt/imutil.h index 6fcfca9..9d35228 100644 --- a/tools/shapegame/dt/imutil.h +++ b/tools/shapegame/dt/imutil.h @@ -4,7 +4,7 @@ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or + * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, @@ -13,8 +13,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * along with this program; if not, see . */ /* some image utilities */ @@ -29,7 +28,7 @@ template void min_max(image *im, T *ret_min, T *ret_max) { int width = im->width(); int height = im->height(); - + T min = imRef(im, 0, 0); T max = imRef(im, 0, 0); for (int y = 0; y < height; y++) { @@ -44,7 +43,7 @@ void min_max(image *im, T *ret_min, T *ret_max) { *ret_min = min; *ret_max = max; -} +} /* threshold image */ template @@ -52,7 +51,7 @@ image *threshold(image *src, int t) { int width = src->width(); int height = src->height(); image *dst = new image(width, height); - + for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { imRef(dst, x, y) = (imRef(src, x, y) >= t); diff --git a/tools/shapegame/dt/misc.h b/tools/shapegame/dt/misc.h index b7b2f50..6d9fe99 100644 --- a/tools/shapegame/dt/misc.h +++ b/tools/shapegame/dt/misc.h @@ -4,7 +4,7 @@ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or + * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, @@ -13,8 +13,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * along with this program; if not, see . */ /* random stuff */ diff --git a/tools/shapegame/dt/pnmfile.h b/tools/shapegame/dt/pnmfile.h index eacf1a1..09a8401 100644 --- a/tools/shapegame/dt/pnmfile.h +++ b/tools/shapegame/dt/pnmfile.h @@ -4,7 +4,7 @@ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or + * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, @@ -13,8 +13,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * along with this program; if not, see . */ /* basic image I/O */ @@ -34,7 +33,7 @@ class pnm_error { }; static void read_packed(unsigned char *data, int size, std::ifstream &f) { unsigned char c = 0; - + int bitshift = -1; for (int pos = 0; pos < size; pos++) { if (bitshift == -1) { @@ -48,7 +47,7 @@ static void read_packed(unsigned char *data, int size, std::ifstream &f) { static void write_packed(unsigned char *data, int size, std::ofstream &f) { unsigned char c = 0; - + int bitshift = 7; for (int pos = 0; pos < size; pos++) { c = c | (data[pos] << bitshift); @@ -61,18 +60,18 @@ static void write_packed(unsigned char *data, int size, std::ofstream &f) { } } -/* read PNM field, skipping comments */ +/* read PNM field, skipping comments */ static void pnm_read(std::ifstream &file, char *buf) { char doc[BUF_SIZE]; char c; - + file >> c; while (c == '#') { file.getline(doc, BUF_SIZE); file >> c; } file.putback(c); - + file.width(BUF_SIZE); file >> buf; file.ignore(); @@ -80,23 +79,23 @@ static void pnm_read(std::ifstream &file, char *buf) { static image *loadPBM(const char *name) { char buf[BUF_SIZE]; - + /* read header */ std::ifstream file(name, std::ios::in | std::ios::binary); pnm_read(file, buf); if (strncmp(buf, "P4", 2)) throw pnm_error(); - + pnm_read(file, buf); int width = atoi(buf); pnm_read(file, buf); int height = atoi(buf); - + /* read data */ image *im = new image(width, height); for (int i = 0; i < height; i++) read_packed(imPtr(im, 0, i), width, file); - + return im; } @@ -112,7 +111,7 @@ static void savePBM(image *im, const char *name) { static image *loadPGM(const char *name) { char buf[BUF_SIZE]; - + /* read header */ std::ifstream file(name, std::ios::in | std::ios::binary); pnm_read(file, buf); @@ -146,7 +145,7 @@ static void savePGM(image *im, const char *name) { static image *loadPPM(const char *name) { char buf[BUF_SIZE], doc[BUF_SIZE]; - + /* read header */ std::ifstream file(name, std::ios::in | std::ios::binary); pnm_read(file, buf); @@ -181,7 +180,7 @@ static void savePPM(image *im, const char *name) { template void load_image(image **im, const char *name) { char buf[BUF_SIZE]; - + /* read header */ std::ifstream file(name, std::ios::in | std::ios::binary); pnm_read(file, buf); diff --git a/tools/shapegame/nice_target_spot.cpp b/tools/shapegame/nice_target_spot.cpp index aa3c31d..1294a84 100644 --- a/tools/shapegame/nice_target_spot.cpp +++ b/tools/shapegame/nice_target_spot.cpp @@ -4,7 +4,7 @@ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or + * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, @@ -13,15 +13,14 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * along with this program; if not, see . */ /************************************************************************** ** Title: create nice target spot ** ** create nice target spots for puzzle pieces in gcpomris shapegame -** based on distance transform from Pedro F. Felzenszwalb and +** based on distance transform from Pedro F. Felzenszwalb and ** Daniel P. Huttenlocher. ** **************************************************************************/ @@ -69,23 +68,23 @@ int main(int argc, char **argv) { } } } - + // draw circle at max position into new image (not touching the border) - image* circleimage = new image( input->width(), + image* circleimage = new image( input->width(), input->height(), false); rgb white; white.r = 255; white.g = 255; white.b = 255; - + circleimage->init(white); float circleRadius = 3.5; float borderThickness = 1; - + float innerCircleSqrRadius = square(circleRadius); float outerCircleSqrRadius = square(circleRadius+borderThickness); - + rgb dotColor; dotColor.r = 255; dotColor.g = 0; @@ -95,12 +94,12 @@ int main(int argc, char **argv) { borderColor.r = 0; borderColor.g = 0; borderColor.b = 0; - + for (int y = 0; y < out->height(); y++) { for (int x = 0; x < out->width(); x++) { float currentSqrRadius = square(x - xmax) + square(y - ymax); - + if( currentSqrRadius <= outerCircleSqrRadius && imRef(out, x, y) > 1) { @@ -122,5 +121,5 @@ int main(int argc, char **argv) { delete input; delete out; delete circleimage; - + } -- cgit v0.9.1