add missing newline
[AROS.git] / workbench / demos / turboprint.c
blobcb117eded2109e90b97fa1711beab066a5d7edfd
1 /***********************************
2 * C-Source
3 * Demonstration of printing 24bit
4 * graphics bitmap with TurboPrint
5 * Professional 3.x/4.x
6 * December 1995
7 ***********************************
8 * IrseeSoft
9 * Meinrad-Spiess-Platz 2
10 * D-87660 Irsee
11 * Germany
12 * Tel. (49) 8341 74327
13 * Fax (49) 8341 12042
14 * Email: IrseeSoft@t-online.de
15 ***********************************/
17 #include <stdio.h>
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>
24 #include <dos/dos.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>
35 // some new Includes
36 #include <turboprint.h>
39 #define Width 256
40 #define Height 256
42 struct IntuitionBase *IntuitionBase;
43 struct GfxBase *GfxBase;
46 union printerIO
48 struct IOStdReq ios;
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;
62 union printerIO *PIO;
63 struct PrinterData *PD;
64 struct TPExtIODRP ExtIoDrp;
66 struct RastPort MyRastPort;
67 struct BitMap MyBitMap;
68 UWORD x,y;
69 UBYTE *MemPoint;
70 BOOL TP_Installed;
72 UWORD TPVersion;
73 char* TPIdString;
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
102 for (y=0;y<256;y++)
103 for (x=0;x<256;x++)
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;
128 TP_Installed = ( ((ULONG *)(PD->pd_OldStk))[2] == TPMATCHWORD);
130 TPVersion = PIO->iodrp.io_Device->dd_Library.lib_Version;
132 TPIdString = (char*)(PIO->iodrp.io_Device->dd_Library.lib_IdString);
134 // you could now check chars 25-27 for version and revision
135 printf("Device-Version:%d\nTPIdString:%s\n",TPVersion,&TPIdString[1]);
138 if (TP_Installed && TPVersion >= 39)
140 // fill in IORequest as normal
141 PIO->iodrp.io_Command = PRD_TPEXTDUMPRPORT;
142 PIO->iodrp.io_RastPort = &MyRastPort;
143 PIO->iodrp.io_ColorMap = 0;
144 PIO->iodrp.io_SrcX = 0;
145 PIO->iodrp.io_SrcY = 0;
146 PIO->iodrp.io_SrcWidth = Width;
147 PIO->iodrp.io_SrcHeight = Height;
148 // all Special Flags are possible, here we do not need any
149 PIO->iodrp.io_Special = 0;
152 // new: io.Modes must point to a new Structure (ExtIoDrp)
153 PIO->iodrp.io_Modes = (IPTR)&ExtIoDrp;
155 // fill in the new structure
156 ExtIoDrp.PixAspX = 1; // for the correct aspect ratio
157 ExtIoDrp.PixAspY = 1; // normally the values of the monitor-structure
158 // TicksX and TicksY
159 // our bitmap is 3 bytes format RGB (24 bits)
160 ExtIoDrp.Mode = TPFMT_RGB24;
162 // send IORequest as usual to the printer.device
163 // Turboprint behaves exactly like the old printer.device
164 // so SendIO etc. are also possible
165 DoIO((struct IORequest *)PIO);
167 // if TurboPrint is not installed: Error-Message
168 // also possible: load TurboPrint:TurboPrefs with the -q flag, so
169 // you can install it yourself
170 else printf("Error: TurboPrint Pro 3 (or higher) not installed\n");
172 CloseDevice((struct IORequest *)PIO);
174 DeleteExtIO((struct IORequest *)PIO);
176 DeleteMsgPort(PrinterMP);
178 FreeMem(MyBitMap.Planes[0],MyBitMap.BytesPerRow*MyBitMap.Rows);
181 if (GfxBase) CloseLibrary((struct Library*)GfxBase);
182 if (IntuitionBase) CloseLibrary((struct Library*)IntuitionBase);
184 return 0;