Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/torch/image.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthieu Tourne <matthieu.tourne@gmail.com>2015-07-13 00:34:47 +0300
committerMatthieu Tourne <matthieu.tourne@gmail.com>2015-07-13 00:34:47 +0300
commit14e9dad412b0dc86c4f09acb6134c59ab9511df3 (patch)
tree17c9f513e365a815ae5b9b38de42aa00b6d8f81a
parentf6e7b24068c4db2c641da5479bddb48d3932bc91 (diff)
Fixing broken PGMA loading - Adding test
-rw-r--r--generic/ppm.c4
-rw-r--r--test/ascii.pgm11
-rw-r--r--test/test_ppm.lua18
3 files changed, 31 insertions, 2 deletions
diff --git a/generic/ppm.c b/generic/ppm.c
index c3315d3..cb1544e 100644
--- a/generic/ppm.c
+++ b/generic/ppm.c
@@ -54,7 +54,7 @@ static int libppm_(Main_load)(lua_State *L)
int c,i;
C = 3;
r = (unsigned char *)malloc(W*H*C);
- for (i=0; i<W*H*3; i++) {
+ for (i=0; i<W*H*C; i++) {
fscanf ( fp, "%d", &c );
r[i] = 255*c / D;
}
@@ -62,7 +62,7 @@ static int libppm_(Main_load)(lua_State *L)
int c,i;
C = 1;
r = (unsigned char *)malloc(W*H*C);
- for (i=0; i<W*H*3; i++) {
+ for (i=0; i<W*H*C; i++) {
fscanf ( fp, "%d", &c );
r[i] = 255*c / D;
}
diff --git a/test/ascii.pgm b/test/ascii.pgm
new file mode 100644
index 0000000..0e76d7d
--- /dev/null
+++ b/test/ascii.pgm
@@ -0,0 +1,11 @@
+P2
+# feep.ascii.pgm
+24 7
+15
+0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
+0 3 3 3 3 0 0 7 7 7 7 0 0 11 11 11 11 0 0 15 15 15 15 0
+0 3 0 0 0 0 0 7 0 0 0 0 0 11 0 0 0 0 0 15 0 0 15 0
+0 3 3 3 0 0 0 7 7 7 0 0 0 11 11 11 0 0 0 15 15 15 15 0
+0 3 0 0 0 0 0 7 0 0 0 0 0 11 0 0 0 0 0 15 0 0 0 0
+0 3 0 0 0 0 0 7 7 7 7 0 0 11 11 11 11 0 0 15 0 0 0 0
+0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \ No newline at end of file
diff --git a/test/test_ppm.lua b/test/test_ppm.lua
index 2746b41..e955eed 100644
--- a/test/test_ppm.lua
+++ b/test/test_ppm.lua
@@ -18,6 +18,24 @@ function myTests.test_ppmload()
tester:assertTensorEq(pix, ref, 0, "PPM load: first pixel check failed")
end
+
+function myTests.test_pgmaload()
+ -- ascii.ppm is a PGMA file (ascii pgm)
+ -- example comes from ehere
+ -- http://people.sc.fsu.edu/~jburkardt/data/pgma/pgma.html
+ local img = image.load(paths.concat(sys.fpath(), "ascii.pgm"), 1, 'byte')
+ local max_gray = 15 -- 4th line of ascii.pgm
+ local ascii_val = 3 -- pixel (2,2) in the file
+ local pix_val = math.floor(255 * ascii_val / max_gray)
+
+ local pix = img[{ {}, {2}, {2} }]
+
+ -- Check that Pixel(1, 2,2) == 3
+ local ref = torch.zeros(1, 1, 1)
+ ref[1][1][1] = pix_val
+ tester:assertTensorEq(pix, ref, 0, "PGMA load: pixel check failed")
+end
+
function myTests.test_pgmload()
-- test.ppm is a 100x1 "French flag" like image, i.e the first pixel is blue
-- the 84 next pixels are white and the 15 last pixels are red.