1 | /*
|
---|
2 | * imgconv.c (C) Chris Wohlgemuth 2002-2003
|
---|
3 | *
|
---|
4 | * This helper converts image files. It is called by the image classes
|
---|
5 | * when the 'convert' menu is chosen.
|
---|
6 | */
|
---|
7 | /*
|
---|
8 | * This program is free software; you can redistribute it and/or modify
|
---|
9 | * it under the terms of the GNU General Public License as published by
|
---|
10 | * the Free Software Foundation; either version 2, or (at your option)
|
---|
11 | * any later version.
|
---|
12 | *
|
---|
13 | * This program is distributed in the hope that it will be useful,
|
---|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
16 | * GNU General Public License for more details.
|
---|
17 | *
|
---|
18 | * You should have received a copy of the GNU General Public License
|
---|
19 | * along with this program; see the file COPYING. If not, write to
|
---|
20 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
21 | */
|
---|
22 | /*
|
---|
23 | * If you need another license for your project/product (commercial,
|
---|
24 | * noncommercial, whatever) contact me at
|
---|
25 | *
|
---|
26 | * http://www.os2world.com/cdwriting
|
---|
27 | * http://www.geocities.com/SiliconValley/Sector/5785/
|
---|
28 | *
|
---|
29 | */
|
---|
30 | #define INCL_DOS
|
---|
31 | #define INCL_DOSFILEMGR
|
---|
32 | #define INCL_DOSERRORS
|
---|
33 | #define INCL_WIN
|
---|
34 | #define INCL_OS2MM
|
---|
35 | #define INCL_MMIOOS2
|
---|
36 | #define INCL_GPI
|
---|
37 | #define INCL_PM
|
---|
38 |
|
---|
39 | #define USE_OS2_TOOLKIT_HEADERS
|
---|
40 | #include <os2.h>
|
---|
41 |
|
---|
42 | #include <sys\types.h>
|
---|
43 | #include <sys\stat.h>
|
---|
44 | #include <stdio.h>
|
---|
45 | #include <stdlib.h>
|
---|
46 | #include <string.h>
|
---|
47 | #include "os2me.h"
|
---|
48 | #include "mmioos2.h"
|
---|
49 | #include <mmio.h>
|
---|
50 | #include "common.h"
|
---|
51 | #include "mmres.h"
|
---|
52 | #include "mmprogs_defaults.h"
|
---|
53 |
|
---|
54 | #include "sys_funcs.h"
|
---|
55 |
|
---|
56 | #ifndef MMIOM_QUERYIMAGE
|
---|
57 | #define MMIOM_QUERYIMAGE MMIOM_START + 39
|
---|
58 | #define MMIOM_QUERYIMAGECOUNT MMIOM_START + 40
|
---|
59 | #define MMIOM_SETIMAGE MMIOM_START + 41
|
---|
60 | #endif
|
---|
61 |
|
---|
62 | #define MSG_CONVERTDONE 1L
|
---|
63 | #define MSG_CONVERTPERCENT 2L
|
---|
64 | #define MSG_CONVERTERROR 3L
|
---|
65 |
|
---|
66 | #define ID_TIMER 1
|
---|
67 | #define TIMER_DELAY 200
|
---|
68 |
|
---|
69 | #define CONVERTBUFFERSIZE 500000
|
---|
70 | #define NUMPARAMS 3
|
---|
71 |
|
---|
72 | /* argv[0]: progname
|
---|
73 | * argv[1]: imgfile
|
---|
74 | * argv[2]: IO proc name
|
---|
75 | */
|
---|
76 |
|
---|
77 | //#define DEBUG
|
---|
78 |
|
---|
79 | void HlpSendCommandToObject(char* chrObject, char* command);
|
---|
80 | BOOL percentRegisterBarClass(void);
|
---|
81 | BOOL IniSaveWindowPos(char * iniFile, char* chrApp, char *chrKey, HWND hwnd);
|
---|
82 | BOOL IniRestoreWindowPos(char * iniFile, char* chrApp, char *chrKey, HWND hwnd);
|
---|
83 | BOOL IniSaveWindowClrs(char * chrIniFile, char* chrApp , HWND hwnd);
|
---|
84 | BOOL IniRestoreWindowClrs(char * chrIniFile, char* chrApp , HWND hwnd);
|
---|
85 | BOOL HlpBuildMMProgIniFileName(char* chrProgname, char * chrBuffer, ULONG ulBufferSize);
|
---|
86 | HMODULE queryResModuleHandle(char *chrExePath);
|
---|
87 | void freeResHandle(void);
|
---|
88 | BOOL getMessage(char* text,ULONG ulID, LONG lSizeText, HMODULE hResource,HWND hwnd);
|
---|
89 | ULONG messageBox( char* text, ULONG ulTextID , LONG lSizeText,
|
---|
90 | char* title, ULONG ulTitleID, LONG lSizeTitle,
|
---|
91 | HMODULE hResource, HWND hwnd, ULONG ulFlags);
|
---|
92 |
|
---|
93 | char logName[]="convert.log";
|
---|
94 |
|
---|
95 | extern SWP swpWindow;
|
---|
96 | BOOL bHaveWindowPos=FALSE;
|
---|
97 |
|
---|
98 | char chrTargetName[CCHMAXPATH]={0};
|
---|
99 | char chrSourceName[CCHMAXPATH]={0};
|
---|
100 | char chrProcName[CCHMAXPATH]={0};
|
---|
101 | char chrIniFile[CCHMAXPATH];
|
---|
102 |
|
---|
103 | int numArgs;
|
---|
104 | char* params[NUMPARAMS];
|
---|
105 |
|
---|
106 | #define NUMIOPROCS 1000
|
---|
107 | int iIoProc; /* Position of IO-Proc in global data area of MMOS2. 0 based */
|
---|
108 | int iPrivIOProc[NUMIOPROCS]; /* Number of possible IO-Procs. I'm lazy here and use a static array.
|
---|
109 | If there ever will be more than 1000 procs there'll be a problem... */
|
---|
110 |
|
---|
111 |
|
---|
112 | TID tidThread=0;
|
---|
113 | BOOL bBreak=FALSE;
|
---|
114 | PMMFORMATINFO pMemFormatInfo=NULLHANDLE;
|
---|
115 | HMODULE RESSOURCEHANDLE=0;
|
---|
116 | BOOL bNoProcGiven=FALSE;
|
---|
117 | HAB globalHab;
|
---|
118 | /* BMP info for preview */
|
---|
119 | BITMAPINFOHEADER2 bmpInfoHeader2;
|
---|
120 | HBITMAP hBitmap;
|
---|
121 |
|
---|
122 | void pmUsage(void);
|
---|
123 |
|
---|
124 | //#define DEBUG
|
---|
125 |
|
---|
126 | #ifdef DEBUG
|
---|
127 | void HlpWriteToTrapLog(const char* chrFormat, ...);
|
---|
128 | #endif
|
---|
129 |
|
---|
130 | /*
|
---|
131 | Load an image file using IO-Procs
|
---|
132 | */
|
---|
133 | HBITMAP loadBitmap ( PSZ pszFileName, PBITMAPINFOHEADER2 pBMPInfoHeader2)
|
---|
134 | {
|
---|
135 | HBITMAP hbm;
|
---|
136 | MMIOINFO mmioinfo;
|
---|
137 | MMFORMATINFO mmFormatInfo;
|
---|
138 | HMMIO hmmio;
|
---|
139 | ULONG ulImageHeaderLength;
|
---|
140 | MMIMAGEHEADER mmImgHdr;
|
---|
141 | ULONG ulBytesRead;
|
---|
142 | ULONG dwNumRowBytes;
|
---|
143 | PBYTE pRowBuffer;
|
---|
144 | ULONG dwRowCount;
|
---|
145 | SIZEL ImageSize;
|
---|
146 | ULONG dwHeight, dwWidth;
|
---|
147 | FOURCC fccStorageSystem;
|
---|
148 | ULONG dwPadBytes;
|
---|
149 | ULONG dwRowBits;
|
---|
150 | ULONG ulReturnCode;
|
---|
151 | FOURCC fccIOProc;
|
---|
152 | HDC hdc;
|
---|
153 | HPS hps;
|
---|
154 |
|
---|
155 |
|
---|
156 | ulReturnCode = mmioIdentifyFile ( pszFileName,
|
---|
157 | 0L,
|
---|
158 | &mmFormatInfo,
|
---|
159 | &fccStorageSystem,
|
---|
160 | 0L,
|
---|
161 | 0L);
|
---|
162 | /*
|
---|
163 | * If this file was NOT identified, then this function won't
|
---|
164 | * work, so return an error by indicating an empty bitmap.
|
---|
165 | */
|
---|
166 | if ( ulReturnCode == MMIO_ERROR )
|
---|
167 | {
|
---|
168 | // showMsgBox(IDSTR_CWIMAGETITLE, IDSTR_NOIMGIOPROCERROR, queryModuleHandle());
|
---|
169 | return (0L);
|
---|
170 | }
|
---|
171 |
|
---|
172 | /*
|
---|
173 | * If mmioIdentifyFile did not find a custom-written IO proc which
|
---|
174 | * can understand the image file, then it will return the DOS IO Proc
|
---|
175 | * info because the image file IS a DOS file.
|
---|
176 | */
|
---|
177 | if( mmFormatInfo.fccIOProc == FOURCC_DOS )
|
---|
178 | {
|
---|
179 | // showMsgBox(IDSTR_CWIMAGETITLE, IDSTR_NOIMGIOPROCERROR, queryModuleHandle());
|
---|
180 | return ( 0L );
|
---|
181 | }
|
---|
182 | /*
|
---|
183 | * Ensure this is an IMAGE IOproc, and that it can read
|
---|
184 | * translated data
|
---|
185 | */
|
---|
186 | if ( (mmFormatInfo.ulMediaType != MMIO_MEDIATYPE_IMAGE) ||
|
---|
187 | ((mmFormatInfo.ulFlags & MMIO_CANREADTRANSLATED) == 0) )
|
---|
188 | {
|
---|
189 | // showMsgBox(IDSTR_CWIMAGETITLE, IDSTR_NOIMGIOPROCERROR, queryModuleHandle());
|
---|
190 | return (0L);
|
---|
191 | }
|
---|
192 | else
|
---|
193 | {
|
---|
194 | fccIOProc = mmFormatInfo.fccIOProc;
|
---|
195 | }
|
---|
196 |
|
---|
197 | /* Clear out and initialize mminfo structure */
|
---|
198 | memset ( &mmioinfo, 0L, sizeof ( MMIOINFO ) );
|
---|
199 | mmioinfo.fccIOProc = fccIOProc;
|
---|
200 | mmioinfo.ulTranslate = MMIO_TRANSLATEHEADER | MMIO_TRANSLATEDATA;
|
---|
201 | hmmio = mmioOpen ( (PSZ) pszFileName,
|
---|
202 | &mmioinfo,
|
---|
203 | MMIO_READ | MMIO_DENYWRITE | MMIO_NOIDENTIFY );
|
---|
204 | if ( ! hmmio )
|
---|
205 | {
|
---|
206 | // If file could not be opened, return with error
|
---|
207 | // showMsgBox(IDSTR_CWIMAGETITLE, IDSTR_OPENFILEERROR, queryModuleHandle());
|
---|
208 | return (0L);
|
---|
209 | }
|
---|
210 |
|
---|
211 |
|
---|
212 | ulReturnCode = mmioQueryHeaderLength ( hmmio,
|
---|
213 | (PLONG)&ulImageHeaderLength,
|
---|
214 | 0L,
|
---|
215 | 0L);
|
---|
216 | if ( ulImageHeaderLength != sizeof ( MMIMAGEHEADER ) )
|
---|
217 | {
|
---|
218 | /* We have a problem.....possibly incompatible versions */
|
---|
219 | ulReturnCode = mmioClose (hmmio, 0L);
|
---|
220 | // showMsgBox(IDSTR_CWIMAGETITLE, IDSTR_NOIMGIOPROCERROR);
|
---|
221 | return (0L);
|
---|
222 | }
|
---|
223 |
|
---|
224 | ulReturnCode = mmioGetHeader ( hmmio,
|
---|
225 | &mmImgHdr,
|
---|
226 | (LONG) sizeof ( MMIMAGEHEADER ),
|
---|
227 | (PLONG)&ulBytesRead,
|
---|
228 | 0L,
|
---|
229 | 0L);
|
---|
230 |
|
---|
231 | if ( ulReturnCode != MMIO_SUCCESS )
|
---|
232 | {
|
---|
233 | /* Header unavailable */
|
---|
234 | ulReturnCode = mmioClose (hmmio, 0L);
|
---|
235 | return (0L);
|
---|
236 | }
|
---|
237 |
|
---|
238 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
---|
239 | *pBMPInfoHeader2=mmImgHdr.mmXDIBHeader.BMPInfoHeader2;
|
---|
240 |
|
---|
241 | /*
|
---|
242 | * Determine the number of bytes required, per row.
|
---|
243 | * PLANES MUST ALWAYS BE = 1
|
---|
244 | */
|
---|
245 | dwHeight = mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cy;
|
---|
246 | dwWidth = mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cx;
|
---|
247 | dwRowBits = dwWidth * mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cBitCount;
|
---|
248 | dwNumRowBytes = dwRowBits >> 3;
|
---|
249 |
|
---|
250 | /*
|
---|
251 | * Account for odd bits used in 1bpp or 4bpp images that are
|
---|
252 | * NOT on byte boundaries.
|
---|
253 | */
|
---|
254 | if ( dwRowBits % 8 )
|
---|
255 | {
|
---|
256 | dwNumRowBytes++;
|
---|
257 | }
|
---|
258 | /*
|
---|
259 | * Ensure the row length in bytes accounts for byte padding.
|
---|
260 | * All bitmap data rows must are aligned on LONG/4-BYTE boundaries.
|
---|
261 | * The data FROM an IOProc should always appear in this form.
|
---|
262 | */
|
---|
263 | dwPadBytes = ( dwNumRowBytes % 4 );
|
---|
264 | if ( dwPadBytes )
|
---|
265 | {
|
---|
266 | dwNumRowBytes += 4 - dwPadBytes;
|
---|
267 | }
|
---|
268 |
|
---|
269 | /* Allocate space for ONE row of pels */
|
---|
270 | if ( DosAllocMem( (PPVOID)&pRowBuffer,
|
---|
271 | (ULONG)dwNumRowBytes,
|
---|
272 | fALLOC))
|
---|
273 | {
|
---|
274 | ulReturnCode = mmioClose (hmmio, 0L);
|
---|
275 | // showMsgBox(IDSTR_CWIMAGETITLE, IDSTR_NOMEMERROR, queryModuleHandle());
|
---|
276 | return(0L);
|
---|
277 | }
|
---|
278 |
|
---|
279 | /* Create a device context */
|
---|
280 | hdc=DevOpenDC(globalHab, OD_MEMORY,"*",0L, NULL, NULLHANDLE);
|
---|
281 | if(hdc==NULLHANDLE)
|
---|
282 | {
|
---|
283 | DosFreeMem(pRowBuffer);
|
---|
284 | mmioClose (hmmio, 0L);
|
---|
285 | return(0L);
|
---|
286 | }
|
---|
287 |
|
---|
288 |
|
---|
289 | // ***************************************************
|
---|
290 | // Create a memory presentation space that includes
|
---|
291 | // the memory device context obtained above.
|
---|
292 | // ***************************************************
|
---|
293 |
|
---|
294 | ImageSize.cx = dwWidth;
|
---|
295 | ImageSize.cy = dwHeight;
|
---|
296 |
|
---|
297 | hps = GpiCreatePS ( globalHab,
|
---|
298 | hdc,
|
---|
299 | &ImageSize,
|
---|
300 | PU_PELS | GPIT_NORMAL | GPIA_ASSOC );
|
---|
301 | // PU_PELS | GPIF_DEFAULT | GPIT_MICRO | GPIA_ASSOC );
|
---|
302 | if ( !hps )
|
---|
303 | {
|
---|
304 | #ifdef DEBUG
|
---|
305 | WinMessageBox( HWND_DESKTOP, HWND_DESKTOP,
|
---|
306 | "No HPS...",
|
---|
307 | "Open Image File",
|
---|
308 | (HMODULE) NULL,
|
---|
309 | (ULONG) MB_OK | MB_MOVEABLE |
|
---|
310 | MB_ERROR );
|
---|
311 | #endif
|
---|
312 | DevCloseDC(hdc);
|
---|
313 | DosFreeMem(pRowBuffer);
|
---|
314 | mmioClose (hmmio, 0L);
|
---|
315 | return(0L);
|
---|
316 | }
|
---|
317 |
|
---|
318 | // GpiSelectPalette(hps, NULLHANDLE);
|
---|
319 | // ***************************************************
|
---|
320 | // Create an uninitialized bitmap. This is where we
|
---|
321 | // will put all of the bits once we read them in.
|
---|
322 | // ***************************************************
|
---|
323 | hbm = GpiCreateBitmap ( hps,
|
---|
324 | pBMPInfoHeader2,
|
---|
325 | 0L,
|
---|
326 | NULL,
|
---|
327 | NULL);
|
---|
328 |
|
---|
329 | if ( !hbm )
|
---|
330 | {
|
---|
331 | #ifdef DEBUG
|
---|
332 | WinMessageBox( HWND_DESKTOP, HWND_DESKTOP,
|
---|
333 | "No HBITMAP...",
|
---|
334 | "Open Image File",
|
---|
335 | (HMODULE) NULL,
|
---|
336 | (ULONG) MB_OK | MB_MOVEABLE |
|
---|
337 | MB_ERROR );
|
---|
338 | #endif
|
---|
339 | GpiDestroyPS(hps);
|
---|
340 | DevCloseDC(hdc);
|
---|
341 | DosFreeMem(pRowBuffer);
|
---|
342 | ulReturnCode = mmioClose (hmmio, 0L);
|
---|
343 | return(0L);
|
---|
344 | }
|
---|
345 |
|
---|
346 | // ***************************************************
|
---|
347 | // Select the bitmap into the memory device context.
|
---|
348 | // ***************************************************
|
---|
349 | ulReturnCode = GpiSetBitmap ( hps,
|
---|
350 | hbm );
|
---|
351 |
|
---|
352 | //***************************************************************
|
---|
353 | // LOAD THE BITMAP DATA FROM THE FILE
|
---|
354 | // One line at a time, starting from the BOTTOM
|
---|
355 | //*************************************************************** */
|
---|
356 |
|
---|
357 | for ( dwRowCount = 0; dwRowCount < dwHeight; dwRowCount++ )
|
---|
358 | {
|
---|
359 | ulBytesRead = (ULONG) mmioRead ( hmmio,
|
---|
360 | pRowBuffer,
|
---|
361 | dwNumRowBytes );
|
---|
362 | if ( !ulBytesRead )
|
---|
363 | {
|
---|
364 | break;
|
---|
365 | }
|
---|
366 | /*
|
---|
367 | * Allow context switching while previewing.. Couldn't get
|
---|
368 | * it to work. Perhaps will get to it when time is available...
|
---|
369 | */
|
---|
370 | ulReturnCode = GpiSetBitmapBits ( hps,
|
---|
371 | (LONG) dwRowCount,
|
---|
372 | (LONG) 1,
|
---|
373 | (PBYTE) pRowBuffer,
|
---|
374 | (PBITMAPINFO2) pBMPInfoHeader2);
|
---|
375 | }
|
---|
376 |
|
---|
377 | /* Clean up */
|
---|
378 | ulReturnCode = GpiSetBitmap ( hps,
|
---|
379 | NULLHANDLE );
|
---|
380 | ulReturnCode = mmioClose (hmmio, 0L);
|
---|
381 | DosFreeMem(pRowBuffer);
|
---|
382 | GpiDestroyPS(hps);
|
---|
383 | DevCloseDC(hdc);
|
---|
384 |
|
---|
385 | return(hbm);
|
---|
386 | }
|
---|
387 |
|
---|
388 |
|
---|
389 | /*
|
---|
390 | Create a BMP of another size from an already loaded BMP.
|
---|
391 | */
|
---|
392 | HBITMAP createNewBitmap ( HBITMAP hbm,
|
---|
393 | PBITMAPINFOHEADER2 pBmpInfoHeader2,
|
---|
394 | HWND hwnd)
|
---|
395 | // ULONG ulWidth,
|
---|
396 | // ULONG ulHeight)
|
---|
397 | {
|
---|
398 | HBITMAP hbmTarget;
|
---|
399 | SIZEL ImageSize;
|
---|
400 | HDC hdc;
|
---|
401 | HPS hps;
|
---|
402 | BITMAPINFOHEADER2 bmpih2;
|
---|
403 | POINTL aptl[4];
|
---|
404 | ULONG ulWidth, ulHeight;
|
---|
405 | SWP swp;
|
---|
406 |
|
---|
407 | /*
|
---|
408 | * Get position of image frame
|
---|
409 | */
|
---|
410 | WinQueryWindowPos ( hwnd, &swp);
|
---|
411 |
|
---|
412 | /* Image size */
|
---|
413 |
|
---|
414 | ulHeight = bmpInfoHeader2.cy;
|
---|
415 | ulWidth = bmpInfoHeader2.cx;
|
---|
416 |
|
---|
417 | if(ulWidth <=swp.cx && ulHeight <= swp.cy)
|
---|
418 | {
|
---|
419 | aptl[0].x=0;
|
---|
420 | aptl[1].x=aptl[0].x+ulWidth;
|
---|
421 |
|
---|
422 | aptl[0].y=0;
|
---|
423 | aptl[1].y=aptl[0].y+ulHeight;
|
---|
424 | }
|
---|
425 | else {
|
---|
426 | float fWidth, fHeight, fRes;
|
---|
427 |
|
---|
428 | fWidth=(float)swp.cx/(float)ulWidth;
|
---|
429 | fHeight=(float)swp.cy/(float)ulHeight;
|
---|
430 | fRes=( fWidth>fHeight ? fHeight : fWidth);
|
---|
431 |
|
---|
432 |
|
---|
433 | aptl[0].x=0;
|
---|
434 | aptl[1].x=aptl[0].x+ulWidth*fRes;
|
---|
435 |
|
---|
436 | aptl[0].y=0;
|
---|
437 | aptl[1].y=aptl[0].y+ulHeight*fRes;
|
---|
438 | }
|
---|
439 |
|
---|
440 | aptl[2].x = 0; // source lower left
|
---|
441 | aptl[2].y = 0;
|
---|
442 |
|
---|
443 | aptl[3].x = ulWidth; // source upper right
|
---|
444 | aptl[3].y = ulHeight;
|
---|
445 |
|
---|
446 | #if 0
|
---|
447 | sprintf(text, "BMP: %d %d, Window: %d %d , new: %d %d", ulWidth, ulHeight, swp.cx, swp.cy,
|
---|
448 | aptl[1].x-aptl[0].x, aptl[1].y-aptl[0].y);
|
---|
449 | WinMessageBox( HWND_DESKTOP, HWND_DESKTOP,
|
---|
450 | text,
|
---|
451 | "Create new bitmap",
|
---|
452 | (HMODULE) NULL,
|
---|
453 | (ULONG) MB_OK | MB_MOVEABLE |
|
---|
454 | MB_ERROR );
|
---|
455 | #endif
|
---|
456 |
|
---|
457 | if(!ulWidth || !ulHeight)
|
---|
458 | return 0L;
|
---|
459 |
|
---|
460 | /* Create a device context */
|
---|
461 | hdc=DevOpenDC(globalHab, OD_MEMORY,"*",0L, NULL, NULLHANDLE);
|
---|
462 | if(hdc==NULLHANDLE)
|
---|
463 | {
|
---|
464 | return(0L);
|
---|
465 | }
|
---|
466 |
|
---|
467 | // ***************************************************
|
---|
468 | // Create a memory presentation space that includes
|
---|
469 | // the memory device context obtained above.
|
---|
470 | // ***************************************************
|
---|
471 | ImageSize.cx = ulWidth;
|
---|
472 | ImageSize.cy = ulHeight;
|
---|
473 | hps = GpiCreatePS ( globalHab,
|
---|
474 | hdc,
|
---|
475 | &ImageSize,
|
---|
476 | PU_PELS | GPIT_NORMAL | GPIA_ASSOC );
|
---|
477 | if ( !hps )
|
---|
478 | {
|
---|
479 | DevCloseDC(hdc);
|
---|
480 | return(0L);
|
---|
481 | }
|
---|
482 |
|
---|
483 | /* Now scale the bitmap */
|
---|
484 | memcpy(&bmpih2, pBmpInfoHeader2, sizeof(BITMAPINFOHEADER2));
|
---|
485 |
|
---|
486 | bmpih2.cx=aptl[1].x-aptl[0].x;
|
---|
487 | bmpih2.cy=aptl[1].y-aptl[0].y;
|
---|
488 |
|
---|
489 | bmpih2.cbImage=(((ulWidth*(1<<bmpih2.cPlanes)*(1<<bmpih2.cBitCount))+31) /32)*ulHeight;
|
---|
490 | // ***************************************************
|
---|
491 | // Create an uninitialized bitmap. This is where we
|
---|
492 | // ***************************************************
|
---|
493 |
|
---|
494 | hbmTarget = GpiCreateBitmap ( hps,
|
---|
495 | &bmpih2,
|
---|
496 | 0L,
|
---|
497 | NULL,
|
---|
498 | NULL);
|
---|
499 | if ( !hbmTarget )
|
---|
500 | {
|
---|
501 | GpiDestroyPS(hps);
|
---|
502 | DevCloseDC(hdc);
|
---|
503 | return(0L);
|
---|
504 | }
|
---|
505 |
|
---|
506 | /* Blit it */
|
---|
507 | GpiSetBitmap ( hps, hbmTarget );
|
---|
508 |
|
---|
509 | GpiWCBitBlt(hps, hbm,4L, aptl, ROP_SRCCOPY, BBO_IGNORE);
|
---|
510 |
|
---|
511 | GpiSetBitmap( hps, NULLHANDLE );
|
---|
512 | GpiDestroyPS(hps);
|
---|
513 | DevCloseDC(hdc);
|
---|
514 | pBmpInfoHeader2->cbFix=sizeof(BITMAPINFOHEADER2);
|
---|
515 | GpiQueryBitmapInfoHeader(hbmTarget, pBmpInfoHeader2);
|
---|
516 |
|
---|
517 | #if 0
|
---|
518 | sprintf(text, "BMP: %d %d, Window: %d %d , new: %d %d", ulWidth, ulHeight, swp.cx, swp.cy,
|
---|
519 | pBmpInfoHeader2->cx, pBmpInfoHeader2->cy);
|
---|
520 | WinMessageBox( HWND_DESKTOP, HWND_DESKTOP,
|
---|
521 | text,
|
---|
522 | "Create new bitmap",
|
---|
523 | (HMODULE) NULL,
|
---|
524 | (ULONG) MB_OK | MB_MOVEABLE |
|
---|
525 | MB_ERROR );
|
---|
526 | #endif
|
---|
527 | return(hbmTarget);
|
---|
528 | }
|
---|
529 |
|
---|
530 |
|
---|
531 |
|
---|
532 | BOOL createTargetName(char *sourceName, char *chrExt)
|
---|
533 | {
|
---|
534 | char *textPtr;
|
---|
535 |
|
---|
536 | strcpy(chrTargetName, sourceName);
|
---|
537 | if((textPtr=strrchr(chrTargetName, '.'))!=NULLHANDLE)
|
---|
538 | *textPtr=0;
|
---|
539 | else
|
---|
540 | textPtr=chrTargetName;
|
---|
541 | strcat(textPtr,".");
|
---|
542 | strcat(textPtr, chrExt);
|
---|
543 |
|
---|
544 | return TRUE;
|
---|
545 | }
|
---|
546 |
|
---|
547 |
|
---|
548 | BOOL insertIOProcItems( HWND hwndDrop )
|
---|
549 | {
|
---|
550 | // CHAR szBuffer[ sizeof( FOURCC ) + CCHMAXPATH + 4 ];
|
---|
551 | MMFORMATINFO mmFormatInfo;
|
---|
552 | PMMFORMATINFO pmmFormatInfoArray;
|
---|
553 | ULONG ulReturnCode;
|
---|
554 | LONG lFormatsRead;
|
---|
555 | LONG index;
|
---|
556 | LONG lBytesRead;
|
---|
557 | LONG lNumIOProcs;
|
---|
558 | int sIdx;
|
---|
559 | memset( &mmFormatInfo,
|
---|
560 | '\0',
|
---|
561 | sizeof(MMFORMATINFO) );
|
---|
562 |
|
---|
563 | mmFormatInfo.ulMediaType |= MMIO_MEDIATYPE_IMAGE;
|
---|
564 | mmFormatInfo.ulFlags|=MMIO_CANWRITETRANSLATED;
|
---|
565 | ulReturnCode = mmioQueryFormatCount ( &mmFormatInfo,
|
---|
566 | &lNumIOProcs,
|
---|
567 | 0,
|
---|
568 | 0 );
|
---|
569 |
|
---|
570 | if( ulReturnCode != MMIO_SUCCESS )
|
---|
571 | {
|
---|
572 | /*
|
---|
573 | * Error - mmioQueryFormatCount failed.
|
---|
574 | */
|
---|
575 | return FALSE;
|
---|
576 | }
|
---|
577 |
|
---|
578 | /*
|
---|
579 | * Allocate enough memory for n number of FormatInfo blocks
|
---|
580 | */
|
---|
581 | pmmFormatInfoArray = (PMMFORMATINFO) malloc (lNumIOProcs * sizeof( MMFORMATINFO ) );
|
---|
582 | pMemFormatInfo=pmmFormatInfoArray;
|
---|
583 | if( pmmFormatInfoArray == NULL )
|
---|
584 | {
|
---|
585 | /*
|
---|
586 | * Could not allocate enough memory for mmFormatInfo array.
|
---|
587 | */
|
---|
588 | return FALSE;
|
---|
589 | }
|
---|
590 |
|
---|
591 | /*
|
---|
592 | * call mmioGetFormats to get info on the formats supported.
|
---|
593 | */
|
---|
594 | ulReturnCode = mmioGetFormats( &mmFormatInfo,
|
---|
595 | lNumIOProcs,
|
---|
596 | pmmFormatInfoArray,
|
---|
597 | &lFormatsRead,
|
---|
598 | 0,
|
---|
599 | 0 );
|
---|
600 | if( ulReturnCode != MMIO_SUCCESS )
|
---|
601 | {
|
---|
602 | /*
|
---|
603 | * mmioGetFormats failed.
|
---|
604 | */
|
---|
605 | free(pmmFormatInfoArray);
|
---|
606 | return FALSE;
|
---|
607 | }
|
---|
608 |
|
---|
609 | if( lFormatsRead != lNumIOProcs )
|
---|
610 | {
|
---|
611 | /*
|
---|
612 | * Error in MMIO - number of formats read in by
|
---|
613 | * mmioGetFormats is not equal to number of formats
|
---|
614 | * found by mmioQueryFormatCount.
|
---|
615 | */
|
---|
616 | free(pmmFormatInfoArray);
|
---|
617 | return FALSE;
|
---|
618 | }
|
---|
619 |
|
---|
620 |
|
---|
621 | for ( index = 0, sIdx=0; index <lNumIOProcs; index++ )
|
---|
622 | {
|
---|
623 | char szName[CCHMAXPATH];
|
---|
624 |
|
---|
625 | mmioGetFormatName(pmmFormatInfoArray, szName, &lBytesRead, 0L, 0L);
|
---|
626 | /* Insert NULL string terminator */
|
---|
627 | *( szName + lBytesRead ) = 0;
|
---|
628 |
|
---|
629 |
|
---|
630 | /* Compressed TIF is not supported because the Warp 4 IO-Procs are
|
---|
631 | broken. */
|
---|
632 | if(pmmFormatInfoArray->fccIOProc!=mmioStringToFOURCC("TFMC",MMIO_TOUPPER) &&
|
---|
633 | pmmFormatInfoArray->fccIOProc!=mmioStringToFOURCC("TFIC",MMIO_TOUPPER) &&
|
---|
634 | (pmmFormatInfoArray->ulFlags & MMIO_CANWRITETRANSLATED))
|
---|
635 | {
|
---|
636 | /* Insert into list box */
|
---|
637 | WinSendMsg(hwndDrop, LM_INSERTITEM,(MPARAM)LIT_END,
|
---|
638 | (MPARAM)szName);
|
---|
639 |
|
---|
640 | #ifdef DEBUG
|
---|
641 | HlpWriteToTrapLog("------ %d private idx: %d, IO-Proc: %s %s\n", index, sIdx,
|
---|
642 | pmmFormatInfoArray->szDefaultFormatExt,
|
---|
643 | szName);
|
---|
644 | #endif
|
---|
645 |
|
---|
646 | iPrivIOProc[sIdx]=index;
|
---|
647 |
|
---|
648 | /* Set text field */
|
---|
649 | if(bNoProcGiven) {
|
---|
650 | WinSetWindowText(hwndDrop, szName);
|
---|
651 | createTargetName(chrSourceName, pmmFormatInfoArray->szDefaultFormatExt);
|
---|
652 | iIoProc=iPrivIOProc[sIdx];
|
---|
653 | bNoProcGiven=FALSE;
|
---|
654 | }
|
---|
655 | else {
|
---|
656 | if(!stricmp(szName, chrProcName)) {
|
---|
657 | WinSetWindowText(hwndDrop, szName);
|
---|
658 | /* Create target name */
|
---|
659 | createTargetName(chrSourceName, pmmFormatInfoArray->szDefaultFormatExt);
|
---|
660 | iIoProc=iPrivIOProc[sIdx];
|
---|
661 | }
|
---|
662 | }
|
---|
663 | sIdx++;
|
---|
664 | }
|
---|
665 | /*
|
---|
666 | * advance to next entry in mmFormatInfo array
|
---|
667 | */
|
---|
668 | pmmFormatInfoArray++;
|
---|
669 | }
|
---|
670 | return TRUE;
|
---|
671 | }
|
---|
672 |
|
---|
673 | BOOL DoConvert(HWND hwnd,
|
---|
674 | PSZ pszSource, // Source file name
|
---|
675 | PSZ pszTarget,
|
---|
676 | FOURCC fccTargetIOProc) //
|
---|
677 | {
|
---|
678 | MMIOINFO mmioinfoSource;
|
---|
679 | MMIOINFO mmioinfoTarget;
|
---|
680 | HMMIO hmmioSource;
|
---|
681 | HMMIO hmmioTarget;
|
---|
682 | ULONG ulImageHeaderLength;
|
---|
683 | MMIMAGEHEADER mmImgHdr;
|
---|
684 | ULONG ulBytesRead;
|
---|
685 | ULONG dwNumRowBytes;
|
---|
686 | PBYTE pRowBuffer;
|
---|
687 | ULONG dwRowCount;
|
---|
688 | ULONG dwWidth;
|
---|
689 | ULONG dwHeight;
|
---|
690 | ULONG dwPadBytes;
|
---|
691 | ULONG dwRowBits;
|
---|
692 | LONG rc;
|
---|
693 | LONG rcSrcQueryCount = 0;
|
---|
694 | LONG rcTrgQueryCount = 0;
|
---|
695 | LONG rcTrgSetImage = 0;
|
---|
696 | ULONG iIndex, iCount, iCount2;
|
---|
697 |
|
---|
698 | MMFORMATINFO mmFormatInfo;
|
---|
699 | FOURCC fccSourceIOProc;
|
---|
700 | FOURCC fccStorageSystem;
|
---|
701 |
|
---|
702 | rc = mmioIdentifyFile ( pszSource,
|
---|
703 | 0L,
|
---|
704 | &mmFormatInfo,
|
---|
705 | &fccStorageSystem,
|
---|
706 | 0L,
|
---|
707 | 0L);
|
---|
708 |
|
---|
709 | /*
|
---|
710 | * If this file was NOT identified, then this function won't
|
---|
711 | * work, so return an error by indicating an empty bitmap.
|
---|
712 | */
|
---|
713 |
|
---|
714 | if ( rc == MMIO_ERROR )
|
---|
715 | {
|
---|
716 | return (0L);
|
---|
717 | }
|
---|
718 | fccSourceIOProc=mmFormatInfo.fccIOProc;
|
---|
719 |
|
---|
720 | /*******************************/
|
---|
721 | /* Set up/open the SOURCE file */
|
---|
722 | /*******************************/
|
---|
723 | memset (&mmioinfoSource, 0L, sizeof (MMIOINFO));
|
---|
724 | mmioinfoSource.fccIOProc = fccSourceIOProc;
|
---|
725 | mmioinfoSource.ulTranslate = MMIO_TRANSLATEHEADER | MMIO_TRANSLATEDATA;
|
---|
726 |
|
---|
727 | hmmioSource = mmioOpen ((PSZ)pszSource, &mmioinfoSource,
|
---|
728 | MMIO_READ | MMIO_DENYWRITE
|
---|
729 | | MMIO_NOIDENTIFY);
|
---|
730 |
|
---|
731 | if (!hmmioSource)
|
---|
732 | return (FALSE);
|
---|
733 |
|
---|
734 | /*******************************/
|
---|
735 | /* Set up/open the TARGET file */
|
---|
736 | /*******************************/
|
---|
737 |
|
---|
738 | memset (&mmioinfoTarget, 0L, sizeof (MMIOINFO));
|
---|
739 | mmioinfoTarget.fccIOProc = fccTargetIOProc;
|
---|
740 | mmioinfoTarget.ulTranslate = MMIO_TRANSLATEHEADER | MMIO_TRANSLATEDATA;
|
---|
741 |
|
---|
742 | hmmioTarget = mmioOpen ((PSZ)pszTarget,
|
---|
743 | &mmioinfoTarget,
|
---|
744 | MMIO_CREATE | MMIO_WRITE |
|
---|
745 | MMIO_DENYWRITE | MMIO_NOIDENTIFY);
|
---|
746 |
|
---|
747 | if (!hmmioTarget)
|
---|
748 | {
|
---|
749 | mmioClose (hmmioSource, 0L);
|
---|
750 | return (FALSE);
|
---|
751 | }
|
---|
752 |
|
---|
753 | #ifdef DEBUG
|
---|
754 | HlpWriteToTrapLog("Target opened.\n");
|
---|
755 | #endif
|
---|
756 |
|
---|
757 | // find out if source has multiple image support
|
---|
758 | rcSrcQueryCount = mmioSendMessage(hmmioSource, MMIOM_QUERYIMAGECOUNT, (LONG)&iCount, (LONG)0);
|
---|
759 | if (rcSrcQueryCount) iCount = 1;
|
---|
760 |
|
---|
761 | // find out if the target has multiple image support
|
---|
762 | rcTrgQueryCount = mmioSendMessage(hmmioTarget, MMIOM_QUERYIMAGECOUNT, (LONG)&iCount2, (LONG)0);
|
---|
763 |
|
---|
764 | for (iIndex=0; iIndex<iCount; iIndex++) { /* loop through known images */
|
---|
765 |
|
---|
766 | if (!rcSrcQueryCount && !rcTrgQueryCount) { /* if Both support images */
|
---|
767 |
|
---|
768 | /* Determine if the target can write arrays, and if not */
|
---|
769 | /* then write the the default image from the source */
|
---|
770 |
|
---|
771 | if (rcTrgSetImage && iIndex > 0) break; /* Target Can't Write array */
|
---|
772 |
|
---|
773 | /* Now, determine if the target can write arrays */
|
---|
774 | rcTrgSetImage = mmioSendMessage (hmmioTarget, MMIOM_SETIMAGE, (LONG)iIndex, (LONG)0);
|
---|
775 |
|
---|
776 | if (!rcTrgSetImage) mmioSendMessage (hmmioSource, MMIOM_SETIMAGE, (LONG)iIndex, (LONG)0);
|
---|
777 |
|
---|
778 | } else if (!rcSrcQueryCount) { /* Source does but target doesn't */
|
---|
779 | /* Use the default image from source to copy to target */
|
---|
780 | /* so do set the index of the first, let it default */
|
---|
781 | /* get the base photo cd image (2 of 5) */
|
---|
782 | if (iIndex > 0) break;
|
---|
783 | } else if (!rcTrgQueryCount) { /* Target does but source doesn't */
|
---|
784 | /* Use the only image to do a default write to target */
|
---|
785 | } else {
|
---|
786 | /* neither do: just write one image from here to there */
|
---|
787 | }
|
---|
788 |
|
---|
789 | /****************************/
|
---|
790 | /* Obtain the SOURCE HEADER */
|
---|
791 | /****************************/
|
---|
792 | mmioQueryHeaderLength (hmmioSource, (PLONG)&ulImageHeaderLength, 0L, 0L);
|
---|
793 | if (ulImageHeaderLength != sizeof (MMIMAGEHEADER))
|
---|
794 | /* We have a problem.....possibly incompatible versions */
|
---|
795 | {
|
---|
796 | mmioClose (hmmioSource, 0L);
|
---|
797 | mmioClose (hmmioTarget, 0L);
|
---|
798 | return (FALSE);
|
---|
799 | }
|
---|
800 |
|
---|
801 | rc = (LONG)mmioGetHeader (hmmioSource, &mmImgHdr,
|
---|
802 | (LONG)sizeof (MMIMAGEHEADER), (PLONG)&ulBytesRead,
|
---|
803 | 0L, 0L);
|
---|
804 |
|
---|
805 | if (rc != MMIO_SUCCESS)
|
---|
806 | /* Header unavailable */
|
---|
807 | {
|
---|
808 | mmioClose (hmmioSource, 0L);
|
---|
809 | mmioClose (hmmioTarget, 0L);
|
---|
810 | return (FALSE);
|
---|
811 | }
|
---|
812 |
|
---|
813 |
|
---|
814 | /*************************/
|
---|
815 | /* Set the TARGET HEADER */
|
---|
816 | /*************************/
|
---|
817 | mmioQueryHeaderLength (hmmioTarget, (PLONG)&ulImageHeaderLength, 0L, 0L);
|
---|
818 | if (ulImageHeaderLength != sizeof (MMIMAGEHEADER))
|
---|
819 | {
|
---|
820 | /* We have a problem.....possibly incompatible versions */
|
---|
821 | mmioClose (hmmioSource, 0L);
|
---|
822 | mmioClose (hmmioTarget, 0L);
|
---|
823 | return (FALSE);
|
---|
824 | }
|
---|
825 |
|
---|
826 |
|
---|
827 | /* Use the SAME data as came from the SOURCE FILE. It must be
|
---|
828 | compatible with the OS/2 bitmaps, etc. */
|
---|
829 | rc = (LONG)mmioSetHeader (hmmioTarget, &mmImgHdr,
|
---|
830 | (LONG)sizeof (MMIMAGEHEADER), (PLONG)&ulBytesRead,
|
---|
831 | 0L, 0L);
|
---|
832 |
|
---|
833 | if (rc != MMIO_SUCCESS)
|
---|
834 | /* Header unavailable */
|
---|
835 | {
|
---|
836 | mmioClose (hmmioSource, 0L);
|
---|
837 | mmioClose (hmmioTarget, 0L);
|
---|
838 | return (FALSE);
|
---|
839 | }
|
---|
840 |
|
---|
841 | #ifdef DEBUG
|
---|
842 | HlpWriteToTrapLog("Target header set.\n");
|
---|
843 | #endif
|
---|
844 |
|
---|
845 | /* Determine the number of bytes required, per row */
|
---|
846 | /* PLANES MUST ALWAYS BE = 1 */
|
---|
847 | dwHeight = mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cy;
|
---|
848 | dwWidth = mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cx;
|
---|
849 | dwRowBits = dwWidth * mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cBitCount;
|
---|
850 | dwNumRowBytes = dwRowBits >> 3;
|
---|
851 |
|
---|
852 | /* Account for odd bits used in 1bpp or 4bpp images that are NOT on byte boundaries. */
|
---|
853 | if (dwRowBits % 8)
|
---|
854 | dwNumRowBytes++;
|
---|
855 |
|
---|
856 | /* Ensure the row length in bytes accounts for byte padding. All bitmap data rows
|
---|
857 | must are aligned on LONG/4-BYTE boundaries. The data FROM an IOProc
|
---|
858 | should always appear in this form. */
|
---|
859 | dwPadBytes = (dwNumRowBytes % 4);
|
---|
860 | if (dwPadBytes)
|
---|
861 | dwNumRowBytes += 4 - dwPadBytes;
|
---|
862 |
|
---|
863 | /* Allocate space for one row */
|
---|
864 | if (DosAllocMem((PVOID)&pRowBuffer, (ULONG)dwNumRowBytes, fALLOC))
|
---|
865 | {
|
---|
866 | mmioClose (hmmioSource, 0L);
|
---|
867 | mmioClose (hmmioTarget, 0L);
|
---|
868 | return(FALSE);
|
---|
869 | }
|
---|
870 |
|
---|
871 | for (dwRowCount = 0;
|
---|
872 | dwRowCount < dwHeight;
|
---|
873 | dwRowCount++)
|
---|
874 | {
|
---|
875 | ulBytesRead = (ULONG)mmioRead (hmmioSource, pRowBuffer, dwNumRowBytes);
|
---|
876 |
|
---|
877 | if (ulBytesRead) {
|
---|
878 | mmioWrite (hmmioTarget, pRowBuffer, (ULONG)ulBytesRead);
|
---|
879 | #ifdef DEBUG
|
---|
880 | HlpWriteToTrapLog("ulBytesRead: %d, lWritten: %d.\n", ulBytesRead, lWritten);
|
---|
881 | #endif
|
---|
882 |
|
---|
883 | }
|
---|
884 | else
|
---|
885 | break;
|
---|
886 |
|
---|
887 | if(dwHeight)
|
---|
888 | WinPostMsg(hwnd, WM_APPTERMINATENOTIFY, MPFROMLONG(MSG_CONVERTPERCENT), MPFROMLONG(dwRowCount*100/dwHeight));
|
---|
889 | }
|
---|
890 | }
|
---|
891 | WinPostMsg(hwnd, WM_APPTERMINATENOTIFY, MPFROMLONG(MSG_CONVERTPERCENT), MPFROMLONG(100));
|
---|
892 | mmioClose (hmmioTarget, 0L);
|
---|
893 | mmioClose (hmmioSource, 0L);
|
---|
894 | DosFreeMem(pRowBuffer);
|
---|
895 |
|
---|
896 | return(TRUE);
|
---|
897 | }
|
---|
898 |
|
---|
899 | void convertThreadFunc (void *arg)
|
---|
900 | {
|
---|
901 | HAB hab;
|
---|
902 | HMQ hmq;
|
---|
903 | HWND hwnd=(HWND)arg;
|
---|
904 |
|
---|
905 | hab=WinInitialize(0);
|
---|
906 | if(hab) {
|
---|
907 | hmq=WinCreateMsgQueue(hab,0);
|
---|
908 | if(hmq) {
|
---|
909 |
|
---|
910 | DoConvert(hwnd,
|
---|
911 | chrSourceName,
|
---|
912 | chrTargetName, pMemFormatInfo[iIoProc].fccIOProc);
|
---|
913 |
|
---|
914 |
|
---|
915 |
|
---|
916 | WinPostMsg(hwnd, WM_APPTERMINATENOTIFY, MPFROMLONG(MSG_CONVERTDONE), 0);
|
---|
917 | DosSleep(1000);
|
---|
918 | WinDestroyMsgQueue(hmq);
|
---|
919 | }
|
---|
920 | WinTerminate(hab);
|
---|
921 | }
|
---|
922 | tidThread=0;
|
---|
923 | bBreak=FALSE;
|
---|
924 | }
|
---|
925 |
|
---|
926 | /* Start the convert thread. hwnd is the HWND of our main dialog */
|
---|
927 | void convertImageFile(HWND hwnd)
|
---|
928 | {
|
---|
929 | tidThread=_beginthread(convertThreadFunc,NULL, 65535*32, (void*)hwnd); //Fehlerbehandlung fehlt
|
---|
930 | if(tidThread==-1) {
|
---|
931 | DosBeep(100, 500);
|
---|
932 | tidThread=0;
|
---|
933 | }
|
---|
934 | }
|
---|
935 |
|
---|
936 | VOID DrawBitmap ( HWND hwnd )
|
---|
937 | {
|
---|
938 | SWP swp;
|
---|
939 | POINTL aptl[4];
|
---|
940 | HPS hps;
|
---|
941 | ULONG ulHeight;
|
---|
942 | ULONG ulWidth;
|
---|
943 |
|
---|
944 | hps = WinBeginPaint ( hwnd,
|
---|
945 | 0,
|
---|
946 | NULL);
|
---|
947 | /*
|
---|
948 | * Get position of image frame
|
---|
949 | */
|
---|
950 | WinQueryWindowPos ( hwnd, &swp);
|
---|
951 |
|
---|
952 | /* Center image */
|
---|
953 | ulHeight = bmpInfoHeader2.cy;
|
---|
954 | ulWidth = bmpInfoHeader2.cx;
|
---|
955 | if(ulWidth <=swp.cx && ulHeight <= swp.cy)
|
---|
956 | {
|
---|
957 | aptl[0].x=(swp.cx-ulWidth)/2;
|
---|
958 | aptl[1].x=aptl[0].x+ulWidth;
|
---|
959 |
|
---|
960 | aptl[0].y=(swp.cy-ulHeight)/2;
|
---|
961 | aptl[1].y=aptl[0].y+ulHeight;
|
---|
962 | }
|
---|
963 | else {
|
---|
964 | float fWidth, fHeight, fRes;
|
---|
965 |
|
---|
966 | fWidth=(float)swp.cx/(float)ulWidth;
|
---|
967 | fHeight=(float)swp.cy/(float)ulHeight;
|
---|
968 | fRes=( fWidth>fHeight ? fHeight : fWidth);
|
---|
969 |
|
---|
970 |
|
---|
971 | aptl[0].x=(swp.cx-ulWidth*fRes)/2;
|
---|
972 | aptl[1].x=aptl[0].x+ulWidth*fRes;
|
---|
973 |
|
---|
974 | aptl[0].y=(swp.cy-ulHeight*fRes)/2;
|
---|
975 | aptl[1].y=aptl[0].y+ulHeight*fRes;
|
---|
976 | }
|
---|
977 |
|
---|
978 | aptl[2].x = 0; // source lower left
|
---|
979 | aptl[2].y = 0;
|
---|
980 |
|
---|
981 | aptl[3].x = ulWidth; // source upper right
|
---|
982 | aptl[3].y = ulHeight;
|
---|
983 |
|
---|
984 | /*
|
---|
985 | * Call GpiBitBlt and supply 4 aptl structures. This tells
|
---|
986 | * it to stretch or compress the bitmap depending on what is
|
---|
987 | * in the aptl structures. See above lines for their current
|
---|
988 | * settings.
|
---|
989 | */
|
---|
990 |
|
---|
991 | WinDrawBitmap(hps, hBitmap, NULLHANDLE, (PPOINTL)aptl, 0, 0, DBM_NORMAL|DBM_STRETCH);
|
---|
992 |
|
---|
993 | #if 0
|
---|
994 | aptl[0].x=0;
|
---|
995 | aptl[0].y=0;
|
---|
996 | //aptl[1].x=100;
|
---|
997 | //aptl[1].y=100;
|
---|
998 | // WinDrawBitmap(hps, hBitmap, NULLHANDLE, (PPOINTL)aptl, 0, 0, DBM_NORMAL/*|DBM_STRETCH*/);
|
---|
999 | #endif
|
---|
1000 | WinEndPaint (hps);
|
---|
1001 | }
|
---|
1002 |
|
---|
1003 | MRESULT EXPENTRY bmpPreviewProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
|
---|
1004 | {
|
---|
1005 |
|
---|
1006 | switch (msg)
|
---|
1007 | {
|
---|
1008 | case WM_PAINT:
|
---|
1009 | {
|
---|
1010 | if (!WinIsWindowVisible(hwnd))
|
---|
1011 | {
|
---|
1012 | return((MRESULT)NULL);
|
---|
1013 | }
|
---|
1014 | DrawBitmap(hwnd);
|
---|
1015 | return MRTRUE;
|
---|
1016 | }
|
---|
1017 | default:
|
---|
1018 | break;
|
---|
1019 | }
|
---|
1020 | return WinDefWindowProc( hwnd, msg, mp1, mp2);
|
---|
1021 | }
|
---|
1022 | /* This Proc handles the on-the-fly data CD writing */
|
---|
1023 | MRESULT EXPENTRY decodeStatusDialogProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
|
---|
1024 | {
|
---|
1025 | char text[CCHMAXPATH*4 +10];
|
---|
1026 | // char title[CCHMAXPATH*4];
|
---|
1027 | SWCNTRL swctl;
|
---|
1028 | PID pid;
|
---|
1029 | int iPercent;
|
---|
1030 |
|
---|
1031 | switch (msg)
|
---|
1032 | {
|
---|
1033 | case WM_INITDLG:
|
---|
1034 | #if 0
|
---|
1035 | sprintf(text,"1: %s, 2: %s, 3: %s 4: %s 5: %s 6: %s",params[1],params[2],params[3],
|
---|
1036 | params[4], params[4],params[4]);
|
---|
1037 | WinMessageBox( HWND_DESKTOP, HWND_DESKTOP, text,
|
---|
1038 | params[4],
|
---|
1039 | 0UL, MB_OK | MB_ICONEXCLAMATION|MB_MOVEABLE );
|
---|
1040 | #endif
|
---|
1041 |
|
---|
1042 | WinSendMsg(WinWindowFromID(hwnd,IDST_IMGCONVERTNAME),EM_SETTEXTLIMIT,MPFROMSHORT((SHORT)CCHMAXPATH),0);
|
---|
1043 |
|
---|
1044 | /* Filename */
|
---|
1045 | WinSetWindowText(WinWindowFromID(hwnd,IDST_IMGCONVERTNAME), chrSourceName);
|
---|
1046 |
|
---|
1047 | /* Set dialog font to WarpSans for Warp 4 and above */
|
---|
1048 | if(SysQueryOSRelease()>=40) {
|
---|
1049 | WinSetPresParam(hwnd,
|
---|
1050 | PP_FONTNAMESIZE,(ULONG)sizeof(DEFAULT_DIALOG_FONT),
|
---|
1051 | DEFAULT_DIALOG_FONT );
|
---|
1052 | }
|
---|
1053 |
|
---|
1054 | /* Subclass preview area */
|
---|
1055 | WinSubclassWindow(WinWindowFromID(hwnd, IDSR_BMP), bmpPreviewProc);
|
---|
1056 |
|
---|
1057 | /* Create a small BMP */
|
---|
1058 | if(hBitmap) {
|
---|
1059 | HBITMAP hBitmapTemp;
|
---|
1060 |
|
---|
1061 | hBitmapTemp=createNewBitmap ( hBitmap, &bmpInfoHeader2, WinWindowFromID(hwnd, IDSR_BMP));
|
---|
1062 | GpiDeleteBitmap(hBitmap);
|
---|
1063 | hBitmap=hBitmapTemp;
|
---|
1064 | }
|
---|
1065 |
|
---|
1066 | /* Set percent bars to 0. */
|
---|
1067 | WinSetWindowText(WinWindowFromID(hwnd,IDBAR_IMGCONVERTPROGRESS),"0#0%");
|
---|
1068 | WinSendMsg(WinWindowFromID(hwnd,IDEF_IMGCONVERTTARGETNAME), EM_SETTEXTLIMIT,
|
---|
1069 | MPFROMSHORT((SHORT)CCHMAXPATH),0);
|
---|
1070 | WinEnableWindow( WinWindowFromID(hwnd,IDPB_IMGCONVERTABORT), FALSE);
|
---|
1071 |
|
---|
1072 | insertIOProcItems( WinWindowFromID(hwnd, IDDD_IMGIOPROC) );
|
---|
1073 |
|
---|
1074 | WinSetWindowText( WinWindowFromID(hwnd,IDEF_IMGCONVERTTARGETNAME), chrTargetName );
|
---|
1075 |
|
---|
1076 | IniRestoreWindowPos(chrIniFile, INI_IMGCONV_APP, INI_WINDOWPOS_KEY, hwnd);
|
---|
1077 | IniRestoreWindowClrs(chrIniFile, INI_IMGCONV_APP , hwnd);
|
---|
1078 |
|
---|
1079 | /* Add switch entry */
|
---|
1080 | memset(&swctl,0,sizeof(swctl));
|
---|
1081 | WinQueryWindowProcess(hwnd,&pid,NULL);
|
---|
1082 | swctl.hwnd=hwnd;
|
---|
1083 | swctl.uchVisibility=SWL_VISIBLE;
|
---|
1084 | swctl.idProcess=pid;
|
---|
1085 | swctl.bProgType=PROG_DEFAULT;
|
---|
1086 | swctl.fbJump=SWL_JUMPABLE;
|
---|
1087 | WinAddSwitchEntry(&swctl);
|
---|
1088 |
|
---|
1089 | WinSetFocus(HWND_DESKTOP, hwnd);
|
---|
1090 |
|
---|
1091 | return (MRESULT) TRUE;
|
---|
1092 | /* WM_APPTERMINATENOTIFY messages are sent from the helper programs e.g. format checker. */
|
---|
1093 | case WM_APPTERMINATENOTIFY:
|
---|
1094 | switch(LONGFROMMP(mp1))
|
---|
1095 | {
|
---|
1096 | case MSG_CONVERTERROR:
|
---|
1097 | case MSG_CONVERTDONE:
|
---|
1098 | WinEnableWindow( WinWindowFromID(hwnd,IDPB_IMGCONVERTOK), TRUE);
|
---|
1099 | WinEnableWindow( WinWindowFromID(hwnd,IDPB_IMGCONVERTABORT), FALSE);
|
---|
1100 | break;
|
---|
1101 | case MSG_CONVERTPERCENT:
|
---|
1102 | iPercent=LONGFROMMP(mp2);
|
---|
1103 | if(iPercent>100)
|
---|
1104 | iPercent=100;
|
---|
1105 | if(iPercent<0)
|
---|
1106 | iPercent=0;
|
---|
1107 |
|
---|
1108 | /* Update track percent bar value. The helper prog sends us the actual decoded %. */
|
---|
1109 | sprintf(text,"%d#%d%%", iPercent, iPercent);
|
---|
1110 | WinSetWindowText(WinWindowFromID(hwnd,IDBAR_IMGCONVERTPROGRESS), text);
|
---|
1111 | break;
|
---|
1112 | default:
|
---|
1113 | break;
|
---|
1114 | }
|
---|
1115 | return FALSE;
|
---|
1116 | case WM_CLOSE:
|
---|
1117 | if(tidThread) {
|
---|
1118 | bBreak=TRUE;
|
---|
1119 | if(!WinStartTimer(WinQueryAnchorBlock(hwnd), hwnd, ID_TIMER, TIMER_DELAY))
|
---|
1120 | {
|
---|
1121 | /* Save window position */
|
---|
1122 | IniSaveWindowPos(chrIniFile, INI_IMGCONV_APP, INI_WINDOWPOS_KEY, hwnd);
|
---|
1123 | IniSaveWindowClrs(chrIniFile, INI_IMGCONV_APP , hwnd);
|
---|
1124 | WinDismissDlg(hwnd,0);
|
---|
1125 | }
|
---|
1126 | else
|
---|
1127 | return FALSE;
|
---|
1128 | }
|
---|
1129 | /* Save window position */
|
---|
1130 | IniSaveWindowPos(chrIniFile, INI_IMGCONV_APP, INI_WINDOWPOS_KEY, hwnd);
|
---|
1131 | IniSaveWindowClrs(chrIniFile, INI_IMGCONV_APP , hwnd);
|
---|
1132 | WinDismissDlg(hwnd,0);
|
---|
1133 | return FALSE;
|
---|
1134 | case WM_CONTROL:
|
---|
1135 | if(SHORT1FROMMP(mp1)==IDDD_IMGIOPROC)
|
---|
1136 | {
|
---|
1137 | if(SHORT2FROMMP(mp1)==EN_CHANGE) {
|
---|
1138 | SHORT sIdx;
|
---|
1139 |
|
---|
1140 | sIdx=SHORT1FROMMR(WinSendMsg(HWNDFROMMP(mp2),LM_QUERYSELECTION, MPFROMLONG(LIT_FIRST),0));
|
---|
1141 |
|
---|
1142 | iIoProc=iPrivIOProc[sIdx];
|
---|
1143 |
|
---|
1144 | createTargetName(chrSourceName, pMemFormatInfo[iIoProc].szDefaultFormatExt);
|
---|
1145 | WinSetWindowText( WinWindowFromID(hwnd,IDEF_IMGCONVERTTARGETNAME), chrTargetName );
|
---|
1146 | }
|
---|
1147 | }
|
---|
1148 | break;
|
---|
1149 | case WM_TIMER:
|
---|
1150 | if(SHORT1FROMMP(mp1)==ID_TIMER)
|
---|
1151 | {
|
---|
1152 | if(!tidThread) {
|
---|
1153 | /* Convert thread ended. Quit. */
|
---|
1154 | WinStopTimer(WinQueryAnchorBlock(hwnd), hwnd, ID_TIMER);
|
---|
1155 | WinPostMsg(hwnd, WM_CLOSE, 0, 0);
|
---|
1156 | }
|
---|
1157 | return MRFALSE;
|
---|
1158 | }
|
---|
1159 | break;
|
---|
1160 | case WM_COMMAND:
|
---|
1161 | switch(SHORT1FROMMP(mp1))
|
---|
1162 | {
|
---|
1163 | case IDPB_IMGCONVERTBROWSE:
|
---|
1164 | {
|
---|
1165 | char chrTitle[200];
|
---|
1166 | FILEDLG fd = { 0 };
|
---|
1167 | /* User pressed the browse button */
|
---|
1168 | fd.cbSize = sizeof( fd );
|
---|
1169 | /* It's an centered 'Open'-dialog */
|
---|
1170 | fd.fl = FDS_OPEN_DIALOG|FDS_CENTER;
|
---|
1171 | /* Title: "Search CDRecord/2" */
|
---|
1172 | // getMessage(text,IDSTR_FDLGSEARCHCDR2TITLE,sizeof(text), hSettingsResource,hwnd);
|
---|
1173 | /* Set the title of the file dialog */
|
---|
1174 | fd.pszTitle = chrTitle;
|
---|
1175 | if(!getMessage(chrTitle, IDSTR_IMAGEBROWSETITLE, sizeof(chrTitle), RESSOURCEHANDLE, hwnd))
|
---|
1176 | fd.pszTitle = "Image name";
|
---|
1177 | /* Only show * files */
|
---|
1178 | //sprintf(fd.szFullFile,"%s","*");
|
---|
1179 | strcpy(fd.szFullFile, chrTargetName);
|
---|
1180 | if( WinFileDlg( HWND_DESKTOP, hwnd, &fd ) == NULLHANDLE )
|
---|
1181 | {
|
---|
1182 | /* WinFileDlg failed */
|
---|
1183 | break;
|
---|
1184 | }
|
---|
1185 | if( fd.lReturn == DID_OK )
|
---|
1186 | {
|
---|
1187 | WinSetWindowText( WinWindowFromID(hwnd,IDEF_IMGCONVERTTARGETNAME), fd.szFullFile );
|
---|
1188 | }
|
---|
1189 | break;
|
---|
1190 | }
|
---|
1191 | case IDPB_IMGCONVERTCLOSE:
|
---|
1192 | bBreak=TRUE;
|
---|
1193 | if(!WinStartTimer(WinQueryAnchorBlock(hwnd), hwnd, ID_TIMER, TIMER_DELAY))
|
---|
1194 | WinPostMsg(hwnd, WM_CLOSE, 0, 0);/* Timer error so do a hard quit */
|
---|
1195 | break;
|
---|
1196 | case IDPB_IMGCONVERTABORT:
|
---|
1197 | bBreak=TRUE;
|
---|
1198 | WinEnableWindow( WinWindowFromID(hwnd,IDPB_IMGCONVERTABORT), FALSE);
|
---|
1199 | break;
|
---|
1200 | case IDPB_IMGCONVERTOK:
|
---|
1201 | {
|
---|
1202 | // FSALLOCATE fsAlloc;
|
---|
1203 | // long long lFreeSpace;
|
---|
1204 | // ULONG ulDiskNum;
|
---|
1205 | // char cLetter;
|
---|
1206 |
|
---|
1207 | /* Get target name */
|
---|
1208 | WinQueryWindowText( WinWindowFromID(hwnd,IDEF_IMGCONVERTTARGETNAME),
|
---|
1209 | sizeof(chrTargetName), chrTargetName );
|
---|
1210 | #if 0
|
---|
1211 | /* Check if diskspace is sufficient */
|
---|
1212 | cLetter=tolower(chrTargetName[0]);
|
---|
1213 | ulDiskNum=cLetter-'a'+1;
|
---|
1214 | if(DosQueryFSInfo(ulDiskNum, FSIL_ALLOC,&fsAlloc,sizeof(fsAlloc)))
|
---|
1215 | lFreeSpace=0;
|
---|
1216 | else
|
---|
1217 | lFreeSpace=fsAlloc.cUnitAvail*fsAlloc.cbSector*fsAlloc.cSectorUnit;
|
---|
1218 |
|
---|
1219 | if(lFreeSpace<lAudioSize) {
|
---|
1220 | /*
|
---|
1221 | Text:
|
---|
1222 | Title:
|
---|
1223 | */
|
---|
1224 | getMessage(title, IDSTR_CONVERTNOSPACETEXT,sizeof(title), RESSOURCEHANDLE, hwnd);
|
---|
1225 | sprintf(text,title,lAudioSize/1000000 );
|
---|
1226 | getMessage(title, IDSTR_CONVERTNOSPACETITLE,sizeof(title), RESSOURCEHANDLE, hwnd);
|
---|
1227 | WinMessageBox( HWND_DESKTOP, hwnd, text,
|
---|
1228 | title,
|
---|
1229 | 1234UL, MB_OK | MB_ICONEXCLAMATION|MB_MOVEABLE );
|
---|
1230 | }
|
---|
1231 | else {
|
---|
1232 | /* Start decoding an audio file */
|
---|
1233 | WinEnableWindow( WinWindowFromID(hwnd,IDPB_CONVERTOK), FALSE);
|
---|
1234 | WinEnableWindow( WinWindowFromID(hwnd,IDPB_CONVERTABORT), TRUE);
|
---|
1235 | convertAudioFile(hwnd);
|
---|
1236 | }
|
---|
1237 | #endif
|
---|
1238 | /* Start converting image file */
|
---|
1239 | WinPostMsg(hwnd, WM_APPTERMINATENOTIFY, MPFROMLONG(MSG_CONVERTPERCENT), MPFROMLONG(0));
|
---|
1240 | WinEnableWindow( WinWindowFromID(hwnd,IDPB_IMGCONVERTOK), FALSE);
|
---|
1241 | WinEnableWindow( WinWindowFromID(hwnd,IDPB_IMGCONVERTABORT), TRUE);
|
---|
1242 | convertImageFile(hwnd);
|
---|
1243 | break;
|
---|
1244 | }
|
---|
1245 | default:
|
---|
1246 | break;
|
---|
1247 | }
|
---|
1248 | return (MRESULT) FALSE;
|
---|
1249 | default:
|
---|
1250 | break;
|
---|
1251 | }/* switch */
|
---|
1252 |
|
---|
1253 | return WinDefDlgProc( hwnd, msg, mp1, mp2);
|
---|
1254 | }
|
---|
1255 |
|
---|
1256 | int main (int argc, char *argv[])
|
---|
1257 | {
|
---|
1258 | HAB hab;
|
---|
1259 | HMQ hmq;
|
---|
1260 | short a;
|
---|
1261 |
|
---|
1262 | /* Create a copy of the args */
|
---|
1263 | /* argv[0]: progname
|
---|
1264 | * argv[1]: imgfile
|
---|
1265 | * argv[2]: IO proc name
|
---|
1266 | */
|
---|
1267 |
|
---|
1268 | numArgs=argc;
|
---|
1269 |
|
---|
1270 | // sprintf(text,"");
|
---|
1271 | for(a=0;a<argc;a++)
|
---|
1272 | {
|
---|
1273 | params[a]=argv[a];
|
---|
1274 | }
|
---|
1275 |
|
---|
1276 | hab=WinInitialize(0);
|
---|
1277 | if(hab) {
|
---|
1278 | hmq=WinCreateMsgQueue(hab,0);
|
---|
1279 | if(hmq) {
|
---|
1280 | /* Check if user started prog by hand */
|
---|
1281 | if(argc<NUMPARAMS-1) {/* Not the right num of params */
|
---|
1282 | pmUsage();
|
---|
1283 | }
|
---|
1284 | else {
|
---|
1285 | /* Save source name */
|
---|
1286 | strcpy(chrSourceName,params[1]);
|
---|
1287 | if(argc==NUMPARAMS)
|
---|
1288 | strcpy(chrProcName,params[2]);
|
---|
1289 | else {
|
---|
1290 | bNoProcGiven=TRUE;
|
---|
1291 | strcpy(chrProcName, "");
|
---|
1292 | }
|
---|
1293 | /* Get our ressource dll */
|
---|
1294 | // RESSOURCEHANDLE=0;
|
---|
1295 | RESSOURCEHANDLE=queryResModuleHandle(argv[0]);
|
---|
1296 |
|
---|
1297 | HlpBuildMMProgIniFileName(argv[0], chrIniFile, sizeof(chrIniFile));
|
---|
1298 | /* Register the percent bar window class */
|
---|
1299 | percentRegisterBarClass();
|
---|
1300 |
|
---|
1301 | globalHab=WinQueryAnchorBlock(HWND_DESKTOP);
|
---|
1302 | hBitmap=loadBitmap ( chrSourceName, &bmpInfoHeader2);
|
---|
1303 |
|
---|
1304 | if( WinDlgBox( HWND_DESKTOP, NULLHANDLE, decodeStatusDialogProc,
|
---|
1305 | RESSOURCEHANDLE, IDDLG_IMGCONVERT, 0) == DID_ERROR )
|
---|
1306 | {
|
---|
1307 | char text[CCHMAXPATH];
|
---|
1308 | char title[CCHMAXPATH];
|
---|
1309 | /*
|
---|
1310 | Text:
|
---|
1311 | Title: "Installation problem"
|
---|
1312 | */
|
---|
1313 | messageBox( text, IDSTR_CONVERTDIALOGERROR , sizeof(text),
|
---|
1314 | title, IDSTR_INSTALLERRORTITLE , sizeof(title),
|
---|
1315 | RESSOURCEHANDLE, HWND_DESKTOP, MB_OK | MB_ICONEXCLAMATION | MB_MOVEABLE);
|
---|
1316 |
|
---|
1317 | if(hBitmap)
|
---|
1318 | GpiDeleteBitmap(hBitmap);
|
---|
1319 | freeResHandle();
|
---|
1320 | WinDestroyMsgQueue( hmq );
|
---|
1321 | WinTerminate( hab );
|
---|
1322 | DosBeep(100,600);
|
---|
1323 | return( 1 );
|
---|
1324 | }
|
---|
1325 | if(pMemFormatInfo)
|
---|
1326 | free(pMemFormatInfo);
|
---|
1327 | if(hBitmap)
|
---|
1328 | GpiDeleteBitmap(hBitmap);
|
---|
1329 | }
|
---|
1330 | freeResHandle();
|
---|
1331 | WinDestroyMsgQueue(hmq);
|
---|
1332 | }
|
---|
1333 | WinTerminate(hab);
|
---|
1334 | }
|
---|
1335 | return 0;
|
---|
1336 | }
|
---|