Changeset 104 for trunk/classes/mm-progs/imageconverter/imgconv.c
- Timestamp:
- Oct 2, 2023, 11:34:35 PM (23 months ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to
/branches/v2.9 merged eligible /branches/v2.9_Lars merged eligible
-
Property svn:mergeinfo
set to
-
trunk/classes/mm-progs/imageconverter/imgconv.c
r2 r104 23 23 * If you need another license for your project/product (commercial, 24 24 * noncommercial, whatever) contact me at 25 * 25 * 26 26 * http://www.os2world.com/cdwriting 27 27 * http://www.geocities.com/SiliconValley/Sector/5785/ … … 37 37 #define INCL_PM 38 38 39 #define USE_OS2_TOOLKIT_HEADERS 39 40 #include <os2.h> 40 41 … … 46 47 #include "os2me.h" 47 48 #include "mmioos2.h" 49 #include <mmio.h> 48 50 #include "common.h" 49 51 #include "mmres.h" … … 143 145 SIZEL ImageSize; 144 146 ULONG dwHeight, dwWidth; 145 SHORT wBitCount;146 147 FOURCC fccStorageSystem; 147 148 ULONG dwPadBytes; 148 149 ULONG dwRowBits; 149 150 ULONG ulReturnCode; 150 ULONG dwReturnCode;151 HBITMAP hbReturnCode;152 LONG lReturnCode;153 151 FOURCC fccIOProc; 154 152 HDC hdc; … … 212 210 213 211 214 dwReturnCode = mmioQueryHeaderLength ( hmmio,212 ulReturnCode = mmioQueryHeaderLength ( hmmio, 215 213 (PLONG)&ulImageHeaderLength, 216 214 0L, … … 247 245 dwHeight = mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cy; 248 246 dwWidth = mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cx; 249 wBitCount = mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cBitCount;250 247 dwRowBits = dwWidth * mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cBitCount; 251 248 dwNumRowBytes = dwRowBits >> 3; … … 288 285 return(0L); 289 286 } 290 287 291 288 292 289 // *************************************************** … … 294 291 // the memory device context obtained above. 295 292 // *************************************************** 296 293 297 294 ImageSize.cx = dwWidth; 298 295 ImageSize.cy = dwHeight; … … 312 309 (ULONG) MB_OK | MB_MOVEABLE | 313 310 MB_ERROR ); 314 #endif 311 #endif 315 312 DevCloseDC(hdc); 316 313 DosFreeMem(pRowBuffer); … … 350 347 // Select the bitmap into the memory device context. 351 348 // *************************************************** 352 hbReturnCode = GpiSetBitmap ( hps,349 ulReturnCode = GpiSetBitmap ( hps, 353 350 hbm ); 354 351 … … 371 368 * it to work. Perhaps will get to it when time is available... 372 369 */ 373 lReturnCode = GpiSetBitmapBits ( hps,370 ulReturnCode = GpiSetBitmapBits ( hps, 374 371 (LONG) dwRowCount, 375 372 (LONG) 1, … … 379 376 380 377 /* Clean up */ 381 hbReturnCode = GpiSetBitmap ( hps,378 ulReturnCode = GpiSetBitmap ( hps, 382 379 NULLHANDLE ); 383 380 ulReturnCode = mmioClose (hmmio, 0L); … … 396 393 PBITMAPINFOHEADER2 pBmpInfoHeader2, 397 394 HWND hwnd) 398 // ULONG ulWidth, 395 // ULONG ulWidth, 399 396 // ULONG ulHeight) 400 397 { 401 398 HBITMAP hbmTarget; 402 399 SIZEL ImageSize; 403 HBITMAP hbReturnCode;404 400 HDC hdc; 405 401 HPS hps; … … 413 409 */ 414 410 WinQueryWindowPos ( hwnd, &swp); 415 411 416 412 /* Image size */ 417 413 418 414 ulHeight = bmpInfoHeader2.cy; 419 415 ulWidth = bmpInfoHeader2.cx; … … 423 419 aptl[0].x=0; 424 420 aptl[1].x=aptl[0].x+ulWidth; 425 421 426 422 aptl[0].y=0; 427 423 aptl[1].y=aptl[0].y+ulHeight; … … 429 425 else { 430 426 float fWidth, fHeight, fRes; 431 427 432 428 fWidth=(float)swp.cx/(float)ulWidth; 433 429 fHeight=(float)swp.cy/(float)ulHeight; 434 430 fRes=( fWidth>fHeight ? fHeight : fWidth); 435 436 431 432 437 433 aptl[0].x=0; 438 434 aptl[1].x=aptl[0].x+ulWidth*fRes; 439 435 440 436 aptl[0].y=0; 441 437 aptl[1].y=aptl[0].y+ulHeight*fRes; 442 438 } 443 439 444 440 aptl[2].x = 0; // source lower left 445 441 aptl[2].y = 0; 446 442 447 443 aptl[3].x = ulWidth; // source upper right 448 444 aptl[3].y = ulHeight; … … 468 464 return(0L); 469 465 } 470 466 471 467 // *************************************************** 472 468 // Create a memory presentation space that includes … … 486 482 487 483 /* Now scale the bitmap */ 488 memcpy(&bmpih2, pBmpInfoHeader2, sizeof(BITMAPINFOHEADER2)); 484 memcpy(&bmpih2, pBmpInfoHeader2, sizeof(BITMAPINFOHEADER2)); 489 485 490 486 bmpih2.cx=aptl[1].x-aptl[0].x; … … 509 505 510 506 /* Blit it */ 511 hbReturnCode =GpiSetBitmap ( hps, hbmTarget );507 GpiSetBitmap ( hps, hbmTarget ); 512 508 513 509 GpiWCBitBlt(hps, hbm,4L, aptl, ROP_SRCCOPY, BBO_IGNORE); 514 510 515 hbReturnCode =GpiSetBitmap( hps, NULLHANDLE );511 GpiSetBitmap( hps, NULLHANDLE ); 516 512 GpiDestroyPS(hps); 517 513 DevCloseDC(hdc); … … 545 541 strcat(textPtr,"."); 546 542 strcat(textPtr, chrExt); 547 543 548 544 return TRUE; 549 545 } … … 564 560 '\0', 565 561 sizeof(MMFORMATINFO) ); 566 562 567 563 mmFormatInfo.ulMediaType |= MMIO_MEDIATYPE_IMAGE; 568 mmFormatInfo.ulFlags|=MMIO_CANWRITETRANSLATED; 564 mmFormatInfo.ulFlags|=MMIO_CANWRITETRANSLATED; 569 565 ulReturnCode = mmioQueryFormatCount ( &mmFormatInfo, 570 566 &lNumIOProcs, 571 567 0, 572 568 0 ); 573 569 574 570 if( ulReturnCode != MMIO_SUCCESS ) 575 571 { … … 592 588 return FALSE; 593 589 } 594 590 595 591 /* 596 592 * call mmioGetFormats to get info on the formats supported. … … 610 606 return FALSE; 611 607 } 612 608 613 609 if( lFormatsRead != lNumIOProcs ) 614 610 { … … 627 623 char szName[CCHMAXPATH]; 628 624 629 mmioGetFormatName(pmmFormatInfoArray, szName, &lBytesRead, 0L, 0L); 625 mmioGetFormatName(pmmFormatInfoArray, szName, &lBytesRead, 0L, 0L); 630 626 /* Insert NULL string terminator */ 631 *( szName + lBytesRead ) = (CHAR)NULL;627 *( szName + lBytesRead ) = 0; 632 628 633 629 … … 643 639 644 640 #ifdef DEBUG 645 HlpWriteToTrapLog("------ %d private idx: %d, IO-Proc: %s %s\n", index, sIdx, 641 HlpWriteToTrapLog("------ %d private idx: %d, IO-Proc: %s %s\n", index, sIdx, 646 642 pmmFormatInfoArray->szDefaultFormatExt, 647 643 szName); 648 644 #endif 649 645 650 646 iPrivIOProc[sIdx]=index; 651 647 … … 669 665 /* 670 666 * advance to next entry in mmFormatInfo array 671 */ 667 */ 672 668 pmmFormatInfoArray++; 673 669 } … … 700 696 ULONG iIndex, iCount, iCount2; 701 697 702 MMFORMATINFO mmFormatInfo; 698 MMFORMATINFO mmFormatInfo; 703 699 FOURCC fccSourceIOProc; 704 700 FOURCC fccStorageSystem; … … 728 724 mmioinfoSource.fccIOProc = fccSourceIOProc; 729 725 mmioinfoSource.ulTranslate = MMIO_TRANSLATEHEADER | MMIO_TRANSLATEDATA; 730 726 731 727 hmmioSource = mmioOpen ((PSZ)pszSource, &mmioinfoSource, 732 728 MMIO_READ | MMIO_DENYWRITE 733 729 | MMIO_NOIDENTIFY); 734 730 735 731 if (!hmmioSource) 736 732 return (FALSE); 737 733 738 734 /*******************************/ 739 735 /* Set up/open the TARGET file */ … … 743 739 mmioinfoTarget.fccIOProc = fccTargetIOProc; 744 740 mmioinfoTarget.ulTranslate = MMIO_TRANSLATEHEADER | MMIO_TRANSLATEDATA; 745 741 746 742 hmmioTarget = mmioOpen ((PSZ)pszTarget, 747 743 &mmioinfoTarget, 748 744 MMIO_CREATE | MMIO_WRITE | 749 745 MMIO_DENYWRITE | MMIO_NOIDENTIFY); 750 746 751 747 if (!hmmioTarget) 752 748 { … … 762 758 rcSrcQueryCount = mmioSendMessage(hmmioSource, MMIOM_QUERYIMAGECOUNT, (LONG)&iCount, (LONG)0); 763 759 if (rcSrcQueryCount) iCount = 1; 764 760 765 761 // find out if the target has multiple image support 766 762 rcTrgQueryCount = mmioSendMessage(hmmioTarget, MMIOM_QUERYIMAGECOUNT, (LONG)&iCount2, (LONG)0); 767 763 768 764 for (iIndex=0; iIndex<iCount; iIndex++) { /* loop through known images */ 769 765 770 766 if (!rcSrcQueryCount && !rcTrgQueryCount) { /* if Both support images */ 771 767 772 768 /* Determine if the target can write arrays, and if not */ 773 769 /* then write the the default image from the source */ 774 770 775 771 if (rcTrgSetImage && iIndex > 0) break; /* Target Can't Write array */ 776 772 777 773 /* Now, determine if the target can write arrays */ 778 774 rcTrgSetImage = mmioSendMessage (hmmioTarget, MMIOM_SETIMAGE, (LONG)iIndex, (LONG)0); 779 775 780 776 if (!rcTrgSetImage) mmioSendMessage (hmmioSource, MMIOM_SETIMAGE, (LONG)iIndex, (LONG)0); 781 777 782 778 } else if (!rcSrcQueryCount) { /* Source does but target doesn't */ 783 779 /* Use the default image from source to copy to target */ … … 806 802 (LONG)sizeof (MMIMAGEHEADER), (PLONG)&ulBytesRead, 807 803 0L, 0L); 808 804 809 805 if (rc != MMIO_SUCCESS) 810 806 /* Header unavailable */ … … 814 810 return (FALSE); 815 811 } 816 812 817 813 818 814 /*************************/ … … 828 824 } 829 825 830 826 831 827 /* Use the SAME data as came from the SOURCE FILE. It must be 832 828 compatible with the OS/2 bitmaps, etc. */ … … 834 830 (LONG)sizeof (MMIMAGEHEADER), (PLONG)&ulBytesRead, 835 831 0L, 0L); 836 832 837 833 if (rc != MMIO_SUCCESS) 838 834 /* Header unavailable */ … … 846 842 HlpWriteToTrapLog("Target header set.\n"); 847 843 #endif 848 844 849 845 /* Determine the number of bytes required, per row */ 850 846 /* PLANES MUST ALWAYS BE = 1 */ … … 853 849 dwRowBits = dwWidth * mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cBitCount; 854 850 dwNumRowBytes = dwRowBits >> 3; 855 851 856 852 /* Account for odd bits used in 1bpp or 4bpp images that are NOT on byte boundaries. */ 857 853 if (dwRowBits % 8) 858 854 dwNumRowBytes++; 859 855 860 856 /* Ensure the row length in bytes accounts for byte padding. All bitmap data rows 861 857 must are aligned on LONG/4-BYTE boundaries. The data FROM an IOProc … … 880 876 881 877 if (ulBytesRead) { 882 LONG lWritten; 883 lWritten=mmioWrite (hmmioTarget, pRowBuffer, (ULONG)ulBytesRead); 878 mmioWrite (hmmioTarget, pRowBuffer, (ULONG)ulBytesRead); 884 879 #ifdef DEBUG 885 880 HlpWriteToTrapLog("ulBytesRead: %d, lWritten: %d.\n", ulBytesRead, lWritten); … … 898 893 mmioClose (hmmioSource, 0L); 899 894 DosFreeMem(pRowBuffer); 900 895 901 896 return(TRUE); 902 897 } 903 898 904 void _OptlinkconvertThreadFunc (void *arg)899 void convertThreadFunc (void *arg) 905 900 { 906 901 HAB hab; … … 916 911 chrSourceName, 917 912 chrTargetName, pMemFormatInfo[iIoProc].fccIOProc); 918 919 920 921 WinPostMsg(hwnd, WM_APPTERMINATENOTIFY, MPFROMLONG(MSG_CONVERTDONE), 0); 913 914 915 916 WinPostMsg(hwnd, WM_APPTERMINATENOTIFY, MPFROMLONG(MSG_CONVERTDONE), 0); 922 917 DosSleep(1000); 923 918 WinDestroyMsgQueue(hmq); … … 944 939 POINTL aptl[4]; 945 940 HPS hps; 946 BOOL bReturnCode;947 941 ULONG ulHeight; 948 942 ULONG ulWidth; … … 954 948 * Get position of image frame 955 949 */ 956 bReturnCode =WinQueryWindowPos ( hwnd, &swp);950 WinQueryWindowPos ( hwnd, &swp); 957 951 958 952 /* Center image */ … … 963 957 aptl[0].x=(swp.cx-ulWidth)/2; 964 958 aptl[1].x=aptl[0].x+ulWidth; 965 959 966 960 aptl[0].y=(swp.cy-ulHeight)/2; 967 961 aptl[1].y=aptl[0].y+ulHeight; … … 977 971 aptl[0].x=(swp.cx-ulWidth*fRes)/2; 978 972 aptl[1].x=aptl[0].x+ulWidth*fRes; 979 973 980 974 aptl[0].y=(swp.cy-ulHeight*fRes)/2; 981 975 aptl[1].y=aptl[0].y+ulHeight*fRes; 982 976 } 983 977 984 978 aptl[2].x = 0; // source lower left 985 979 aptl[2].y = 0; 986 980 987 981 aptl[3].x = ulWidth; // source upper right 988 982 aptl[3].y = ulHeight; … … 1004 998 // WinDrawBitmap(hps, hBitmap, NULLHANDLE, (PPOINTL)aptl, 0, 0, DBM_NORMAL/*|DBM_STRETCH*/); 1005 999 #endif 1006 bReturnCode =WinEndPaint (hps);1000 WinEndPaint (hps); 1007 1001 } 1008 1002 … … 1011 1005 1012 1006 switch (msg) 1013 { 1007 { 1014 1008 case WM_PAINT: 1015 1009 { … … 1036 1030 1037 1031 switch (msg) 1038 { 1032 { 1039 1033 case WM_INITDLG: 1040 1034 #if 0 … … 1047 1041 1048 1042 WinSendMsg(WinWindowFromID(hwnd,IDST_IMGCONVERTNAME),EM_SETTEXTLIMIT,MPFROMSHORT((SHORT)CCHMAXPATH),0); 1049 1043 1050 1044 /* Filename */ 1051 1045 WinSetWindowText(WinWindowFromID(hwnd,IDST_IMGCONVERTNAME), chrSourceName); 1052 1046 1053 1047 /* Set dialog font to WarpSans for Warp 4 and above */ 1054 1048 if(SysQueryOSRelease()>=40) { … … 1112 1106 iPercent=0; 1113 1107 1114 /* Update track percent bar value. The helper prog sends us the actual decoded %. */ 1108 /* Update track percent bar value. The helper prog sends us the actual decoded %. */ 1115 1109 sprintf(text,"%d#%d%%", iPercent, iPercent); 1116 1110 WinSetWindowText(WinWindowFromID(hwnd,IDBAR_IMGCONVERTPROGRESS), text); … … 1149 1143 1150 1144 createTargetName(chrSourceName, pMemFormatInfo[iIoProc].szDefaultFormatExt); 1151 WinSetWindowText( WinWindowFromID(hwnd,IDEF_IMGCONVERTTARGETNAME), chrTargetName ); 1145 WinSetWindowText( WinWindowFromID(hwnd,IDEF_IMGCONVERTTARGETNAME), chrTargetName ); 1152 1146 } 1153 1147 } … … 1210 1204 // ULONG ulDiskNum; 1211 1205 // char cLetter; 1212 1206 1213 1207 /* Get target name */ 1214 WinQueryWindowText( WinWindowFromID(hwnd,IDEF_IMGCONVERTTARGETNAME), 1208 WinQueryWindowText( WinWindowFromID(hwnd,IDEF_IMGCONVERTTARGETNAME), 1215 1209 sizeof(chrTargetName), chrTargetName ); 1216 1210 #if 0 … … 1225 1219 if(lFreeSpace<lAudioSize) { 1226 1220 /* 1227 Text: 1228 Title: 1229 */ 1221 Text: 1222 Title: 1223 */ 1230 1224 getMessage(title, IDSTR_CONVERTNOSPACETEXT,sizeof(title), RESSOURCEHANDLE, hwnd); 1231 1225 sprintf(text,title,lAudioSize/1000000 ); … … 1237 1231 else { 1238 1232 /* Start decoding an audio file */ 1239 WinEnableWindow( WinWindowFromID(hwnd,IDPB_CONVERTOK), FALSE); 1233 WinEnableWindow( WinWindowFromID(hwnd,IDPB_CONVERTOK), FALSE); 1240 1234 WinEnableWindow( WinWindowFromID(hwnd,IDPB_CONVERTABORT), TRUE); 1241 1235 convertAudioFile(hwnd); … … 1244 1238 /* Start converting image file */ 1245 1239 WinPostMsg(hwnd, WM_APPTERMINATENOTIFY, MPFROMLONG(MSG_CONVERTPERCENT), MPFROMLONG(0)); 1246 WinEnableWindow( WinWindowFromID(hwnd,IDPB_IMGCONVERTOK), FALSE); 1240 WinEnableWindow( WinWindowFromID(hwnd,IDPB_IMGCONVERTOK), FALSE); 1247 1241 WinEnableWindow( WinWindowFromID(hwnd,IDPB_IMGCONVERTABORT), TRUE); 1248 1242 convertImageFile(hwnd); … … 1256 1250 break; 1257 1251 }/* switch */ 1258 1252 1259 1253 return WinDefDlgProc( hwnd, msg, mp1, mp2); 1260 1254 } … … 1283 1277 if(hab) { 1284 1278 hmq=WinCreateMsgQueue(hab,0); 1285 if(hmq) { 1286 /* Check if user started prog by hand */ 1279 if(hmq) { 1280 /* Check if user started prog by hand */ 1287 1281 if(argc<NUMPARAMS-1) {/* Not the right num of params */ 1288 1282 pmUsage(); … … 1297 1291 strcpy(chrProcName, ""); 1298 1292 } 1299 /* Get our ressource dll */ 1293 /* Get our ressource dll */ 1300 1294 // RESSOURCEHANDLE=0; 1301 1295 RESSOURCEHANDLE=queryResModuleHandle(argv[0]); … … 1304 1298 /* Register the percent bar window class */ 1305 1299 percentRegisterBarClass(); 1306 1307 globalHab=WinQueryAnchorBlock(HWND_DESKTOP); 1300 1301 globalHab=WinQueryAnchorBlock(HWND_DESKTOP); 1308 1302 hBitmap=loadBitmap ( chrSourceName, &bmpInfoHeader2); 1309 1310 if( WinDlgBox( HWND_DESKTOP, NULLHANDLE, decodeStatusDialogProc, 1303 1304 if( WinDlgBox( HWND_DESKTOP, NULLHANDLE, decodeStatusDialogProc, 1311 1305 RESSOURCEHANDLE, IDDLG_IMGCONVERT, 0) == DID_ERROR ) 1312 1306 { … … 1314 1308 char title[CCHMAXPATH]; 1315 1309 /* 1316 Text: 1317 Title: "Installation problem" 1318 */ 1310 Text: 1311 Title: "Installation problem" 1312 */ 1319 1313 messageBox( text, IDSTR_CONVERTDIALOGERROR , sizeof(text), 1320 1314 title, IDSTR_INSTALLERRORTITLE , sizeof(title), … … 1329 1323 return( 1 ); 1330 1324 } 1331 if(pMemFormatInfo) 1325 if(pMemFormatInfo) 1332 1326 free(pMemFormatInfo); 1333 1327 if(hBitmap)
Note:
See TracChangeset
for help on using the changeset viewer.