Skip to content

ridatatypeslib

With datatypes, a program can load any file format for which a datatype is installed: a picture viewer that knows only IFF ILBM reads GIF or JPEG pictures as well. This library makes the system’s datatypes.library usable from Blitz Basic 2. It opens datatypes.library (version 37 or later) when the program starts; without it the commands do nothing. All its commands are Amiga mode only.

The library works on one file at a time, not on numbered objects. DataTypeOpen chooses the file and finds its datatype; DataTypeName, DataTypeBaseName, DataTypeID and DataTypeGroup describe it. DataTypeCreate loads the file into a datatype object. For a picture, DataTypeBitmap then reads its size and depth, which DataTypeWidth, DataTypeHeight, DataTypeDepth and DataTypeModeID return, and DataTypesPalette copies its colours into a Blitz palette object. AttachDataType adds the object to a Blitz window as a gadget, DetachDataType removes it again, and DataTypeClose frees the file and the object. Only one file and one object can be in use: DataTypeOpen and DataTypeCreate fail until DataTypeClose is called.

The commands were written for pictures; other groups may work with the commands that do not need a picture. An attached object is laid out by the system in the background: DataTypeReady tells when it is done, and the window gets IDCMP_IDCMPUPDATE messages from it.

Showing the type and size of a picture:

If DataTypeOpen("picture.iff")
  NPrint DataTypeName," (",DataTypeGroup,")"
  If DataTypeCreate
    If DataTypeBitmap
      NPrint DataTypeWidth,"x",DataTypeHeight,"x",DataTypeDepth
    EndIf
  EndIf
  DataTypeClose
EndIf

The fixed bugs of the library are listed in Fixes in ridatatypeslib.

Based on the RI DataTypes Lib guide by Red When Excited.

Library number 25.

Commands

AttachDataType

Adds the datatype object to a window as a gadget with the ID id, at 0,0 in the size of the picture, at x,y in the size width,height, or with a tag list. Returns -1, or 0 if there is no object or an object is attached already.

Statement or function, result .w. Help text: window,id[,x,y,width,height] | window,id,&taglist
3 forms:

  • .w, .l
  • .w, .l, .w, .w, .w, .w
  • .w, .l, .l

The object sends its update messages to the window as IDCMP_IDCMPUPDATE events; it is not ready to be drawn until DataTypeReady returns -1. The colours of a picture are not remapped. Only one object can be attached at a time.

The form without a position reads the picture’s bitmap header itself if DataTypeBitmap was not called, so DataTypeWidth and the other size functions can use it afterwards; for an object that is not a picture, this form returns 0. The form with a tag list passes the tag list on to the object.

DataTypeBaseName

The base name of the datatype of the open file, the name of the datatype’s own library without .datatype, for example ilbm. An empty string if no file is open.

Function, result $. No help text.
No arguments.

DataTypeBitmap

Reads the bitmap header of a picture object, which holds the picture’s size and depth, and returns its address; 0 if there is no object or it is not a picture. Call it before DataTypeWidth, DataTypeHeight, DataTypeDepth and DataTypeModeID.

Statement or function, result .l. No help text.
No arguments.

DataTypeClose

Frees the datatype object and closes the file opened with DataTypeOpen. An object that is still attached to a window is removed from it first.

Statement. No help text.
No arguments.

DataTypeCreate

Loads the open file into a datatype object, for the commands that work on the object. Returns the object’s address, or 0 if it cannot be made. The optional tag list is passed to the system when the object is made.

Statement or function, result .l. Help text: [&taglist]
2 forms:

  • no arguments
  • .l

The command returns 0 when no file is open, and while an object exists: the object stays in use until DataTypeClose.

DataTypeDepth

The depth of the picture in bitplanes, from the bitmap header that DataTypeBitmap reads; 0 if it has not been read.

Function, result .w. No help text.
No arguments.

DataTypeGroup

The group of the datatype of the open file, four characters, for example pict for pictures. An empty string if no file is open.

Function, result $. No help text.
No arguments.

The groups of the system are pict (picture), anim (animation), movi (movie), text (text), docu (hypertext document), musi (music), soun (sound), inst (musical instrument) and syst (system file).

DataTypeHeight

The height of the picture in pixels, from the bitmap header that DataTypeBitmap reads; 0 if it has not been read.

Function, result .w. No help text.
No arguments.

DataTypeID

The ID of the datatype of the open file, up to four characters, for example ILBM; for an IFF file the FORM type. An empty string if no file is open.

Function, result $. No help text.
No arguments.

DataTypeModeID

The display mode ID that suits the size and depth of the picture best, for example to open a screen for it; 0 if the bitmap header of DataTypeBitmap has not been read.

Function, result .l. Help text: [taglist]]
2 forms:

  • no arguments
  • .l

The form with a tag list passes the program’s tags on to the system after the library’s own three, the picture’s width, height and depth; for a tag in both, the library’s value counts. The program’s list stays unchanged.

DataTypeName

The name of the datatype of the open file, for example ILBM. An empty string if no file is open.

Function, result $. No help text.
No arguments.

DataTypeOpen

Opens a file and finds the datatype that matches it. Returns the address of the datatype on success, and 0 if the file cannot be found, no datatype matches it, another file is still open or datatypes.library could not be opened.

Statement or function, result .l. Help text: filename$
Arguments: $

DataTypeReady

Returns -1 when the system has finished preparing the attached object and it can be drawn, and 0 while it is still working or when no object is attached.

Function, result .w. No help text.
No arguments.

DataTypesPalette

Copies the colours of the picture object into the palette object palette#, at most as many as the palette object has. Returns a value other than 0 after copying, and 0 if there is no object or it has no colours.

Statement or function, result .l. Help text: palette#
Arguments: .w

The palette object must already exist; give it as many colours as the picture has, 2 to the power of DataTypeDepth. A smaller palette gets the picture’s first colours, a larger one keeps its other colours. The object does not have to be attached to a window.

DataTypeSuper

The name of the class of the datatype object, for example ilbm.datatype. An empty string if there is no object.

Function, result $. No help text.
No arguments.

DataTypeWidth

The width of the picture in pixels, from the bitmap header that DataTypeBitmap reads; 0 if it has not been read.

Function, result .w. No help text.
No arguments.

DetachDataType

Removes the datatype object from the window it was attached to with AttachDataType. Nothing happens if it is not attached.

Statement. No help text.
No arguments.

GetDataTypeAttr

Reads one attribute of the datatype object and returns the address where its value is stored, not the value itself; read it with Peek.l. Returns 0 if there is no object.

Function, result .l. Help text: attribute
Arguments: .l

The value is kept in a buffer that the next command of the library may overwrite.

SetDataTypeAttr

Changes attributes of the datatype object, given as the address of a tag list or as pairs of attribute and value. Nothing happens if there is no object.

Statement. Help text: &taglist / attr,data[,attr,data..]
2 forms:

  • .l
  • { .l, .l }...