|
35 | 35 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
36 | 36 | # SOFTWARE.
|
37 | 37 |
|
| 38 | +import polyglot |
38 | 39 | import sys
|
39 | 40 | import os
|
40 | 41 |
|
|
44 | 45 |
|
45 | 46 | from image_magix import Image
|
46 | 47 |
|
47 |
| -MIME_R = "application/x-r" |
48 |
| - |
49 |
| -load_jpeg = eval(compile("""function(file.name) { |
| 48 | +load_jpeg = polyglot.eval(string="""function(file.name) { |
50 | 49 | jimg <- read.csv(gzfile(file.name))
|
51 | 50 | return (jimg)
|
52 |
| -}""", "", MIME_R)) |
| 51 | +}""", language="R") |
53 | 52 |
|
54 | 53 | print("stage 1")
|
55 | 54 |
|
56 | 55 | working_dir_parts.append("img.csv.gz")
|
57 | 56 | raw_data = load_jpeg(os.sep.join(working_dir_parts))
|
58 | 57 |
|
59 | 58 | # the dimensions are R attributes; define function to access them
|
60 |
| -getDim = eval(compile("function(v, pos) dim(v)[[pos]]", "", MIME_R)) |
61 |
| -getDataRowMajor = eval(compile("function(v) as.vector(t(v))", "", MIME_R)) |
| 59 | +getDim = polyglot.eval(string="function(v, pos) dim(v)[[pos]]", language="R") |
| 60 | +getDataRowMajor = polyglot.eval(string="function(v) as.vector(t(v))", language="R") |
62 | 61 |
|
63 | 62 | print("stage 2")
|
64 | 63 |
|
|
77 | 76 |
|
78 | 77 | print("stage 3")
|
79 | 78 |
|
80 |
| -draw = eval(compile("""function(processedImgObj) { |
| 79 | +draw = polyglot.eval(string="""function(processedImgObj) { |
81 | 80 | require(grDevices)
|
82 | 81 | require(grid)
|
83 | 82 | mx <- matrix(processedImgObj$`@data`/255, nrow=processedImgObj$`@height`, ncol=processedImgObj$`@width`)
|
84 | 83 | cat("rows:", nrow(mx), "\n")
|
85 | 84 | grid.newpage()
|
86 | 85 | grid.raster(mx, height=unit(nrow(mx),"points"))
|
87 | 86 | cat("DONE\n")
|
88 |
| -}""", "", MIME_R)) |
| 87 | +}""", language="R") |
89 | 88 |
|
90 | 89 | draw(result)
|
91 | 90 |
|
92 |
| -eval(compile("dev.off()", "", MIME_R)) |
93 |
| - |
| 91 | +polyglot.eval(string="dev.off()", language="R") |
0 commit comments