< Scratch File Format (1.4)(Redirected from Scratch File Format/Fixed-format Objects)

Archive.png This article or section documents something not included in the current version of Scratch (3.0). It is only useful from a historical perspective.
This is part of a technical description of the file format.

Fixed-format Objects are Objects with a fixed structure. This means they have a fixed number of fields (each with a fixed type). Their structure cannot change between versions, unlike User-class Objects.

They include basic data types: such as Color, String (text value), Point, Rectangle, Array, and Dictionary. The full list below is sorted by classID.


Their structure is described here.

They have classIDs between 1 and 98.

Non-pointer objects

9 String, 10 Symbol, 11 ByteArray

  • length: 32-bit unsigned integer
  • bytes: length many bytes.

12 SoundBuffer

  • length: 32-bit unsigned integer
  • bytes: (length * 2) many bytes.

13 Bitmap

  • length: 32-bit unsigned integer
  • bytes: (length * 4) many bytes.

14 UTF8

  • length: 32-bit unsigned integer
  • bytes: length many bytes.

[15-19 reserved for non-pointer objects]


20 Array, 21 OrderedCollection, 22 Set, 23 IdentitySet

These are assorted Arrays, like lists of objects.

  • length: 32-bit unsigned integer
  • bytes: length many fields (usually References, I think).

24 Dictionary, 25 IdentityDictionary

Dictionaries are collections of keys mapped to values.

  • length: 32-bit unsigned integer
  • items: length many key, value pairs.

[26-29 reserved for collections]


30 Color

  • 2 bits of padding
  • r: 10-bit integer
  • g: 10-bit integer
  • b: 10-bit integer

31 TranslucentColor

Same structure as Color, but also includes:

  • alpha: 8-bit unsigned integer


32 Point

  • x: field
  • y: field

33 Rectangle

4 fields


34 Form

Forms are rectangular arrays of pixels, used for holding images.

  • width: dimensions of the image
  • height:
  • depth: how many bits are used to specify the color at each pixel.
  • privateOffset: ?
  • bits: a Bitmap (or ByteArray). Has different internal structure depending on depth.
    • at depth 32: contains 32-bit color values.
      • alpha: 8-bit integer
      • r: 8-bit integer
      • g: 8-bit integer
      • b: 8-bit integer

35 ColorForm

Same fields as Form, but also includes:

  • color map: an array used to decode the bits bitmap.

From a post by nXIII:

"Form stores 32-bit words (split these into bytes to avoid arithmetic rounding errors) compressed into a ByteArray, decompressed in both the static & instance methods of Bitmap. These correspond to pixel values in the Form's depth, look into Color's static methods (I think #pixelValue:depth:)

ColorForm stores bytes containing color array indices (remember to subtract one from this because Squeak arrays are 1-based) which are also compressed. These point to colors in the colors array, which has 2^depth colors. For some reason, I had to render ColorForms in rows, and Forms in columns (this might be a bug in my code, though)."

"ColorForms end up with a ByteArray of indices in their colors array (which has 2^depth colors in it). Forms end up with an array of colors of the Form's depth."

[36-98 reserved]