Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

Previous Book Contents Book Index Next

Inside Macintosh: Imaging With QuickDraw /
Appendix A - Picture Opcodes


Opcodes in Pictures

Pictures created with the OpenPicture function in a color graphics port use the picture opcodes of the version 2 format. Pictures created with the OpenCPicture function use the opcodes of the extended version 2 format. The inclusion of resolution information in the header differentiates the extended version 2 format from the version 2 picture format. The extended version 2 and version 2 formats share the same opcodes, which are listed in Table A-2. The length of the data that follows each 2-byte opcode is listed in this table.

Pictures created with the OpenPicture function in a basic graphics port use the opcodes of the version 1 format, which are listed in Table A-3 on page A-18.

The unused opcodes found throughout Table A-2 and Table A-3 are reserved for Apple use. If these opcodes are encountered in pictures, they and their reserved data bytes can simply be skipped. By default, QuickDraw reads and then ignores these opcodes. Because opcodes must be word-aligned in version 2 and extended version 2 pictures, a byte of 0 (zero) data is added after odd-size data.

Note
For opcodes $0100-$7FFF, the amount of data for
opcode $nnXX = 2 times nn bytes.
Table A-2Opcodes for extended version 2 and version 2 pictures
OpcodeNameDescriptionSize (in bytes) of additional data
$0000NOPNo operation0
$0001ClipClipping regionRegion size
$0002BkPatBackground pattern8
$0003TxFontFont number for text (Integer)2
$0004TxFaceText's font style (0..255)1
$0005TxModeSource mode (Integer)2
 
$0006SpExtraExtra space (Fixed)4
$0007PnSizePen size (Point)4
$0008PnModePen mode (Integer)2
$0009PnPatPen pattern8
$000AFillPatFill pattern8
$000BOvSizeOval size (Point)4
$000COrigindh, dv (Integer)4
$000DTxSizeText size (Integer)2
$000EFgColorForeground color (Long)4
$000FBkColorBackground color (Long)4
$0010TxRatioNumerator (Point), denominator (Point)8
$0011VersionOpVersion (0..255)1
$0012BkPixPatBackground pixel patternVariable; see Listing A-1 on page A-17
$0013PnPixPatPen pixel patternVariable; see Listing A-1 on page A-17
$0014FillPixPatFill pixel patternVariable; see Listing A-1 on page A-17
$0015PnLocHFracFractional pen position (Integer--low word of Fixed); if value is not 0.5, pen position is always set to the picture before each text-drawing operation.2
$0016ChExtraAdded width for nonspace characters (Integer)2
$0017Reserved for Apple use Not determined
$0018Reserved for Apple use Not determined
$0019Reserved for Apple use Not determined
$001ARGBFgColForeground color (RGBColor)6
$001BRGBBkColBackground color (RGBColor)6
$001CHiliteModeHighlight mode flag: no data; this opcode is sent before a drawing operation that uses the highlight mode0
$001DHiliteColorHighlight color (RGBColor)6
$001EDefHiliteUse default highlight color; no data; set highlight to default (from low memory)0
$001FOpColorOpcolor (RGBColor)6
$0020LinepnLoc (Point), newPt (Point)8
$0021LineFromnewPt (Point)4
$0022ShortLinepnLoc (Point), dh (-128..127), dv (-128..127)6
$0023ShortLineFromdh (-128..127), dv (-128..127)2
$0024Reserved for Apple useData length (Integer), data2 + data length
$0025Reserved for Apple useData length (Integer), data2 + data length
$0026Reserved for Apple useData length (Integer), data2 + data length
$0027Reserved for Apple useData length (Integer), data2 + data length
$0028LongTexttxLoc (Point), count (0..255), text5 + text
$0029DHTextdh (0..255), count (0..255), text2 + text
$002ADVTextdv (0..255), count (0..255), text2 + text
$002BDHDVTextdh (0..255), dv (0..255), count (0..255), text3 + text
$002CfontNameData length (Integer), old font ID (Integer), name length (0..255), font name[1]5 + name length
$002DlineJustifyOperand data length (Integer), intercharacter spacing (Fixed), total extra space for justification (Fixed)[2]10
$002EglyphStateData length (word), followed by these 1-byte Boolean values: outline preferred, preserve glyph, fractional widths, scaling disabled8
 
$002FReserved for Apple useData length (Integer), data2 + data length
$0030frameRectRectangle (Rect)8
$0031paintRectRectangle (Rect)8
$0032eraseRectRectangle (Rect)8
$0033invertRectRectangle (Rect)8
$0034fillRectRectangle (Rect)8
$0035Reserved for Apple use8 bytes of data8
$0036Reserved for Apple use8 bytes of data8
$0037Reserved for Apple use8 bytes of data8
$0038frameSameRectRectangle (Rect)0
$0039paintSameRectRectangle (Rect)0
$003AeraseSameRectRectangle (Rect)0
$003BinvertSameRectRectangle (Rect)0
$003CfillSameRectRectangle (Rect)0
$003DReserved for Apple use 0
$003EReserved for Apple use 0
$003FReserved for Apple use 0
$0040frameRRectRectangle (Rect)[3]8
$0041paintRRectRectangle (Rect)[3]8
$0042eraseRRectRectangle (Rect)[3]8
$0043invertRRectRectangle (Rect)[3]8
$0044fillRRectRectangle (Rect)[3]8
$0045Reserved for Apple use8 bytes of data8
$0046Reserved for Apple use8 bytes of data8
$0047Reserved for Apple use8 bytes of data8
$0048frameSameRRectRectangle (Rect)0
$0049paintSameRRectRectangle (Rect)0
$004AeraseSameRRectRectangle (Rect)0
$004BinvertSameRRectRectangle (Rect)0
$004CfillSameRRectRectangle (Rect)0
$004DReserved for Apple use 0
$004EReserved for Apple use 0
$004FReserved for Apple use 0
$0050frameOvalRectangle (Rect)8
$0051paintOvalRectangle (Rect)8
$0052eraseOvalRectangle (Rect)8
$0053invertOvalRectangle (Rect)8
$0054fillOvalRectangle (Rect)8
$0055Reserved for Apple use8 bytes of data8
$0056Reserved for Apple use8 bytes of data8
$0057Reserved for Apple use8 bytes of data8
$0058frameSameOvalRectangle (Rect)0
$0059paintSameOvalRectangle (Rect)0
$005AeraseSameOvalRectangle (Rect)0
$005BinvertSameOvalRectangle (Rect)0
$005CfillSameOvalRectangle (Rect)0
$005DReserved for Apple use 0
$005EReserved for Apple use 0
$005FReserved for Apple use 0
$0060frameArcRectangle (Rect), startAngle, arcAngle12
$0061paintArcRectangle (Rect), startAngle, arcAngle12
$0062eraseArcRectangle (Rect), startAngle, arcAngle12
$0063invertArcRectangle (Rect), startAngle, arcAngle12
$0064fillArcRectangle (Rect), startAngle, arcAngle12
$0065Reserved for Apple use12 bytes of data12
$0066Reserved for Apple use12 bytes of data12
 
$0067Reserved for Apple use12 bytes of data12
$0068frameSameArcRectangle (Rect)4
$0069paintSameArcRectangle (Rect)4
$006AeraseSameArcRectangle (Rect)4
$006BinvertSameArcRectangle (Rect)4
$006CfillSameArcRectangle (Rect)4
$006DReserved for Apple use4 bytes of data4
$006EReserved for Apple use4 bytes of data4
$006FReserved for Apple use4 bytes of data4
$0070framePolyPolygon (Poly)Polygon size
$0071paintPolyPolygon (Poly)Polygon size
$0072erasePolyPolygon (Poly)Polygon size
$0073invertPolyPolygon (Poly)Polygon size
$0074fillPolyPolygon (Poly)Polygon size
$0075Reserved for Apple usePolygon (Poly)Polygon size
$0076Reserved for Apple usePolygon (Poly)Polygon size
$0077Reserved for Apple usePolygon (Poly)Polygon size
$0078frameSamePoly(Not yet implemented)0
$0079paintSamePoly(Not yet implemented)0
$007AeraseSamePoly(Not yet implemented)0
$007BinvertSamePoly(Not yet implemented)0
$007CfillSamePoly(Not yet implemented)0
$007DReserved for Apple use 0
$007EReserved for Apple use 0
$007FReserved for Apple use 0
$0080frameRgnRegion (Rgn)Region size
$0081paintRgnRegion (Rgn)Region size
$0082eraseRgnRegion (Rgn)Region size
$0083invertRgnRegion (Rgn)Region size
$0084fillRgnRegion (Rgn)Region size
$0085Reserved for Apple useRegion (Rgn)Region size
$0086Reserved for Apple useRegion (Rgn)Region size
$0087Reserved for Apple useRegion (Rgn)Region size
$0088frameSameRgn(Not yet implemented)0
$0089paintSameRgn(Not yet implemented)0
$008AeraseSameRgn(Not yet implemented)0
$008BinvertSameRgn(Not yet implemented)0
$008CfillSameRgn(Not yet implemented)0
$008DReserved for Apple use 0
$008EReserved for Apple use 0
$008FReserved for Apple use 0
$0090BitsRectCopyBits with clipped rectangleVariable[4][5]; see Listing A-2 on page A-17
$0091BitsRgnCopyBits with clipped regionVariable[4][5]; see Listing A-3 on page A-18
$0092Reserved for Apple useData length (Integer), data2 + data length
$0093Reserved for Apple useData length (Integer), data2 + data length
$0094Reserved for Apple useData length (Integer), data2 + data length
$0095Reserved for Apple useData length (Integer), data2 + data length
$0096Reserved for Apple useData length (Integer), data2 + data length
$0097Reserved for Apple useData length (Integer), data2 + data length
$0098PackBitsRectPacked CopyBits with clipped rectangleVariable[4]; see Listing A-2 on page A-17
$0099PackBitsRgnPacked CopyBits with clipped rectangleVariable[4]; see Listing A-3 on page A-18
$009ADirectBitsRect PixMap, srcRect, dstRect, mode (Integer), PixDataVariable
 
$009BDirectBitsRgnPixMap, srcRect, dstRect,
mode (Integer), maskRgn, PixData
Variable
$009CReserved for Apple useData length (Integer), data2 + data length
$009DReserved for Apple useData length (Integer), data2 + data length
$009EReserved for Apple useData length (Integer), data2 + data length
$009FReserved for Apple useData length (Integer), data2 + data length
$00A0ShortCommentKind (Integer)2
$00A1LongCommentKind (Integer), size (Integer), data4 + data
$00A2Reserved for Apple useData length (Integer), data2 + data length
....
....
....
$00AFReserved for Apple useData length (Integer), data2 + data length
$00B0Reserved for Apple use 0
....
....
....
$00CFReserved for Apple use 0
$00D0Reserved for Apple useData length (Long), data4 + data length
....
....
....
$00FEReserved for Apple useData length (Long), data4 + data length
$00FFOpEndPicEnd of picture2
$0100Reserved for Apple use2 bytes of data2
....
....
....
$01FFReserved for Apple use2 bytes of data2
$0200Reserved for Apple use4 bytes of data4
$02FFVersionVersion number of picture2
....
....
....
$0BFFReserved for Apple use22 bytes of data22
$0C00HeaderOpFor extended version 2: version (Integer), reserved (Integer), hRes, vRes (Fixed), srcRect, reserved (Long);
for version 2: opcode
24
$0C01Reserved for Apple use24 bytes of data24
....
....
....
$7F00Reserved for Apple use254 bytes of data254
....
....
....
$7FFFReserved for Apple use254 bytes of data254
$8000Reserved for Apple use 0
....
....
....
$80FFReserved for Apple use 0
$8100Reserved for Apple useData length (Long), data4 + data length
....
....
....
 
$8200CompressedQuickTimeData length (Long), data (private to QuickTime)4 + data length
$8201UncompressedQuickTimeData length (Long), data (private to QuickTime)4 + data length
$FFFFReserved for Apple useData length (Long), data4 + data length
Opcodes $009A (DirectBitsRect) and $009B (DirectBitsRgn) define direct-pixel pictures, with pixel maps containing three components that directly specify RGB colors. These opcodes allow your application to cut, paste, and store images with up to 32 bits of color information per pixel.

The DirectBitsRect and DirectBitsRgn opcodes store the baseAddr field of the PixMap record in a version 2 picture. For compatibility with existing systems, the baseAddr field is set to $000000FF. Black-and-white video devices can display pixel maps that are in pictures. On systems without direct-pixel support, opcodes $009A and $009B read a word from the picture and then skip a word of data. The next opcode retrieved from the picture is $00FF, which terminates picture playback. (Note that if you play back a picture on a machine without direct-pixel support, it terminates picture parsing.)

The DirectBitsRect opcode is followed by this structure:

pixMap:     PixMap;   
srcRect:    Rect;    {source rectangle}
dstRect:    Rect;    {destination rectangle}
mode:       Mode;    {transfer mode}
pixData:    
The DirectBitsRgn opcode is followed by this structure:

pixMap:     PixMap;  
srcRect:    Rect;    {source rectangle}
dstRect:    Rect;    {destination rectangle}
mode:       Mode;    {transfer mode}
maskRgn:    Region;  {region for masking}
pixData:    
In a picture, the packType field of a PixMap record specifies the manner in which the pixel data was compressed. To facilitate banding of images when memory is short, all data compression is done on a scan-line basis. The following pseudocode describes the pixel data:

PixData:
IF packType = 1 (unpacked) OR rowbytes < 8 THEN 
   data is unpacked; 
   data size = rowBytes * (bounds.bottom - bounds.top);

IF packType = 2 (drop pad byte) THEN 
   the high-order pad byte of a 32-bit direct pixel is 
   dropped; 
   data size = (3/4) * rowBytes * 
   (bounds.bottom - bounds.top);

IF packType > 2 (packed) THEN 
   image contains (bounds.bottom - bounds.top) packed 
   scan lines;
   each scan line consists of [byteCount] [data];
   IF rowBytes > 250 THEN 
      byteCount is a word
   ELSE 
      it is a byte
Here are the currently defined packing types:
Packing typeMeaning
0Use default packing
1Use no packing
2Remove pad byte--supported only for 32-bit pixels
(24-bit data)
3Run length encoding by pixelSize chunks, one scan line
at a time--supported only for 16-bit pixels
4Run length encoding one component at a time, one scan
line at a time, red component first--supported only for
32-bit pixels (24-bit data)

For future compatibility, other packType values skip scan-line data and draw nothing. Since QuickDraw assumes that pixel map data in memory is unpacked regardless of the packType field value, you can use packType to tell the picture-recording mechanism what packing technique to use on that data. A packType value of 0 in memory indicates that the default packing scheme should be used. (Using the default packing scheme is recommended.) Currently, the default packType value for a pixelSize value of 16 is type 3; for a pixelSize value of 32, it is type 4. Regardless of the setting of packType at the time of picture recording, the packType value actually used to save the image is recorded in the picture.

Since each scan line of packed data is preceded by a byte count, packSize is not used and must be 0 for future compatibility.

When the pixel type is direct, cmpCount * cmpSize is less than or equal to pixelSize. For storing 24-bit data in a 32-bit pixel, set cmpSize to 8 and cmpCount to 3. If you set cmpCount to 4, then the high byte is compressed by packing scheme 4 and stored in the picture.

The OpenCPicture function lets your application create a version 2 format picture and include rectangle and resolution information, which is stored in the version 2 picture header. The OpenCPicture function is described in the chapter "Pictures."

The HeaderOp information is passed to the OpenCPicture function as an OpenCPicParams record, which is described in the chapter "Pictures" in this book.

The pseudocode in Listing A-1 illustrates the data for the BkPixPat, PnPixPat, and FillPixPat opcodes.

Listing A-1 Data for the BkPixPat, PnPixPat, and FillPixPat opcodes

IF patType = ditherPat  
THEN
   PatType:    word;       {pattern type = 2}
   Pat1Data:   Pattern;    {old pattern data}
   RGB:        RGBColor;   {desired RGB for pattern}
ELSE 
   PatType:    word;       {pattern type = 1}
   Pat1Data:   Pattern;    {old pattern data}
   PixMap:     PixMap;
   ColorTable: ColorTable;
   PixData:    PixData;    
END;
The pseudocode in Listing A-2 illustrates the data is stored in the BitsRect and PackBitsRect opcodes.

Listing A-2 Data for the BitsRect and PackBitsRect opcodes

   PixMap:     PixMap;     {pixel map}
   ColorTable: ColorTable; {ColorTable record}
   srcRect:    Rect;       {source rectangle}  
   dstRect:    Rect;       {destination rectangle}  
   mode:       Word;       {transfer mode (may include }
                           { new transfer modes)}
   PixData:    PixData;    
The pseudocode in Listing A-3 illustrates the data is stored in the BitsRgn and PackBitsRgn opcodes.

Listing A-3 Data for the BitsRgn and PackBitsRgn opcodes

   pixMap:     PixMap;         
   colorTable: ColorTable;     
   srcRect:    Rect;          {source rectangle} 
   dstRect:    Rect;          {destination rectangle} 
   mode:       Word;          {transfer mode (may }
                              { include new modes)}
   maskRgn:    Rgn;           {region for masking} 
   pixData:    PixData;       
Pictures created with the OpenPicture function in a basic graphics port use the opcodes of the version 1 format, as listed in Table A-3. This size of data that follows each opcode is also listed in this table. Version 1 pictures are limited to 32 KB.
Table A-3 Opcodes for version 1 pictures (Continued)
OpcodeNameDescriptionSize (in bytes) of additional data
$00NOPNo operation0
$01ClipRgnClipping regionRegion size
$02BkPatBackground pattern8
$03TxFontFont number for text (Integer)2
$04TxFaceText's font style (0..255)1
$05TxModeSource mode (Integer)2
$06SpExtraExtra space (Fixed)4
$07PnSizePen size (Point)4
$08PnModePen mode (Integer)2
$09PnPatPen pattern8
$0AFillPatFill pattern8
$0BOvSizeOval size (Point)4
$0COrigindh (Integer), dv (Integer)4
$0DTxSizeText size (Integer)2
$0EFgColorForeground color (Long)4
$0FBkColorBackground color (Long)4
$10TxRatioNumerator (Point), denominator (Point)8
$11picVersionVersion (0..255)1
$20LinepnLoc (Point), newPt (Point)8
$21LineFromnewPt (Point)4
$22ShortLinepnLoc (Point), dh (-128..127),
dv (-128..127)
6
$23ShortLineFromdh (-128..127), dv (-128..127)2
$28LongTexttxLoc (Point), count (0..255), text5 + text
$29DHTextdh (0..255), count (0..255), text2 + text
$2ADVTextdv (0..255), count (0..255), text2 + text
$2BDHDVTextdh (0..255), dv (0..255), count (0..255), text3 + text
$30frameRectRectangle (Rect)8
$31paintRectRectangle (Rect)8
$32eraseRectRectangle (Rect)8
$33invertRectRectangle (Rect)8
$34fillRectRectangle (Rect)8
$38frameSameRectRectangle (Rect)0
$39paintSameRectRectangle (Rect)0
$3AeraseSameRectRectangle (Rect)0
$3BinvertSameRectRectangle (Rect)0
$3CfillSameRectRectangle (Rect)0
$40frameRRectRectangle (Rect)[6]8
$41paintRRectRectangle (Rect)8
$42eraseRRectRectangle (Rect)8
$43invertRRectRectangle (Rect)8
$44fillRRectRectangle (Rect)8
$48frameSameRRectRectangle (Rect)0
$49paintSameRRectRectangle (Rect)0
$4AeraseSameRRectRectangle (Rect)0
 
$4BinvertSameRRectRectangle (Rect)0
$4CfillSameRRectRectangle (Rect)0
$50frameOvalRectangle (Rect)8
$51paintOvalRectangle (Rect)8
$52eraseOvalRectangle (Rect)8
$53invertOvalRectangle (Rect)8
$54fillOvalRectangle (Rect)8
$58frameSameOvalRectangle (Rect)0
$59paintSameOvalRectangle (Rect)0
$5AeraseSameOvalRectangle (Rect)0
$5BinvertSameOvalRectangle (Rect)0
$5CfillSameOvalRectangle (Rect)0
$60frameArcRectangle (Rect), startAngle, arcAngle12
$61paintArcRectangle (Rect), startAngle, arcAngle12
$62eraseArcRectangle (Rect), startAngle, arcAngle12
$63invertArcRectangle (Rect), startAngle, arcAngle12
$64fillArcRectangle (Rect), startAngle, arcAngle12
$68frameSameArcRectangle (Rect)4
$69paintSameArcRectangle (Rect)4
$6AeraseSameArcRectangle (Rect)4
$6BinvertSameArcRectangle (Rect)4
$6CfillSameArcRectangle (Rect)4
$70framePolyPolygon (Poly)Polygon size
$71paintPolyPolygon (Poly)Polygon size
$72erasePolyPolygon (Poly)Polygon size
$73invertPolyPolygon (Poly)Polygon size
$74fillPolyPolygon (Poly)Polygon size
$78frameSamePoly(Not yet implemented)0
$79paintSamePoly(Not yet implemented)0
$7AeraseSamePoly(Not yet implemented)0
$7BinvertSamePoly(Not yet implemented)0
$7CfillSamePoly(Not yet implemented)0
$80frameRgnRegion (Rgn)Region size
$81paintRgnRegion (Rgn)Region size
$82eraseRgnRegion (Rgn)Region size
$83invertRgnRegion (Rgn)Region size
$84fillRgnRegion (Rgn)Region size
$88frameSameRgn(Not yet implemented) 0
$89paintSameRgn(Not yet implemented)0
$8AeraseSameRgn(Not yet implemented)0
$8BinvertSameRgn(Not yet implemented)0
$8CfillSameRgn(Not yet implemented)0
$90BitsRectCopyBits with clipped rectangleVariable[7][8]; see Listing A-2 on page A-17
$91BitsRgnCopyBits with clipped regionVariable[7][8]; see Listing A-3 on page A-18
$98PackBitsRectPacked CopyBits with clipped rectangleVariable[7]; see
Listing A-2 on page A-17
$99PackBitsRgnPacked CopyBits with clipped rectangleVariable[7]; see
Listing A-3 on page A-18
$A0ShortCommentKind (Integer)2
$A1LongCommentKind (Integer), size (Integer), data4 + data
$FFEndOfPictureEnd of picture0


[1] The font name information begins with a word containing the field's data length, followed by a word containing the old font ID, a byte containing the length of the font name, and then the font name itself.

You can extract font names, IDs, and other information from a picture by using the routines described in the chapter "Pictures" in this book.
[2] For opcode $002D (lineJustify), the line justification information contains the line-layout state of the Script Manager so that it can be restored when the picture is played back. It begins with a word containing the field's data length, which should always be 8 bytes. The operands are two fixed-point values, describing the Script Manager's extra character width value and the total extra width that was added to the style run (each StdText call) to perform justification.

For example, if the intercharacter spacing were 1 pixel and the total extra width added were 10 pixels, the following hexadecimal bytes would be generated for the picture:

2D 00 08 00 01 00 00 00 0A 00 00

In this example, the $002D opcode is followed by the length word, 00 08, and then the integer part of the intercharacter spacing, 00 01, its fractional part, 00 00, and then the integer part of the total extra spacing, 00 0A, and its fractional part, 00 00.
[3] For opcodes $0040-$0044: rounded rectangles use the setting of the OvSize point (refer to opcode $000B).

[4] Four opcodes ($0090, $0091, $0098, $0099) are modifications of version 1 opcodes. The first word following the opcode is rowBytes. If the high bit of rowBytes is set, then it is a pixel map containing multiple bits per pixel; if it is not set, it is a bitmap containing 1 bit per pixel. In general, the difference between version 2 and version 1 formats is that the pixel map replaces the bitmap, a color table has been added, and pixData replaces bitData.

[5] For opcodes $0090 (BitsRect) and $0091 (BitsRgn), the data is unpacked. These opcodes can be used only when rowBytes is less than 8.
[6] For opcodes $40-$44: rounded rectangles use the setting of the OvSize point (refer to
opcode $0B).
[7] In general, the difference between version 2 and version 1 formats is that the pixel map replaces the bitmap, a color table has been added, and pixData replaces bitData.
[8] For opcodes $90 (BitsRect) and $91 (BitsRgn), the data is unpacked. These opcodes can only be used when rowBytes is less than 8.

Previous Book Contents Book Index Next

© Apple Computer, Inc.
7 JUL 1996