Ignore:
Timestamp:
Oct 2, 2023, 11:34:35 PM (23 months ago)
Author:
gyoung
Message:

Remaining changes from merge with Lars 2.9 branch

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/classes/mm-progs/imageconverter/imgconv.c

    r2 r104  
    2323 * If you need another license for your project/product (commercial,
    2424 * noncommercial, whatever) contact me at
    25  * 
     25 *
    2626 * http://www.os2world.com/cdwriting
    2727 * http://www.geocities.com/SiliconValley/Sector/5785/
     
    3737#define INCL_PM
    3838
     39#define USE_OS2_TOOLKIT_HEADERS
    3940#include <os2.h>
    4041
     
    4647#include "os2me.h"
    4748#include "mmioos2.h"
     49#include <mmio.h>
    4850#include "common.h"
    4951#include "mmres.h"
     
    143145    SIZEL         ImageSize;
    144146    ULONG         dwHeight, dwWidth;
    145     SHORT          wBitCount;
    146147    FOURCC        fccStorageSystem;
    147148    ULONG         dwPadBytes;
    148149    ULONG         dwRowBits;
    149150    ULONG         ulReturnCode;
    150     ULONG         dwReturnCode;
    151     HBITMAP       hbReturnCode;
    152     LONG          lReturnCode;
    153151    FOURCC        fccIOProc;
    154152    HDC           hdc;
     
    212210
    213211
    214     dwReturnCode = mmioQueryHeaderLength ( hmmio,
     212    ulReturnCode = mmioQueryHeaderLength ( hmmio,
    215213                                         (PLONG)&ulImageHeaderLength,
    216214                                           0L,
     
    247245    dwHeight = mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cy;
    248246    dwWidth = mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cx;
    249     wBitCount = mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cBitCount;
    250247    dwRowBits = dwWidth * mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cBitCount;
    251248    dwNumRowBytes = dwRowBits >> 3;
     
    288285        return(0L);
    289286      }
    290    
     287
    291288
    292289    // ***************************************************
     
    294291    // the memory device context obtained above.
    295292    // ***************************************************
    296    
     293
    297294    ImageSize.cx = dwWidth;
    298295    ImageSize.cy = dwHeight;
     
    312309                       (ULONG) MB_OK | MB_MOVEABLE |
    313310                       MB_ERROR );
    314 #endif   
     311#endif
    315312        DevCloseDC(hdc);
    316313        DosFreeMem(pRowBuffer);
     
    350347    // Select the bitmap into the memory device context.
    351348    // ***************************************************
    352     hbReturnCode = GpiSetBitmap ( hps,
     349    ulReturnCode = GpiSetBitmap ( hps,
    353350                                  hbm );
    354351
     
    371368          *  it to work. Perhaps will get to it when time is available...
    372369          */
    373          lReturnCode = GpiSetBitmapBits ( hps,
     370         ulReturnCode = GpiSetBitmapBits ( hps,
    374371                                          (LONG) dwRowCount,
    375372                                          (LONG) 1,
     
    379376
    380377    /* Clean up */
    381     hbReturnCode = GpiSetBitmap ( hps,
     378    ulReturnCode = GpiSetBitmap ( hps,
    382379                                  NULLHANDLE );
    383380    ulReturnCode = mmioClose (hmmio, 0L);
     
    396393                          PBITMAPINFOHEADER2 pBmpInfoHeader2,
    397394                          HWND hwnd)
    398                           //                          ULONG ulWidth, 
     395                          //                          ULONG ulWidth,
    399396                          //     ULONG ulHeight)
    400397{
    401398  HBITMAP       hbmTarget;
    402399  SIZEL         ImageSize;
    403   HBITMAP       hbReturnCode;
    404400  HDC           hdc;
    405401  HPS           hps;
     
    413409   */
    414410  WinQueryWindowPos ( hwnd, &swp);
    415  
     411
    416412  /* Image size */
    417  
     413
    418414  ulHeight = bmpInfoHeader2.cy;
    419415  ulWidth = bmpInfoHeader2.cx;
     
    423419      aptl[0].x=0;
    424420      aptl[1].x=aptl[0].x+ulWidth;
    425      
     421
    426422      aptl[0].y=0;
    427423      aptl[1].y=aptl[0].y+ulHeight;
     
    429425  else {
    430426    float fWidth, fHeight, fRes;
    431    
     427
    432428    fWidth=(float)swp.cx/(float)ulWidth;
    433429    fHeight=(float)swp.cy/(float)ulHeight;
    434430    fRes=( fWidth>fHeight ? fHeight : fWidth);
    435    
    436    
     431
     432
    437433    aptl[0].x=0;
    438434    aptl[1].x=aptl[0].x+ulWidth*fRes;
    439    
     435
    440436      aptl[0].y=0;
    441437      aptl[1].y=aptl[0].y+ulHeight*fRes;
    442438    }
    443    
     439
    444440    aptl[2].x = 0;              // source lower left
    445441    aptl[2].y = 0;
    446    
     442
    447443    aptl[3].x = ulWidth;   // source upper right
    448444    aptl[3].y = ulHeight;
     
    468464        return(0L);
    469465      }
    470    
     466
    471467    // ***************************************************
    472468    // Create a memory presentation space that includes
     
    486482
    487483    /* Now scale the bitmap */
    488     memcpy(&bmpih2, pBmpInfoHeader2, sizeof(BITMAPINFOHEADER2));   
     484    memcpy(&bmpih2, pBmpInfoHeader2, sizeof(BITMAPINFOHEADER2));
    489485
    490486    bmpih2.cx=aptl[1].x-aptl[0].x;
     
    509505
    510506    /* Blit it */
    511     hbReturnCode = GpiSetBitmap ( hps, hbmTarget );
     507    GpiSetBitmap ( hps, hbmTarget );
    512508
    513509    GpiWCBitBlt(hps, hbm,4L, aptl, ROP_SRCCOPY, BBO_IGNORE);
    514510
    515     hbReturnCode = GpiSetBitmap( hps, NULLHANDLE );
     511    GpiSetBitmap( hps, NULLHANDLE );
    516512    GpiDestroyPS(hps);
    517513    DevCloseDC(hdc);
     
    545541  strcat(textPtr,".");
    546542  strcat(textPtr, chrExt);
    547  
     543
    548544  return TRUE;
    549545}
     
    564560            '\0',
    565561            sizeof(MMFORMATINFO) );
    566    
     562
    567563    mmFormatInfo.ulMediaType |= MMIO_MEDIATYPE_IMAGE;
    568     mmFormatInfo.ulFlags|=MMIO_CANWRITETRANSLATED;   
     564    mmFormatInfo.ulFlags|=MMIO_CANWRITETRANSLATED;
    569565    ulReturnCode = mmioQueryFormatCount ( &mmFormatInfo,
    570566                                          &lNumIOProcs,
    571567                                          0,
    572568                                          0 );
    573    
     569
    574570    if( ulReturnCode != MMIO_SUCCESS )
    575571      {
     
    592588        return FALSE;
    593589      }
    594    
     590
    595591    /*
    596592     * call mmioGetFormats to get info on the formats supported.
     
    610606        return FALSE;
    611607      }
    612    
     608
    613609    if( lFormatsRead != lNumIOProcs )
    614610      {
     
    627623        char szName[CCHMAXPATH];
    628624
    629         mmioGetFormatName(pmmFormatInfoArray, szName, &lBytesRead, 0L, 0L);       
     625        mmioGetFormatName(pmmFormatInfoArray, szName, &lBytesRead, 0L, 0L);
    630626        /* Insert NULL string terminator */
    631         *( szName + lBytesRead ) = (CHAR)NULL;
     627        *( szName + lBytesRead ) = 0;
    632628
    633629
     
    643639
    644640#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,
    646642                          pmmFormatInfoArray->szDefaultFormatExt,
    647643                          szName);
    648644#endif
    649            
     645
    650646            iPrivIOProc[sIdx]=index;
    651647
     
    669665        /*
    670666         *  advance to next entry in mmFormatInfo array
    671          */       
     667         */
    672668        pmmFormatInfoArray++;
    673669      }
     
    700696  ULONG         iIndex, iCount, iCount2;
    701697
    702   MMFORMATINFO  mmFormatInfo; 
     698  MMFORMATINFO  mmFormatInfo;
    703699  FOURCC fccSourceIOProc;
    704700  FOURCC        fccStorageSystem;
     
    728724  mmioinfoSource.fccIOProc = fccSourceIOProc;
    729725  mmioinfoSource.ulTranslate = MMIO_TRANSLATEHEADER | MMIO_TRANSLATEDATA;
    730  
     726
    731727  hmmioSource = mmioOpen ((PSZ)pszSource, &mmioinfoSource,
    732728                          MMIO_READ | MMIO_DENYWRITE
    733729                          | MMIO_NOIDENTIFY);
    734  
     730
    735731  if (!hmmioSource)
    736732    return (FALSE);
    737  
     733
    738734  /*******************************/
    739735  /* Set up/open the TARGET file */
     
    743739  mmioinfoTarget.fccIOProc = fccTargetIOProc;
    744740  mmioinfoTarget.ulTranslate = MMIO_TRANSLATEHEADER | MMIO_TRANSLATEDATA;
    745  
     741
    746742  hmmioTarget = mmioOpen ((PSZ)pszTarget,
    747743                          &mmioinfoTarget,
    748744                          MMIO_CREATE | MMIO_WRITE |
    749745                          MMIO_DENYWRITE | MMIO_NOIDENTIFY);
    750  
     746
    751747  if (!hmmioTarget)
    752748    {
     
    762758  rcSrcQueryCount = mmioSendMessage(hmmioSource, MMIOM_QUERYIMAGECOUNT, (LONG)&iCount, (LONG)0);
    763759  if (rcSrcQueryCount) iCount = 1;
    764  
     760
    765761  // find out if the target has multiple image support
    766762  rcTrgQueryCount = mmioSendMessage(hmmioTarget, MMIOM_QUERYIMAGECOUNT, (LONG)&iCount2, (LONG)0);
    767  
     763
    768764  for (iIndex=0; iIndex<iCount; iIndex++) { /* loop through known images */
    769765
    770766    if (!rcSrcQueryCount && !rcTrgQueryCount) {  /* if Both support images */
    771      
     767
    772768      /* Determine if the target can write arrays, and if not */
    773769      /* then write the the default image from the source     */
    774770
    775771      if (rcTrgSetImage && iIndex > 0) break;  /* Target Can't Write array */
    776      
     772
    777773      /* Now, determine if the target can write arrays */
    778774      rcTrgSetImage = mmioSendMessage (hmmioTarget, MMIOM_SETIMAGE, (LONG)iIndex, (LONG)0);
    779      
     775
    780776      if (!rcTrgSetImage) mmioSendMessage (hmmioSource, MMIOM_SETIMAGE, (LONG)iIndex, (LONG)0);
    781      
     777
    782778    } else if (!rcSrcQueryCount) {      /* Source does but target doesn't */
    783779      /* Use the default image from source to copy to target */
     
    806802                              (LONG)sizeof (MMIMAGEHEADER), (PLONG)&ulBytesRead,
    807803                              0L, 0L);
    808    
     804
    809805    if (rc != MMIO_SUCCESS)
    810806      /* Header unavailable */
     
    814810        return (FALSE);
    815811      }
    816    
     812
    817813
    818814    /*************************/
     
    828824      }
    829825
    830    
     826
    831827    /* Use the SAME data as came from the SOURCE FILE.  It must be
    832828       compatible with the OS/2 bitmaps, etc.   */
     
    834830                              (LONG)sizeof (MMIMAGEHEADER), (PLONG)&ulBytesRead,
    835831                              0L, 0L);
    836    
     832
    837833    if (rc != MMIO_SUCCESS)
    838834      /* Header unavailable */
     
    846842        HlpWriteToTrapLog("Target header set.\n");
    847843#endif
    848    
     844
    849845    /* Determine the number of bytes required, per row */
    850846    /*      PLANES MUST ALWAYS BE = 1 */
     
    853849    dwRowBits = dwWidth * mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cBitCount;
    854850    dwNumRowBytes = dwRowBits >> 3;
    855    
     851
    856852    /* Account for odd bits used in 1bpp or 4bpp images that are NOT on byte boundaries. */
    857853    if (dwRowBits % 8)
    858854      dwNumRowBytes++;
    859    
     855
    860856    /* Ensure the row length in bytes accounts for byte padding.  All bitmap data rows
    861857       must are aligned on LONG/4-BYTE boundaries.   The data FROM an IOProc
     
    880876
    881877        if (ulBytesRead) {
    882           LONG lWritten;
    883           lWritten=mmioWrite (hmmioTarget, pRowBuffer, (ULONG)ulBytesRead);
     878          mmioWrite (hmmioTarget, pRowBuffer, (ULONG)ulBytesRead);
    884879#ifdef DEBUG
    885880        HlpWriteToTrapLog("ulBytesRead: %d, lWritten: %d.\n", ulBytesRead, lWritten);
     
    898893  mmioClose (hmmioSource, 0L);
    899894  DosFreeMem(pRowBuffer);
    900  
     895
    901896  return(TRUE);
    902897}
    903898
    904 void _Optlink convertThreadFunc (void *arg)
     899void convertThreadFunc (void *arg)
    905900{
    906901  HAB  hab;
     
    916911                chrSourceName,
    917912                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);
    922917      DosSleep(1000);
    923918      WinDestroyMsgQueue(hmq);
     
    944939    POINTL aptl[4];
    945940    HPS    hps;
    946     BOOL   bReturnCode;
    947941    ULONG  ulHeight;
    948942    ULONG  ulWidth;
     
    954948     *  Get position of image frame
    955949     */
    956     bReturnCode = WinQueryWindowPos ( hwnd, &swp);
     950    WinQueryWindowPos ( hwnd, &swp);
    957951
    958952    /* Center image */
     
    963957        aptl[0].x=(swp.cx-ulWidth)/2;
    964958        aptl[1].x=aptl[0].x+ulWidth;
    965        
     959
    966960        aptl[0].y=(swp.cy-ulHeight)/2;
    967961        aptl[1].y=aptl[0].y+ulHeight;
     
    977971      aptl[0].x=(swp.cx-ulWidth*fRes)/2;
    978972      aptl[1].x=aptl[0].x+ulWidth*fRes;
    979      
     973
    980974      aptl[0].y=(swp.cy-ulHeight*fRes)/2;
    981975      aptl[1].y=aptl[0].y+ulHeight*fRes;
    982976    }
    983    
     977
    984978    aptl[2].x = 0;              // source lower left
    985979    aptl[2].y = 0;
    986    
     980
    987981    aptl[3].x = ulWidth;   // source upper right
    988982    aptl[3].y = ulHeight;
     
    1004998    //       WinDrawBitmap(hps, hBitmap, NULLHANDLE, (PPOINTL)aptl, 0, 0, DBM_NORMAL/*|DBM_STRETCH*/);
    1005999#endif
    1006     bReturnCode = WinEndPaint (hps);
     1000    WinEndPaint (hps);
    10071001}
    10081002
     
    10111005
    10121006  switch (msg)
    1013     {     
     1007    {
    10141008    case WM_PAINT:
    10151009      {
     
    10361030
    10371031  switch (msg)
    1038     {     
     1032    {
    10391033    case WM_INITDLG:
    10401034#if 0
     
    10471041
    10481042      WinSendMsg(WinWindowFromID(hwnd,IDST_IMGCONVERTNAME),EM_SETTEXTLIMIT,MPFROMSHORT((SHORT)CCHMAXPATH),0);
    1049      
     1043
    10501044      /* Filename */
    10511045      WinSetWindowText(WinWindowFromID(hwnd,IDST_IMGCONVERTNAME), chrSourceName);
    1052      
     1046
    10531047      /* Set dialog font to WarpSans for Warp 4 and above */
    10541048      if(SysQueryOSRelease()>=40) {
     
    11121106            iPercent=0;
    11131107
    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 %. */
    11151109          sprintf(text,"%d#%d%%", iPercent, iPercent);
    11161110          WinSetWindowText(WinWindowFromID(hwnd,IDBAR_IMGCONVERTPROGRESS), text);
     
    11491143
    11501144           createTargetName(chrSourceName, pMemFormatInfo[iIoProc].szDefaultFormatExt);
    1151            WinSetWindowText( WinWindowFromID(hwnd,IDEF_IMGCONVERTTARGETNAME), chrTargetName );           
     1145           WinSetWindowText( WinWindowFromID(hwnd,IDEF_IMGCONVERTTARGETNAME), chrTargetName );
    11521146         }
    11531147        }
     
    12101204            // ULONG ulDiskNum;
    12111205            // char cLetter;
    1212            
     1206
    12131207            /* Get target name */
    1214             WinQueryWindowText( WinWindowFromID(hwnd,IDEF_IMGCONVERTTARGETNAME), 
     1208            WinQueryWindowText( WinWindowFromID(hwnd,IDEF_IMGCONVERTTARGETNAME),
    12151209                                sizeof(chrTargetName), chrTargetName );
    12161210#if 0
     
    12251219             if(lFreeSpace<lAudioSize) {
    12261220               /*
    1227                  Text:   
    1228                  Title: 
    1229                  */       
     1221                 Text:
     1222                 Title:
     1223                 */
    12301224               getMessage(title, IDSTR_CONVERTNOSPACETEXT,sizeof(title), RESSOURCEHANDLE, hwnd);
    12311225               sprintf(text,title,lAudioSize/1000000 );
     
    12371231             else {
    12381232               /* Start decoding an audio file */
    1239                WinEnableWindow( WinWindowFromID(hwnd,IDPB_CONVERTOK), FALSE);           
     1233               WinEnableWindow( WinWindowFromID(hwnd,IDPB_CONVERTOK), FALSE);
    12401234               WinEnableWindow( WinWindowFromID(hwnd,IDPB_CONVERTABORT), TRUE);
    12411235               convertAudioFile(hwnd);
     
    12441238             /* Start converting image file */
    12451239             WinPostMsg(hwnd, WM_APPTERMINATENOTIFY, MPFROMLONG(MSG_CONVERTPERCENT), MPFROMLONG(0));
    1246              WinEnableWindow( WinWindowFromID(hwnd,IDPB_IMGCONVERTOK), FALSE);           
     1240             WinEnableWindow( WinWindowFromID(hwnd,IDPB_IMGCONVERTOK), FALSE);
    12471241             WinEnableWindow( WinWindowFromID(hwnd,IDPB_IMGCONVERTABORT), TRUE);
    12481242             convertImageFile(hwnd);
     
    12561250      break;
    12571251    }/* switch */
    1258  
     1252
    12591253  return WinDefDlgProc( hwnd, msg, mp1, mp2);
    12601254}
     
    12831277  if(hab) {
    12841278    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 */
    12871281      if(argc<NUMPARAMS-1) {/* Not the right num of params */
    12881282        pmUsage();
     
    12971291          strcpy(chrProcName, "");
    12981292        }
    1299         /* Get our ressource dll */ 
     1293        /* Get our ressource dll */
    13001294        //   RESSOURCEHANDLE=0;
    13011295        RESSOURCEHANDLE=queryResModuleHandle(argv[0]);
     
    13041298        /* Register the percent bar window class */
    13051299        percentRegisterBarClass();
    1306        
    1307         globalHab=WinQueryAnchorBlock(HWND_DESKTOP);       
     1300
     1301        globalHab=WinQueryAnchorBlock(HWND_DESKTOP);
    13081302        hBitmap=loadBitmap ( chrSourceName, &bmpInfoHeader2);
    1309        
    1310         if( WinDlgBox( HWND_DESKTOP, NULLHANDLE, decodeStatusDialogProc, 
     1303
     1304        if( WinDlgBox( HWND_DESKTOP, NULLHANDLE, decodeStatusDialogProc,
    13111305                       RESSOURCEHANDLE, IDDLG_IMGCONVERT, 0) == DID_ERROR )
    13121306          {
     
    13141308            char title[CCHMAXPATH];
    13151309            /*
    1316               Text:   
    1317               Title:  "Installation problem"                       
    1318               */             
     1310              Text:
     1311              Title:  "Installation problem"
     1312              */
    13191313            messageBox( text, IDSTR_CONVERTDIALOGERROR , sizeof(text),
    13201314                        title, IDSTR_INSTALLERRORTITLE , sizeof(title),
     
    13291323            return( 1 );
    13301324          }
    1331         if(pMemFormatInfo)   
     1325        if(pMemFormatInfo)
    13321326          free(pMemFormatInfo);
    13331327        if(hBitmap)
Note: See TracChangeset for help on using the changeset viewer.