Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorBruno Coudoin <bcoudoin@src.gnome.org>2007-08-29 21:41:58 (GMT)
committer Bruno Coudoin <bcoudoin@src.gnome.org>2007-08-29 21:41:58 (GMT)
commit80f4afe96041638b474e87a2abc5777f3358aa9e (patch)
tree43b1fa9c96cc2cc4e185f9f2c185227100f9c529 /tools
parent522b446f11e7feff791ac54c57d9d2b5699bb168 (diff)
Switched to GPL V3
svn path=/trunk/; revision=2909
Diffstat (limited to 'tools')
-rw-r--r--tools/gcompris_shapegame.py53
-rw-r--r--tools/shapegame/dt/dt.cpp5
-rw-r--r--tools/shapegame/dt/dt.h5
-rw-r--r--tools/shapegame/dt/image.h27
-rw-r--r--tools/shapegame/dt/imconv.h17
-rw-r--r--tools/shapegame/dt/imutil.h11
-rw-r--r--tools/shapegame/dt/misc.h5
-rw-r--r--tools/shapegame/dt/pnmfile.h29
-rw-r--r--tools/shapegame/nice_target_spot.cpp23
9 files changed, 83 insertions, 92 deletions
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 <http://www.gnu.org/licenses/>.
#
#######################################################################
#
# 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["<name>"] = 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["<tooltip>"] = "%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("""<?xml version="1.0" encoding="UTF-8"?>
@@ -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("</ShapeGame>\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 <http://www.gnu.org/licenses/>.
*/
#include <cstdio>
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 <http://www.gnu.org/licenses/>.
*/
/* 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 <http://www.gnu.org/licenses/>.
*/
/* a simple image class */
@@ -37,26 +36,26 @@ class image {
/* copy an image */
image<T> *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<T>::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 <class T>
image<T>::~image() {
- delete [] data;
+ delete [] data;
delete [] access;
}
@@ -98,4 +97,4 @@ image<T> *image<T>::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 <http://www.gnu.org/licenses/>.
*/
/* image conversion */
@@ -58,7 +57,7 @@ static image<rgb> *imageGRAYtoRGB(image<uchar> *input) {
imRef(output, x, y).b = imRef(input, x, y);
}
}
- return output;
+ return output;
}
static image<float> *imageUCHARtoFLOAT(image<uchar> *input) {
@@ -71,7 +70,7 @@ static image<float> *imageUCHARtoFLOAT(image<uchar> *input) {
imRef(output, x, y) = imRef(input, x, y);
}
}
- return output;
+ return output;
}
static image<float> *imageINTtoFLOAT(image<int> *input) {
@@ -84,10 +83,10 @@ static image<float> *imageINTtoFLOAT(image<int> *input) {
imRef(output, x, y) = imRef(input, x, y);
}
}
- return output;
+ return output;
}
-static image<uchar> *imageFLOATtoUCHAR(image<float> *input,
+static image<uchar> *imageFLOATtoUCHAR(image<float> *input,
float min, float max) {
int width = input->width();
int height = input->height();
@@ -122,7 +121,7 @@ static image<long> *imageUCHARtoLONG(image<uchar> *input) {
imRef(output, x, y) = imRef(input, x, y);
}
}
- return output;
+ return output;
}
static image<uchar> *imageLONGtoUCHAR(image<long> *input, long min, long max) {
@@ -149,7 +148,7 @@ static image<uchar> *imageLONGtoUCHAR(image<long> *input) {
return imageLONGtoUCHAR(input, min, max);
}
-static image<uchar> *imageSHORTtoUCHAR(image<short> *input,
+static image<uchar> *imageSHORTtoUCHAR(image<short> *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 <http://www.gnu.org/licenses/>.
*/
/* some image utilities */
@@ -29,7 +28,7 @@ template <class T>
void min_max(image<T> *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<T> *im, T *ret_min, T *ret_max) {
*ret_min = min;
*ret_max = max;
-}
+}
/* threshold image */
template <class T>
@@ -52,7 +51,7 @@ image<uchar> *threshold(image<T> *src, int t) {
int width = src->width();
int height = src->height();
image<uchar> *dst = new image<uchar>(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 <http://www.gnu.org/licenses/>.
*/
/* 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 <http://www.gnu.org/licenses/>.
*/
/* 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<uchar> *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<uchar> *im = new image<uchar>(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<uchar> *im, const char *name) {
static image<uchar> *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<uchar> *im, const char *name) {
static image<rgb> *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<rgb> *im, const char *name) {
template <class T>
void load_image(image<T> **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 <http://www.gnu.org/licenses/>.
*/
/**************************************************************************
** 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<rgb>* circleimage = new image<rgb>( input->width(),
+ image<rgb>* circleimage = new image<rgb>( 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;
-
+
}