Ignore:
Timestamp:
Jun 26, 1999, 1:34:43 PM (26 years ago)
Author:
hugh
Message:

DX 6 Version of ddraw rel files

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/ddraw/OS2PALETTE.CPP

    r97 r210  
    1 /* $Id: OS2PALETTE.CPP,v 1.3 1999-06-10 17:10:56 phaller Exp $ */
    2 
    3 /*
    4  * DirectDraw Palette class
    5  *
    6  * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl)
    7  *
    8  * Project Odin Software License can be found in LICENSE.TXT
    9  *
    10  */
    11 
    12 /*@Const************************************************************************
    13 *   Defined Constants                                                          *
    14 *******************************************************************************/
    15 #define INCL_GUID
    16 #define WIN32SDK_NOPOSTWRAPPER
    17 
    18 /*@Header***********************************************************************
    19 *   Header Files                                                               *
    20 *******************************************************************************/
    21 #include <os2win.h>
    22 #include <dive.h>
    23 
    241#include <stdio.h>
    252#include <stdlib.h>
    263#include <string.h>
    274#include <memory.h>
    28 
    29 #include "no.h"
    30 #include <w_windows.h>
    31 #include <ddraw.h>
    32 #include <d3d.h>
    33 #include <Win32SDKPostWrapper.h>
    34 
    35 #include "os2ddraw.h"
     5#define INITGUID
    366#include "os2palette.h"
     7#define _OS2WIN_H
     8#define FAR
    379#include "misc.h"
    3810#include "os2palset.h"
    39 
    40 extern DIVE_CAPS dcaps;
    41 
    42 //******************************************************************************
    43 //******************************************************************************
    44 OS2IDirectDrawPalette::OS2IDirectDrawPalette(OS2IDirectDraw *lpDirectDraw,
    45                          int palsize,
    46                          W32_LPPALETTEENTRY lpColorTable) :
    47                          Referenced(0), os2pal(NULL),
    48                          lastError(DD_OK), lpDraw(NULL)
    49 {
    50   lpVtbl                        = &Vtbl;
    51   Vtbl.AddRef           = PalAddRef;
    52   Vtbl.Release              = PalRelease;
    53   Vtbl.QueryInterface       = PalQueryInterface;
    54   Vtbl.GetCaps          = PalGetCaps;
    55   Vtbl.GetEntries       = PalGetEntries;
    56   Vtbl.Initialize       = PalInitialize;
    57   Vtbl.SetEntries       = PalSetEntries;
     11#include <winerror.h>
     12
     13//******************************************************************************
     14//******************************************************************************
     15OS2IDirectDrawPalette::OS2IDirectDrawPalette( OS2IDirectDraw *lpDirectDraw,
     16                                              int palsize,
     17                                              LPPALETTEENTRY lpColorTable,
     18                                              DWORD dwPalFlags) :
     19                                              Referenced(0), os2pal(NULL),
     20                                              lastError(DD_OK), lpDraw(NULL)
     21{
     22  lpVtbl              = &Vtbl;
     23  Vtbl.AddRef         = PalAddRef;
     24  Vtbl.Release        = PalRelease;
     25  Vtbl.QueryInterface = PalQueryInterface;
     26  Vtbl.GetCaps        = PalGetCaps;
     27  Vtbl.GetEntries     = PalGetEntries;
     28  Vtbl.Initialize     = PalInitialize;
     29  Vtbl.SetEntries     = PalSetEntries;
    5830
    5931  lpDraw                        = lpDirectDraw;
    60   lpDraw->Vtbl.AddRef((IDirectDraw2*)lpDraw);
     32  lpDraw->Vtbl.AddRef(lpDraw);
    6133  hDive                         = lpDirectDraw->GetDiveInstance();
    62   nrColors                      = palsize;
    63 
    64   dprintf(("OS2IDirectDrawPalette::OS2IDirectDrawPalette nr colors %d", palsize));
    65   os2pal = (W32_LPPALETTEENTRY)malloc(palsize*sizeof(PALETTEENTRY));
     34  dwCaps                        = dwPalFlags;
     35
     36  dwSize = palsize;
     37  if(256==dwSize)
     38    dwCaps |= DDPCAPS_ALLOW256;
     39  dwCaps &= ~DDPCAPS_VSYNC; // No sync change
     40
     41  os2pal = (LPPALETTEENTRY)malloc(palsize*sizeof(PALETTEENTRY));
    6642  memcpy((char *)os2pal, (char *)lpColorTable, palsize*sizeof(PALETTEENTRY));
    6743}
     
    7046OS2IDirectDrawPalette::~OS2IDirectDrawPalette()
    7147{
    72   if(os2pal)    free(os2pal);
    73   lpDraw->Vtbl.Release((IDirectDraw2*)lpDraw);
    74   RestorePhysPalette();
    75 }
    76 //******************************************************************************
    77 //******************************************************************************
    78 HRESULT __stdcall PalQueryInterface(THIS, REFIID riid, LPVOID FAR * ppvObj)
    79 {
    80   dprintf(("OS2IDirectDrawPalette::PalQueryInterface\n"));
     48  if(os2pal)
     49    free(os2pal);
     50  lpDraw->Vtbl.Release(lpDraw);
     51}
     52//******************************************************************************
     53//******************************************************************************
     54HRESULT __stdcall PalQueryInterface(THIS This, REFIID riid, LPVOID FAR * ppvObj)
     55{
     56  #ifdef DEBUG
     57    WriteLog("OS2IDirectDrawPalette::PalQueryInterface\n");
     58  #endif
     59
    8160  *ppvObj = NULL;
    8261
    8362  if(!IsEqualGUID(riid, IID_IDirectDrawPalette))
    8463//&& !IsEqualGUID(riid, IID_IUnknown))
    85     return E_NOINTERFACE;
     64  return E_NOINTERFACE;
    8665
    8766  *ppvObj = This;
     
    9271//******************************************************************************
    9372//******************************************************************************
    94 ULONG __stdcall PalAddRef(THIS)
     73ULONG __stdcall PalAddRef(THIS This)
     74{
     75  OS2IDirectDrawPalette *me = (OS2IDirectDrawPalette *)This;
     76
     77  #ifdef DEBUG
     78    WriteLog("OS2IDirectDrawPalette::PalAddRef %d\n", me->Referenced+1);
     79  #endif
     80
     81  return (++me->Referenced);
     82}
     83//******************************************************************************
     84//******************************************************************************
     85ULONG __stdcall PalRelease(THIS This)
     86{
     87  OS2IDirectDrawPalette *me = (OS2IDirectDrawPalette *)This;
     88
     89  #ifdef DEBUG
     90    WriteLog("OS2IDirectDrawPalette::PalRelease %d\n", me->Referenced-1);
     91  #endif
     92
     93  if(me->Referenced)
     94  {
     95    me->Referenced--;
     96    if(me->Referenced == 0)
     97    {
     98      delete me;
     99      return(0);
     100    }
     101    else
     102      return (me->Referenced);
     103  }
     104  else
     105    return(0);
     106}
     107//******************************************************************************
     108//******************************************************************************
     109HRESULT __stdcall PalGetCaps(THIS This, LPDWORD lpdwCaps)
     110{
     111  OS2IDirectDrawPalette *me = (OS2IDirectDrawPalette *)This;
     112
     113  #ifdef DEBUG
     114    WriteLog("OS2IDirectDrawPalette::GetCaps\n");
     115  #endif
     116
     117  if(NULL== lpdwCaps)
     118    return(DDERR_INVALIDPARAMS);
     119
     120  *lpdwCaps = me->dwCaps;
     121
     122  if(me->fAttachedToPrimary)
     123    *lpdwCaps |= DDPCAPS_PRIMARYSURFACE;
     124
     125  return(DD_OK);
     126}
     127//******************************************************************************
     128//******************************************************************************
     129HRESULT __stdcall PalGetEntries(THIS This, DWORD dwFlags,
     130                                      DWORD dwBase,
     131                                      DWORD dwNumEntries,
     132                                      LPPALETTEENTRY lpEntries)
    95133{
    96134 OS2IDirectDrawPalette *me = (OS2IDirectDrawPalette *)This;
    97135
    98   dprintf(("OS2IDirectDrawPalette::PalAddRef %d\n", me->Referenced+1));
    99   return ++me->Referenced;
    100 }
    101 //******************************************************************************
    102 //******************************************************************************
    103 ULONG __stdcall PalRelease(THIS)
     136  #ifdef DEBUG
     137    WriteLog("OS2IDirectDrawPalette::PalGetEntries\n");
     138  #endif
     139
     140  if( (NULL== lpEntries) ||(0!=dwFlags) ||(dwBase<0) ||((dwBase + dwNumEntries)>me->dwSize) )
     141    return(DDERR_INVALIDPARAMS);
     142
     143  memcpy( (char *)lpEntries,
     144          (char *)(me->os2pal + dwBase),
     145          dwNumEntries*sizeof(PALETTEENTRY));
     146  return(DD_OK);
     147}
     148//******************************************************************************
     149//******************************************************************************
     150HRESULT __stdcall PalInitialize(THIS, LPDIRECTDRAW, DWORD, LPPALETTEENTRY)
     151{
     152  #ifdef DEBUG
     153    WriteLog("OS2IDirectDrawPalette::PalInitialize\n");
     154  #endif
     155  return(DDERR_ALREADYINITIALIZED);
     156}
     157//******************************************************************************
     158//******************************************************************************
     159HRESULT __stdcall PalSetEntries(THIS This, DWORD dwFlags,
     160                                      DWORD dwBase,
     161                                      DWORD dwNumEntries,
     162                                      LPPALETTEENTRY lpNewEntries)
    104163{
    105164 OS2IDirectDrawPalette *me = (OS2IDirectDrawPalette *)This;
    106165
    107   dprintf(("OS2IDirectDrawPalette::PalRelease %d\n", me->Referenced-1));
    108   if(me->Referenced) {
    109     me->Referenced--;
    110     if(me->Referenced == 0) {
    111         delete me;
    112         return(0);
    113     }
    114     else    return me->Referenced;
    115   }
    116   else  return(0);
    117 }
    118 //******************************************************************************
    119 //******************************************************************************
    120 HRESULT __stdcall PalGetCaps(THIS_ LPDWORD)
    121 {
    122   dprintf(("OS2IDirectDrawPalette::GetCaps\n"));
    123   return(DD_OK);
    124 }
    125 //******************************************************************************
    126 //******************************************************************************
    127 HRESULT __stdcall PalGetEntries(THIS_ DWORD dwFlags, DWORD dwBase, DWORD dwNumEntries,
    128                         W32_LPPALETTEENTRY lpEntries)
    129 {
    130  OS2IDirectDrawPalette *me = (OS2IDirectDrawPalette *)This;
    131 
    132   dprintf(("OS2IDirectDrawPalette::PalGetEntries %d %d\n", dwBase, dwNumEntries));
    133 
    134   if(dwBase + dwNumEntries > 256)
    135     return(DDERR_UNSUPPORTED);
    136 
    137   memcpy((char *)lpEntries, (char *)(me->os2pal + dwBase), dwNumEntries*sizeof(PALETTEENTRY));
    138   return(DD_OK);
    139 }
    140 //******************************************************************************
    141 //******************************************************************************
    142 HRESULT __stdcall PalInitialize(THIS_ LPDIRECTDRAW, DWORD, W32_LPPALETTEENTRY)
    143 {
    144   dprintf(("OS2IDirectDrawPalette::PalInitialize\n"));
    145   return(DD_OK);
    146 }
    147 //******************************************************************************
    148    #pragma pack(1)          /* pack on wordboundary */
    149 
    150    typedef struct _RGB2         /* rgb2 */
    151    {
    152       BYTE bBlue;              /* Blue component of the color definition */
    153       BYTE bGreen;             /* Green component of the color definition*/
    154       BYTE bRed;               /* Red component of the color definition  */
    155       BYTE fcOptions;          /* Reserved, must be zero                 */
    156    } RGB2;
    157    typedef RGB2 *PRGB2;
    158  #pragma pack()
    159 //******************************************************************************
    160 HRESULT __stdcall PalSetEntries(THIS_ DWORD dwFlags, DWORD dwStartingEntry,
    161                 DWORD dwCount, W32_LPPALETTEENTRY lpEntries)
    162 {
    163  OS2IDirectDrawPalette *me = (OS2IDirectDrawPalette *)This;
    164  int i, rc;
    165  RGB2 os2rgb[256];
    166 
    167    dprintf(("OS2IDirectDrawPalette::PalSetEntries %X %X %d %d\n", me, dwFlags, dwStartingEntry, dwCount));
    168    memcpy(&me->os2pal[dwStartingEntry], lpEntries, sizeof(PALETTEENTRY)*dwCount);
    169 
    170    for(i=0;i<256;i++) {
    171     os2rgb[i].bBlue     = me->os2pal[i].peBlue;
    172     os2rgb[i].bGreen    = me->os2pal[i].peGreen;
    173     os2rgb[i].bRed      = me->os2pal[i].peRed;
    174     os2rgb[i].fcOptions = 0;
    175 //  dprintf(("pal (%3d,%3d,%3d) %d\n", me->os2pal[i].peBlue, me->os2pal[i].peGreen, me->os2pal[i].peRed, me->os2pal[i].peFlags));
    176    }
    177 #if 0
    178    rc = DiveSetSourcePalette(me->hDive, dwStartingEntry, dwCount, (PBYTE)os2rgb);
    179    if(rc != DIVE_SUCCESS) {
    180     dprintf(("DiveSetSourcePalette returned %d\n", rc));
     166  #ifdef DEBUG
     167    WriteLog("OS2IDirectDrawPalette::PalSetEntries\n");
     168  #endif
     169  if( (NULL== lpNewEntries) ||(0!=dwFlags) ||(dwBase<0) ||((dwBase + dwNumEntries)>me->dwSize) )
    181170    return(DDERR_INVALIDPARAMS);
    182    }
    183    if(dcaps.ulDepth == 8) {
    184     rc = DiveSetDestinationPalette(me->hDive, dwStartingEntry, dwCount, (PBYTE)os2rgb);
    185     if(rc != DIVE_SUCCESS) {
    186         dprintf(("DiveSetDestinationPalette returned %d\n", rc));
    187         return(DDERR_INVALIDPARAMS);
    188     }
    189    }
    190 #else
    191    if(dcaps.ulDepth == 8) {
    192     OS2SetPhysPalette((HWND)me->lpDraw->GetWindowHandle(), me->os2pal);
    193     rc = DiveSetDestinationPalette(me->hDive, 0, 0, 0);
    194     if(rc != DIVE_SUCCESS) {
    195         dprintf(("DiveSetDestinationPalette returned %d\n", rc));
    196         return(DDERR_INVALIDPARAMS);
    197     }
    198    }
    199    else {
    200     rc = DiveSetSourcePalette(me->hDive, 0, me->nrColors, (PBYTE)os2rgb);
    201     if(rc != DIVE_SUCCESS) {
    202         dprintf(("DiveSetSourcePalette returned %d\n", rc));
    203         return(DDERR_INVALIDPARAMS);
    204     }
    205    }
    206 #endif
    207    return(DD_OK);
     171  memcpy((char *)(me->os2pal + dwBase),
     172         (char *)lpNewEntries,
     173         dwNumEntries*sizeof(PALETTEENTRY));
     174
     175  if(me->fAttachedToPrimary)
     176    me->SetPhysPalette();
     177
     178  return(DD_OK);
    208179}
    209180//******************************************************************************
     
    211182void OS2IDirectDrawPalette::SetPhysPalette()
    212183{
    213  int i, rc;
    214  RGB2 os2rgb[256];
    215 
    216    for(i=0;i<nrColors;i++) {
    217     os2rgb[i].bBlue     = os2pal[i].peBlue;
    218     os2rgb[i].bGreen    = os2pal[i].peGreen;
    219     os2rgb[i].bRed      = os2pal[i].peRed;
    220     os2rgb[i].fcOptions = 0;
    221     dprintf(("pal (%3d,%3d,%3d) %d\n", os2pal[i].peBlue, os2pal[i].peGreen, os2pal[i].peRed, os2pal[i].peFlags));
    222    }
    223 #if 0
    224    rc = DiveSetSourcePalette(hDive, 0, nrColors, (PBYTE)os2rgb);
    225    if(rc != DIVE_SUCCESS) {
    226     dprintf(("DiveSetSourcePalette returned %d\n", rc));
     184  OS2SetPhysPalette(os2pal);
     185}
     186//******************************************************************************
     187//******************************************************************************
     188void OS2IDirectDrawPalette::RestorePhysPalette()
     189{
     190  OS2ResetPhysPalette();
     191}
     192//******************************************************************************
     193//******************************************************************************
     194void OS2IDirectDrawPalette::SetIsPrimary(BOOL fNewVal)
     195{
     196  if(fNewVal==fAttachedToPrimary)
    227197    return;
    228    }
    229    if(dcaps.ulDepth == 8) {
    230     rc = DiveSetDestinationPalette(hDive, 0, nrColors, (PBYTE)os2rgb);
    231     if(rc != DIVE_SUCCESS) {
    232         dprintf(("DiveSetDestinationPalette returned %d\n", rc));
    233         return;
    234     }
    235    }
    236 #else
    237    if(dcaps.ulDepth == 8) {
    238     OS2SetPhysPalette((HWND)lpDraw->GetWindowHandle(), os2pal);
    239     rc = DiveSetDestinationPalette(hDive, 0, 0, 0);
    240     if(rc != DIVE_SUCCESS) {
    241         dprintf(("DiveSetDestinationPalette returned %d\n", rc));
    242         return;
    243     }
    244   }
    245   else {
    246     rc = DiveSetSourcePalette(hDive, 0, nrColors, (PBYTE)os2rgb);
    247     if(rc != DIVE_SUCCESS) {
    248         dprintf(("DiveSetSourcePalette returned %d\n", rc));
    249         return;
    250     }
    251   }
    252 #endif
    253 }
    254 //******************************************************************************
    255 //******************************************************************************
    256 void OS2IDirectDrawPalette::RestorePhysPalette()
    257 {
    258    if(dcaps.ulDepth == 8) {
    259     OS2ResetPhysPalette();
    260    }
    261 }
    262 //******************************************************************************
    263 //******************************************************************************
    264 
     198  fAttachedToPrimary = fNewVal;
     199  if(fAttachedToPrimary)
     200    SetPhysPalette();
     201
     202}
     203//******************************************************************************
     204//******************************************************************************
     205
Note: See TracChangeset for help on using the changeset viewer.