I discovered several strange results and inconsistencies while trying to understand what undocumented RawArray and ArrayObject really are:
image = ImageResize[Import["http://wolfram.com/favicon.ico"][[1]], 1];
rawArray = ToBoxes[image][[1, 1, 1]]
(* RawArray[Byte, <1,1,4>] *)
rawArray // Head
(* RawArray *)
rawArray // Length
(* 2 *)
rawArray // InputForm
(* RawArray["Byte", {{{237, 153, 142, 255}}}] *)
Hold[RawArray]["Byte", {{{237, 153, 142, 255}}}] // Depth
(* 5 *)
rawArray // Depth
(* 2 *)
rawArray[[0]]
(* Part::partd: Part specification RawArray[Byte,<1,1,4>][[0]] is longer than depth of object. >> *)
(* RawArray *)
rawArray[[1]]
(* Part::partd: Part specification RawArray[Byte,<1,1,4>][[1]] is longer than depth of object. >> *)
(* "Byte" *)
arrayObject = rawArray[[2]]
(* Part::partd: Part specification RawArray[Byte,<1,1,4>][[2]] is longer than depth of object. >> *)
(* ArrayObject[Byte, <4>] *)
arrayObject // Head
(* Language`ArrayObject *)
arrayObject // AtomQ
(* True *)
wdx = ExportString[arrayObject, "WDX"];
ImportString[wdx, "WDX"]
(* {{{237, 153, 142, 255}}} *)
% // Head
(* List *)
Uncompress[Compress[arrayObject]]
(* {{{237, 153, 142, 255}}} *)
arrayObject // FullForm
(* List[List[List[237, 153, 142, 255]]] *)
arrayObject // InputForm
(* Raw[Language`ArrayObject, "78c4801b00000000"] *)
inputFormStr = ToString[arrayObject, InputForm]
(* "Raw[Language`ArrayObject, \"78c4801b00000000\"]" *)
heldArrayObject = ToExpression[inputFormStr, InputForm, Hold]
(* Hold[Raw[Language`ArrayObject, "78c4801b00000000"]] *)
heldArrayObject[[1, 0]]
(* Raw *)
heldArrayObject[[1, 1]]
(* Language`ArrayObject *)
heldArrayObject[[1, 2]]
(* "78c4801b00000000" *)
arrayObject2 = ReleaseHold[heldArrayObject]
(* 0 *)
arrayObject2 == 0
(* 0 == 0 *)
% // FullForm
(* Equal[1, 0] *)
ToBoxes[arrayObject2]
(* 0 *)
% // Head
(* Integer *)
arrayObject2 // Head
(* Language`ArrayObject *)
arrayObject2 // AtomQ
(* True *)
wdx = ExportString[arrayObject2, "WDX"];
reimported = ImportString[wdx, "WDX"]
(* Raw::string: String expected at position 2 in Raw[Language`ArrayObject,78 c4801b00000000]. >> *)
(* Raw[Language`ArrayObject, 78 c4801b00000000] *)
reimported // FullForm
(* Raw[Language`ArrayObject, Times[78, c4801b00000000]] *)
reimported // AtomQ
(* False *)
reimported // Depth
(* 3 *)
Uncompress[Compress[arrayObject2]]
(* "<---RAW DATA--->" *)
% // Head
(* String *)
Note that Part reports errors when invoked on a RawArray, but still is able to extract parts. ArrayObject has completely different representation in InputForm and FullForm, and turns into a List when reimported.
Is this behavior normal? Or there are some bugs? Is it because these parts were not supposed to ever be seen by humans?
Are there situations when one needs to explicitly construct or manipulate by RawArray or ArrayObject expressions? What is their real meaning?
AtomQ[image]on your favicon. I assume the user is not supposed to use/see/care-aboutRawArray's. – halirutan Jun 24 '13 at 11:00Imageis atomic, butGraphicsBoxorRasterBoxare not. – Vladimir Reshetnikov Jun 24 '13 at 17:22Image(and the underlying arrays) are highly optimized for speed. Otherwise there would clearly be any documentation and someone would have used it in all the packages which come with Mathematica. Anyway, have you seenimage[[1, 2]] //Language\FromArrayObjectandLanguage`NewArrayObject["Byte", {1, 2, 3, 4, 5, 5}]`? – halirutan Jun 24 '13 at 18:40ArrayObjectis literally just a thin wrapper around a C array that records its type and dimensions so that these can be passed around between the different image processing functions. AFAIK, there aren't any functions provided in the top-level language for manipulation of theRawArraytype. – Oleksandr R. Jun 24 '13 at 19:05