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