1 /***********************************
3 * Demonstration of printing 24bit
4 * graphics bitmap with TurboPrint
7 ***********************************
9 * Meinrad-Spiess-Platz 2
12 * Tel. (49) 8341 74327
14 * Email: IrseeSoft@t-online.de
15 ***********************************/
19 #include <exec/types.h>
20 #include <exec/ports.h>
21 #include <exec/devices.h>
22 #include <devices/printer.h>
23 #include <devices/prtbase.h>
26 #include <proto/exec.h>
27 #include <proto/graphics.h>
28 #include <proto/intuition.h>
29 #include <proto/alib.h>
31 #include <libraries/cybergraphics.h>
32 #include <intuition/intuition.h>
33 #include <intuition/screens.h>
36 #include <turboprint.h>
42 struct IntuitionBase
*IntuitionBase
;
43 struct GfxBase
*GfxBase
;
49 struct IODRPReq iodrp
;
50 struct IOPrtCmdReq iopc
;
55 // this short demo programm opens an invisible 24bit RastPort and
56 // dumps it through TurboPrint to the printer
57 // You see: it works almost like the normal graphics dump
59 int main(int argc
, char **argv
)
61 struct MsgPort
*PrinterMP
;
63 struct PrinterData
*PD
;
64 struct TPExtIODRP ExtIoDrp
;
66 struct RastPort MyRastPort
;
67 struct BitMap MyBitMap
;
75 if ((IntuitionBase
= (struct IntuitionBase
*)OpenLibrary("intuition.library",37)))
76 if ((GfxBase
= (struct GfxBase
*)OpenLibrary("graphics.library",37)))
79 // create a RastPort Width * Height 24-Bit
81 InitRastPort(&MyRastPort
);
82 MyRastPort
.BitMap
= &MyBitMap
;
83 // we need only one BitPlane, because it's chunky format
84 InitBitMap(&MyBitMap
,1,Width
,Height
);
86 // now set the right BytesPerRow
87 // we could have set it as 3*Width in InitBitMap but
88 // InitBitMap sometimes calculates wrong BytesPerRow
89 // so we do it on our own
91 MyBitMap
.BytesPerRow
= 3*Width
;
94 // allocate a demo bitmap
96 if ((MyBitMap
.Planes
[0]= (APTR
)AllocMem(3*Width
*Height
,0)))
98 MemPoint
= (UBYTE
*)MyBitMap
.Planes
[0];
100 // and fill it with some colored stuff
105 // fill it with some nice colors
106 *MemPoint
++ = 255-((x
+y
)>>1); // red
107 *MemPoint
++ = (x
>127)? 2*(x
-128):255-2*x
; // green
108 *MemPoint
++ = (y
>127)? ((x
<127)? 255-((x
+y
)>>1):2*(y
-127)):0; // blue
112 // now create a MessagePort and Open the printer.device as usual
114 if ((PrinterMP
= (struct MsgPort
*)CreateMsgPort()))
116 if ((PIO
= (union printerIO
*)CreateExtIO(PrinterMP
,sizeof(union printerIO
))))
118 // open printer.device, if TurboPrint is installed, we automatically access the
119 // turboprint printer.device
120 if (!(OpenDevice("printer.device",0,(struct IORequest
*)PIO
,0)))
123 // before printing we need to know if TurboPrint is installed
124 // therefore check the MatchWord in the "PrinterData" structure
125 // element "pd_OldStack"
127 PD
= (struct PrinterData
*)PIO
->iodrp
.io_Device
;
129 typedef union {UBYTE b
[4]; ULONG l
;} BL
;
130 BL
*p
= (BL
*)(PD
->pd_OldStk
+ (2 * sizeof(ULONG
)));
131 TP_Installed
= (p
->l
== TPMATCHWORD
) ? TRUE
: FALSE
;
134 TPVersion
= PIO
->iodrp
.io_Device
->dd_Library
.lib_Version
;
136 TPIdString
= (char*)(PIO
->iodrp
.io_Device
->dd_Library
.lib_IdString
);
138 // you could now check chars 25-27 for version and revision
139 printf("Device-Version:%d\nTPIdString:%s\n",TPVersion
,&TPIdString
[1]);
142 if (TP_Installed
&& TPVersion
>= 39)
144 // fill in IORequest as normal
145 PIO
->iodrp
.io_Command
= PRD_TPEXTDUMPRPORT
;
146 PIO
->iodrp
.io_RastPort
= &MyRastPort
;
147 PIO
->iodrp
.io_ColorMap
= 0;
148 PIO
->iodrp
.io_SrcX
= 0;
149 PIO
->iodrp
.io_SrcY
= 0;
150 PIO
->iodrp
.io_SrcWidth
= Width
;
151 PIO
->iodrp
.io_SrcHeight
= Height
;
152 // all Special Flags are possible, here we do not need any
153 PIO
->iodrp
.io_Special
= 0;
156 // new: io.Modes must point to a new Structure (ExtIoDrp)
157 PIO
->iodrp
.io_Modes
= (IPTR
)&ExtIoDrp
;
159 // fill in the new structure
160 ExtIoDrp
.PixAspX
= 1; // for the correct aspect ratio
161 ExtIoDrp
.PixAspY
= 1; // normally the values of the monitor-structure
163 // our bitmap is 3 bytes format RGB (24 bits)
164 ExtIoDrp
.Mode
= TPFMT_RGB24
;
166 // send IORequest as usual to the printer.device
167 // Turboprint behaves exactly like the old printer.device
168 // so SendIO etc. are also possible
169 DoIO((struct IORequest
*)PIO
);
171 // if TurboPrint is not installed: Error-Message
172 // also possible: load TurboPrint:TurboPrefs with the -q flag, so
173 // you can install it yourself
174 else printf("Error: TurboPrint Pro 3 (or higher) not installed\n");
176 CloseDevice((struct IORequest
*)PIO
);
178 DeleteExtIO((struct IORequest
*)PIO
);
180 DeleteMsgPort(PrinterMP
);
182 FreeMem(MyBitMap
.Planes
[0],MyBitMap
.BytesPerRow
*MyBitMap
.Rows
);
185 if (GfxBase
) CloseLibrary((struct Library
*)GfxBase
);
186 if (IntuitionBase
) CloseLibrary((struct Library
*)IntuitionBase
);