REBOL 3.0

Load/save and decode/encode (Codecs in A42)

Carl Sassenrath, CTO
REBOL Technologies
31-Mar-2009 3:42 GMT

Article #0184
Main page || Index || Prior Article [0183] || Next Article [0185] || 14 Comments || Send feedback

Here's a quick summary of changes in A42.

This is a first draft and adheres to the keep-it-simple principle. (I realize it will grow as we move forward, but let's be sure not to forget to keep it productive to all users.)

LOAD and SAVE changes

The load and save functions have been updated to call the appropriate codec (see section below) depending on the suffix. This keeps things simple.

Here is an example that converts a JPEG to a BMP:

save %photo.bmp load %photo.jpg

Here is an example to display an image:

load-gui ; (required for now, but not later)
gob: make gob! []
gob/image: load %photo.jpg
view gob

(BTW, we should extend view to accept an image! datatype directly. Easy to support. Little code.)

DECODE and ENCODE

These two mezzanine functions have been added. These functions convert between binary and REBOL datatypes.

>> ? decode
USAGE:
       DECODE type data

DESCRIPTION:
       Decodes a series of bytes into its specific media type.
       DECODE is a function value.

ARGUMENTS:
       type -- Media type (jpeg, png, etc.) (word!)
       data -- The data to decode (binary!)

and:

>> ? encode
USAGE:
       ENCODE type data /options

DESCRIPTION:
       Encodes media data type into a series of bytes.
       ENCODE is a function value.

ARGUMENTS:
       type -- Media type (jpeg, png, etc.) (word!)
       data -- The data to encode (image! binary! string!)

REFINEMENTS:
       /options -- Special encoding options

These are called by load and save, but you can also call them directly.

Examples:

image: decode 'jpeg data
data: encode 'bmp image

The special encoding options will be for variables, such as JPEG quality (once that's supported).

Codecs added to system object:

The codecs (encoders/decoders) used above are actually accessed via a general mechanism the system object.

>> ? system/catalog/codecs
SYSTEM/CATALOG/CODECS is an object of value:
   jpeg            object!   [entry name info suffixes]
   bmp             object!   [entry name info suffixes]

As you can see, two internal codecs are in this release. More will be added, and we will allow external codecs too. Also, currently, only the image! datatype is supported, but other types will be allowed.

The codec field names are not final. Also, a type field must be added.

The suffixes field is used to provide the basic mapping from a file suffix to one of these codecs. The suffixes are used to build system/catalog/file-types.

How to make comments and suggestions

I realize that this could become a hot topic with many comments. You can post them on DevBase (R3 Chat #3190) or here on this blog.

Please try to keep things concise and to the point. Provide examples where possible. We must take it a step at a time.

14 Comments

REBOL 3.0
Updated 24-Apr-2024 - Edit - Copyright REBOL Technologies - REBOL.net