1 | /*
|
---|
2 | * Copyright (c) Chris Wohlgemuth 2002
|
---|
3 | * All rights reserved.
|
---|
4 | *
|
---|
5 | * http://www.geocities.com/SiliconValley/Sector/5785/
|
---|
6 | * http://www.os2world.com/cdwriting
|
---|
7 | *
|
---|
8 | * Redistribution and use in source and binary forms, with or without
|
---|
9 | * modification, are permitted provided that the following conditions
|
---|
10 | * are met:
|
---|
11 | * 1. Redistributions of source code must retain the above copyright
|
---|
12 | * notice, this list of conditions and the following disclaimer.
|
---|
13 | * 2. Redistributions in binary form must reproduce the above copyright
|
---|
14 | * notice, this list of conditions and the following disclaimer in the
|
---|
15 | * documentation and/or other materials provided with the distribution.
|
---|
16 | * 3. The authors name may not be used to endorse or promote products
|
---|
17 | * derived from this software without specific prior written permission.
|
---|
18 | *
|
---|
19 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND
|
---|
20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
---|
21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
---|
22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
---|
23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
---|
24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
---|
25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
---|
26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
---|
27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
---|
28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
---|
29 | * SUCH DAMAGE.
|
---|
30 | *
|
---|
31 | */
|
---|
32 | #define INCL_DOSERRORS
|
---|
33 | #define INCL_DOSMODULEMGR
|
---|
34 | #define INCL_DOSPROCESS
|
---|
35 | #define INCL_DOSSEMAPHORES
|
---|
36 | #define INCL_DOSMEMMGR
|
---|
37 | #define INCL_GPI
|
---|
38 | #define INCL_GPICONTROL
|
---|
39 | #define INCL_GPILCIDS
|
---|
40 | #define INCL_GPIMETAFILES
|
---|
41 | #define INCL_GPIPRIMITIVES
|
---|
42 | #define INCL_GPIREGIONS
|
---|
43 | #define INCL_PM
|
---|
44 | #define INCL_WIN
|
---|
45 | #define INCL_WINDIALOGS
|
---|
46 | #define INCL_WINERRORS
|
---|
47 | #define INCL_WINFRAMEMGR
|
---|
48 | #define INCL_WINHELP
|
---|
49 | #define INCL_WINMENUS
|
---|
50 | #define INCL_WINMESSAGEMGR
|
---|
51 | #define INCL_WINMLE
|
---|
52 | #define INCL_WINPOINTERS
|
---|
53 | #define INCL_WINSTDDLGS
|
---|
54 | #define INCL_WINSTDFILE
|
---|
55 | #define INCL_WINSTDSLIDER
|
---|
56 | #define INCL_WINSWITCHLIST
|
---|
57 | #define INCL_WINSYS
|
---|
58 | #define INCL_WINTIMER
|
---|
59 | #define INCL_WINWINDOWMGR
|
---|
60 |
|
---|
61 | #include <os2.h>
|
---|
62 | #include <stdio.h>
|
---|
63 | #include <string.h>
|
---|
64 | #include <malloc.h>
|
---|
65 | #include "mmioos2.h"
|
---|
66 |
|
---|
67 | char pszFileName[]="";
|
---|
68 |
|
---|
69 | int main()
|
---|
70 | {
|
---|
71 | HBITMAP hbm;
|
---|
72 | MMIOINFO mmioinfo;
|
---|
73 | MMFORMATINFO mmFormatInfo;
|
---|
74 | HMMIO hmmio;
|
---|
75 | ULONG ulImageHeaderLength;
|
---|
76 | MMIMAGEHEADER mmImgHdr;
|
---|
77 | ULONG ulBytesRead;
|
---|
78 | ULONG dwNumRowBytes;
|
---|
79 | PBYTE pRowBuffer;
|
---|
80 | ULONG dwRowCount;
|
---|
81 | SIZEL ImageSize;
|
---|
82 | ULONG dwHeight, dwWidth;
|
---|
83 | SHORT wBitCount;
|
---|
84 | FOURCC fccStorageSystem;
|
---|
85 | ULONG dwPadBytes;
|
---|
86 | ULONG dwRowBits;
|
---|
87 | ULONG ulReturnCode;
|
---|
88 | ULONG dwReturnCode;
|
---|
89 | HBITMAP hbReturnCode;
|
---|
90 | LONG lReturnCode;
|
---|
91 | FOURCC fccIOProc;
|
---|
92 |
|
---|
93 | #if 0
|
---|
94 | CHAR szBuffer[ sizeof( FOURCC ) + MAX_FILENAME_SIZE + 4 ];
|
---|
95 | LONG lNumIOProcs;
|
---|
96 | MMFORMATINFO mmFormatInfo;
|
---|
97 | PMMFORMATINFO pmmFormatInfoArray;
|
---|
98 | PSZ pszFourccString;
|
---|
99 | ULONG ulReturnCode;
|
---|
100 | LONG lFormatsRead;
|
---|
101 | LONG index;
|
---|
102 | LONG lBytesRead;
|
---|
103 | #endif
|
---|
104 |
|
---|
105 | printf("in Main\n");
|
---|
106 | ulReturnCode = mmioIdentifyFile ( pszFileName,
|
---|
107 | 0L,
|
---|
108 | &mmFormatInfo,
|
---|
109 | &fccStorageSystem,
|
---|
110 | 0L,
|
---|
111 | 0L);
|
---|
112 |
|
---|
113 | /*
|
---|
114 | * If this file was NOT identified, then this function won't
|
---|
115 | * work, so return an error by indicating an empty bitmap.
|
---|
116 | */
|
---|
117 |
|
---|
118 | if ( ulReturnCode == MMIO_ERROR )
|
---|
119 | {
|
---|
120 | printf("Can't identify file...\n");
|
---|
121 | return (0L);
|
---|
122 | }
|
---|
123 |
|
---|
124 | /*
|
---|
125 | * If mmioIdentifyFile did not find a custom-written IO proc which
|
---|
126 | * can understand the image file, then it will return the DOS IO Proc
|
---|
127 | * info because the image file IS a DOS file.
|
---|
128 | */
|
---|
129 |
|
---|
130 | if( mmFormatInfo.fccIOProc == FOURCC_DOS )
|
---|
131 | {
|
---|
132 |
|
---|
133 | printf("Image file could not be interpreted by any permanently or temporarily installed IO procedures.\n");
|
---|
134 | return ( 0L );
|
---|
135 | }
|
---|
136 |
|
---|
137 | /*
|
---|
138 | * Ensure this is an IMAGE IOproc, and that it can read
|
---|
139 | * translated data
|
---|
140 | */
|
---|
141 |
|
---|
142 | if ( (mmFormatInfo.ulMediaType != MMIO_MEDIATYPE_IMAGE) ||
|
---|
143 | ((mmFormatInfo.ulFlags & MMIO_CANREADTRANSLATED) == 0) )
|
---|
144 | {
|
---|
145 | printf("No IMAGE IO Procedures exist which can translate the data in the image file specified.");
|
---|
146 | return (0L);
|
---|
147 | }
|
---|
148 | else
|
---|
149 | {
|
---|
150 | fccIOProc = mmFormatInfo.fccIOProc;
|
---|
151 | }
|
---|
152 |
|
---|
153 | /* Clear out and initialize mminfo structure */
|
---|
154 |
|
---|
155 | memset ( &mmioinfo,
|
---|
156 | 0L,
|
---|
157 | sizeof ( MMIOINFO ) );
|
---|
158 |
|
---|
159 | mmioinfo.fccIOProc = fccIOProc;
|
---|
160 | mmioinfo.ulTranslate = MMIO_TRANSLATEHEADER | MMIO_TRANSLATEDATA;
|
---|
161 |
|
---|
162 | hmmio = mmioOpen ( (PSZ) pszFileName,
|
---|
163 | &mmioinfo,
|
---|
164 | MMIO_READ | MMIO_DENYWRITE | MMIO_NOIDENTIFY );
|
---|
165 |
|
---|
166 | if ( ! hmmio )
|
---|
167 | {
|
---|
168 | /* If file could not be opened, return with error */
|
---|
169 | printf("File can't be opened!\n");
|
---|
170 | return (0L);
|
---|
171 | }
|
---|
172 |
|
---|
173 | dwReturnCode = mmioQueryHeaderLength ( hmmio,
|
---|
174 | (PLONG)&ulImageHeaderLength,
|
---|
175 | 0L,
|
---|
176 | 0L);
|
---|
177 |
|
---|
178 | if ( ulImageHeaderLength != sizeof ( MMIMAGEHEADER ) )
|
---|
179 | {
|
---|
180 | /* We have a problem.....possibly incompatible versions */
|
---|
181 | printf("Error in mmioQueryHeaderLength ()\n");
|
---|
182 | ulReturnCode = mmioClose (hmmio, 0L);
|
---|
183 | return (0L);
|
---|
184 | }
|
---|
185 |
|
---|
186 | ulReturnCode = mmioGetHeader ( hmmio,
|
---|
187 | &mmImgHdr,
|
---|
188 | (LONG) sizeof ( MMIMAGEHEADER ),
|
---|
189 | (PLONG)&ulBytesRead,
|
---|
190 | 0L,
|
---|
191 | 0L);
|
---|
192 |
|
---|
193 | if ( ulReturnCode != MMIO_SUCCESS )
|
---|
194 | {
|
---|
195 | /* Header unavailable */
|
---|
196 | printf("Can't get header!\n");
|
---|
197 | ulReturnCode = mmioClose (hmmio, 0L);
|
---|
198 |
|
---|
199 | return (0L);
|
---|
200 | }
|
---|
201 |
|
---|
202 | /*
|
---|
203 | * Determine the number of bytes required, per row.
|
---|
204 | * PLANES MUST ALWAYS BE = 1
|
---|
205 | */
|
---|
206 |
|
---|
207 | dwHeight = mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cy;
|
---|
208 | dwWidth = mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cx;
|
---|
209 | wBitCount = mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cBitCount;
|
---|
210 | dwRowBits = dwWidth * mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cBitCount;
|
---|
211 | dwNumRowBytes = dwRowBits >> 3;
|
---|
212 |
|
---|
213 | /*
|
---|
214 | * Account for odd bits used in 1bpp or 4bpp images that are
|
---|
215 | * NOT on byte boundaries.
|
---|
216 | */
|
---|
217 |
|
---|
218 | if ( dwRowBits % 8 )
|
---|
219 | {
|
---|
220 | dwNumRowBytes++;
|
---|
221 | }
|
---|
222 |
|
---|
223 | /*
|
---|
224 | * Ensure the row length in bytes accounts for byte padding.
|
---|
225 | * All bitmap data rows must are aligned on LONG/4-BYTE boundaries.
|
---|
226 | * The data FROM an IOProc should always appear in this form.
|
---|
227 | */
|
---|
228 |
|
---|
229 | dwPadBytes = ( dwNumRowBytes % 4 );
|
---|
230 |
|
---|
231 | if ( dwPadBytes )
|
---|
232 | {
|
---|
233 | dwNumRowBytes += 4 - dwPadBytes;
|
---|
234 | }
|
---|
235 |
|
---|
236 | /* Allocate space for ONE row of pels */
|
---|
237 |
|
---|
238 | if ( DosAllocMem( (PPVOID)&pRowBuffer,
|
---|
239 | (ULONG)dwNumRowBytes,
|
---|
240 | fALLOC))
|
---|
241 | {
|
---|
242 | ulReturnCode = mmioClose (hmmio, 0L);
|
---|
243 |
|
---|
244 | printf("No memory!!\n");
|
---|
245 | return(0L);
|
---|
246 | }
|
---|
247 |
|
---|
248 |
|
---|
249 | printf("Done\n");
|
---|
250 | return 0;
|
---|
251 | }
|
---|
252 |
|
---|
253 |
|
---|
254 |
|
---|
255 |
|
---|
256 |
|
---|