Skip to content
14 changes: 14 additions & 0 deletions mathics/autoload/formats/Image/Export.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
(* Image Exporter *)

Begin["System`Convert`Image`"]

RegisterImageExport[type_] := RegisterExport[
type,
System`ImageExport,
Options -> {},
BinaryFormat -> True
];

RegisterImageExport[#]& /@ {"BMP", "GIF", "JPEG2000", "JPEG", "PCX", "PNG", "PPM", "PBM", "PGM", "TIFF"};

End[]
16 changes: 16 additions & 0 deletions mathics/autoload/formats/Image/Import.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
(* Image Importer *)

Begin["System`Convert`Image`"]

RegisterImageImport[type_] := RegisterImport[
type,
System`ImageImport,
{},
AvailableElements -> {"Image"},
DefaultElement -> "Image",
FunctionChannels -> {"FileNames"}
];

RegisterImageImport[#]& /@ {"BMP", "GIF", "JPEG2000", "JPEG", "PCX", "PNG", "PPM", "PBM", "PGM", "TIFF", "ICO", "TGA"};

End[]
12 changes: 12 additions & 0 deletions mathics/autoload/formats/JPEG/Export.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
(* Text Exporter *)

Begin["System`Convert`JPEG`"]

RegisterExport[
"JPEG",
System`ImageExport,
Options -> {},
BinaryFormat -> True
]

End[]
14 changes: 14 additions & 0 deletions mathics/autoload/formats/JPEG/Import.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
(* JPEG Importer *)

Begin["System`Convert`JPEG`"]

RegisterImport[
"JPEG",
System`ImageImport,
{},
AvailableElements -> {"Image"},
DefaultElement -> "Image",
FunctionChannels -> {"FileNames"}
]

End[]
19 changes: 17 additions & 2 deletions mathics/builtin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from mathics.builtin import (
algebra, arithmetic, assignment, attributes, calculus, combinatorial,
comparison, control, datentime, diffeqns, evaluation, exptrig, functional,
graphics, graphics3d, inout, integer, linalg, lists, logic, numbertheory,
graphics, graphics3d, image, inout, integer, linalg, lists, logic, numbertheory,
numeric, options, patterns, plot, physchemdata, randomnumbers, recurrence,
specialfunctions, scoping, strings, structure, system, tensors)

Expand All @@ -19,7 +19,7 @@
modules = [
algebra, arithmetic, assignment, attributes, calculus, combinatorial,
comparison, control, datentime, diffeqns, evaluation, exptrig, functional,
graphics, graphics3d, inout, integer, linalg, lists, logic, numbertheory,
graphics, graphics3d, image, inout, integer, linalg, lists, logic, numbertheory,
numeric, options, patterns, plot, physchemdata, randomnumbers, recurrence,
specialfunctions, scoping, strings, structure, system, tensors]

Expand Down Expand Up @@ -121,3 +121,18 @@ def contribute(definitions):
if not definitions.have_definition(ensure_context(operator)):
op = ensure_context(operator)
definitions.builtin[op] = Definition(name=op)

# Special case for Image[]: Image[] is an atom, and so Image[...]
# will not usually evaluate to anything, since there are no rules
# attached to it. we're adding one special rule here, that allows
# to construct Image atoms by using Image[] (using the helper
# builin ImageCreate).
from mathics.core.rules import Rule
from mathics.builtin.image import Image
from mathics.core.parser import parse_builtin_rule

definition = Definition(
name='System`Image', rules=[
Rule(parse_builtin_rule('Image[x_]'),
parse_builtin_rule('ImageCreate[x]'), system=True)])
definitions.builtin['System`Image'] = definition
Loading