Changeset 435 for pwntcha


Ignore:
Timestamp:
Jan 8, 2005, 11:37:34 PM (16 years ago)
Author:
Sam Hocevar
Message:
  • Win32 support!!
Location:
pwntcha/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • pwntcha/trunk/configure.ac

    r432 r435  
    2020
    2121AC_CHECK_FUNCS(getopt_long)
     22
     23# Use Windows?
     24AC_CHECK_HEADERS(olectl.h,
     25 [ac_cv_my_have_ole="yes"],
     26 [ac_cv_my_have_ole="no"])
     27CPPFLAGS="${save_CPPFLAGS}"
     28AM_CONDITIONAL(USE_OLE, test "${ac_cv_my_have_ole}" = "yes")
    2229
    2330# Use SDL?
  • pwntcha/trunk/src

    • Property svn:ignore
      •  

        old new  
        44.deps
        55pwntcha
         6pwntcha.exe
  • pwntcha/trunk/src/Makefile.am

    r426 r435  
    22
    33bin_PROGRAMS = pwntcha
    4 pwntcha_CFLAGS = $(ADDITIONAL_CFLAGS) -Wall -O6
    5 pwntcha_LDFLAGS = $(ADDITIONAL_LDFLAGS)
    64pwntcha_SOURCES = \
    75    main.c \
     
    1715    vbulletin.c \
    1816    test.c
     17pwntcha_CFLAGS = $(ADDITIONAL_CFLAGS) -Wall -O6
     18pwntcha_LDFLAGS = $(ADDITIONAL_LDFLAGS)
     19pwntcha_LDADD = $(ADDITIONAL_LDADD)
    1920
     21if USE_OLE
     22ADDITIONAL_CFLAGS =
     23ADDITIONAL_LDFLAGS =
     24ADDITIONAL_LDADD = -luuid -loleaut32 -lole32 -lgdi32
     25else
    2026if USE_SDL
    2127ADDITIONAL_CFLAGS = `sdl-config --cflags`
    2228ADDITIONAL_LDFLAGS = `sdl-config --libs` -lSDL_image
     29ADDITIONAL_LDADD =
    2330else
    2431if USE_IMLIB2
    2532ADDITIONAL_CFLAGS = `imlib2-config --cflags` -DX_DISPLAY_MISSING=1
    2633ADDITIONAL_LDFLAGS = `imlib2-config --libs`
     34ADDITIONAL_LDADD =
    2735else
    2836if USE_OPENCV
    2937ADDITIONAL_CFLAGS = `opencv-config --cflags`
    3038ADDITIONAL_LDFLAGS = `opencv-config --libs opencv highgui`
     39ADDITIONAL_LDADD =
    3140else
    3241ADDITIONAL_CFLAGS =
    3342ADDITIONAL_LDFLAGS =
     43ADDITIONAL_LDADD =
     44endif
    3445endif
    3546endif
  • pwntcha/trunk/src/image.c

    r427 r435  
    1616#include "common.h"
    1717
    18 #if defined(HAVE_SDL_IMAGE_H)
     18#if defined(WIN32)
     19#   include <windows.h>
     20#   include <ocidl.h>
     21#   include <olectl.h>
     22BOOL oleload(LPCTSTR name, LPPICTURE* pic);
     23struct priv
     24{
     25    HBITMAP bitmap;
     26    BITMAPINFO info;
     27};
     28#elif defined(HAVE_SDL_IMAGE_H)
    1929#   include <SDL_image.h>
    2030#elif defined(HAVE_IMLIB2_H)
     
    3040{
    3141    struct image *img;
    32 #if defined(HAVE_SDL_IMAGE_H)
     42#if defined(WIN32)
     43    struct priv *priv = malloc(sizeof(struct priv));
     44    LPPICTURE pic = NULL;
     45    HDC dc;
     46    long scrwidth = 0, scrheight = 0;
     47    int width, height, i;
     48    void *data = NULL;
     49#elif defined(HAVE_SDL_IMAGE_H)
    3350    SDL_Surface *priv = IMG_Load(name);
    3451#elif defined(HAVE_IMLIB2_H)
     
    4158        return NULL;
    4259
    43 #if defined(HAVE_SDL_IMAGE_H)
     60#if defined(WIN32)
     61    if(!oleload((LPCTSTR)name, &pic))
     62    {
     63        free(priv);
     64        return NULL;
     65    }
     66
     67    dc = CreateCompatibleDC(NULL);
     68
     69    for(i = 0; ; i++)
     70    {
     71        DEVMODE devMode;
     72        devMode.dmSize = sizeof(DEVMODE);
     73
     74        if(EnumDisplaySettings(NULL, i, &devMode) != 1)
     75            break;
     76
     77        /* printf("mode %i x %i - %i\n", (int)devMode.dmPelsWidth,
     78                  (int)devMode.dmPelsHeight, (int)devMode.dmBitsPerPel); */
     79    }
     80
     81    if(GetDeviceCaps(dc, BITSPIXEL) < 24)
     82    {
     83        fprintf(stderr, "a screen depth of at least 24bpp is required\n");
     84        DeleteDC(dc);
     85        free(priv);
     86        return NULL;
     87    }
     88
     89    pic->lpVtbl->get_Width(pic, &scrwidth);
     90    pic->lpVtbl->get_Height(pic, &scrheight);
     91    width = (scrwidth * GetDeviceCaps(dc, LOGPIXELSX) + 2540 / 2) / 2540;
     92    height = (scrheight * GetDeviceCaps(dc, LOGPIXELSY) + 2540 / 2) / 2540;
     93
     94    memset(&priv->info, 0, sizeof(BITMAPINFO));
     95    priv->info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
     96    priv->info.bmiHeader.biBitCount = 24;
     97    priv->info.bmiHeader.biWidth = width;
     98    priv->info.bmiHeader.biHeight = -height;
     99    priv->info.bmiHeader.biCompression = BI_RGB;
     100    priv->info.bmiHeader.biPlanes = 1;
     101
     102    priv->bitmap = CreateDIBSection(dc, &priv->info, DIB_RGB_COLORS, &data, 0, 0);
     103    SelectObject(dc, priv->bitmap);
     104    pic->lpVtbl->Render(pic, dc, 0, 0, width, height,
     105                        0, scrheight, scrwidth, -scrheight, NULL);
     106    pic->lpVtbl->Release(pic);
     107    DeleteDC(dc);
     108#elif defined(HAVE_SDL_IMAGE_H)
    44109    if(priv->format->BytesPerPixel == 1)
    45110    {
     
    51116#endif
    52117
    53     img = malloc(sizeof(struct image));
    54 #if defined(HAVE_SDL_IMAGE_H)
     118    img = (struct image *)malloc(sizeof(struct image));
     119#if defined(WIN32)
     120    img->width = width;
     121    img->height = height;
     122    img->pitch = 3 * width;
     123    img->channels = 3;
     124    img->pixels = data;
     125#elif defined(HAVE_SDL_IMAGE_H)
    55126    img->width = priv->w;
    56127    img->height = priv->h;
     
    80151{
    81152    struct image *img;
    82 #if defined(HAVE_SDL_IMAGE_H)
     153#if defined(WIN32)
     154    struct priv *priv = malloc(sizeof(struct priv));
     155    HDC dc;
     156    void *data = NULL;
     157#elif defined(HAVE_SDL_IMAGE_H)
    83158    SDL_Surface *priv;
    84159    Uint32 rmask, gmask, bmask, amask;
     
    105180        return NULL;
    106181
    107     img = malloc(sizeof(struct image));
    108 #if defined(HAVE_SDL_IMAGE_H)
     182    img = (struct image *)malloc(sizeof(struct image));
     183#if defined(WIN32)
     184    dc = CreateCompatibleDC(NULL);
     185    if(GetDeviceCaps(dc, BITSPIXEL) < 24)
     186    {
     187        fprintf(stderr, "a screen depth of at least 24bpp is required\n");
     188        DeleteDC(dc);
     189        free(priv);
     190        return NULL;
     191    }
     192    priv->info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
     193    priv->info.bmiHeader.biWidth = width;
     194    priv->info.bmiHeader.biHeight = -height;
     195    priv->info.bmiHeader.biCompression = BI_RGB;
     196    priv->info.bmiHeader.biBitCount = 24;
     197    priv->info.bmiHeader.biPlanes = 1;
     198    priv->bitmap = CreateDIBSection(dc, &priv->info,
     199                                    DIB_RGB_COLORS, &data, 0, 0);
     200    DeleteDC(dc);
     201    img->width = width;
     202    img->height = height;
     203    img->pitch = 3 * width;
     204    img->channels = 3;
     205    img->pixels = data;
     206#elif defined(HAVE_SDL_IMAGE_H)
    109207    img->width = priv->w;
    110208    img->height = priv->h;
     
    133231void image_free(struct image *img)
    134232{
    135 #if defined(HAVE_SDL_IMAGE_H)
     233#if defined(WIN32)
     234    struct priv *priv = img->priv;
     235    DeleteObject(priv->bitmap);
     236    free(img->priv);
     237#elif defined(HAVE_SDL_IMAGE_H)
    136238    SDL_FreeSurface(img->priv);
    137239#elif defined(HAVE_IMLIB2_H)
     
    149251void image_save(struct image *img, const char *name)
    150252{
    151 #if defined(HAVE_SDL_IMAGE_H)
     253#if defined(WIN32)
     254
     255#elif defined(HAVE_SDL_IMAGE_H)
    152256    SDL_SaveBMP(img->priv, name);
    153257#elif defined(HAVE_IMLIB2_H)
     
    201305}
    202306
     307#if defined(WIN32)
     308BOOL oleload(LPCTSTR name, LPPICTURE* pic)
     309{
     310    HRESULT ret;
     311    HANDLE h;
     312    DWORD size, read = 0;
     313    LPVOID data;
     314    HGLOBAL buffer;
     315    LPSTREAM stream = NULL;
     316
     317    h = CreateFile(name, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
     318    if (h == INVALID_HANDLE_VALUE)
     319        return FALSE;
     320
     321    size = GetFileSize(h, NULL);
     322    if(size == (DWORD)-1)
     323    {
     324        CloseHandle(h);
     325        return FALSE;
     326    }
     327
     328    buffer = GlobalAlloc(GMEM_MOVEABLE, size);
     329    if(!buffer)
     330    {
     331        CloseHandle(h);
     332        return FALSE;
     333    }
     334
     335    data = GlobalLock(buffer);
     336    if(!data)
     337    {
     338        GlobalUnlock(buffer);
     339        CloseHandle(h);
     340        return FALSE;
     341    }
     342
     343    ret = ReadFile(h, data, size, &read, NULL);
     344    GlobalUnlock(buffer);
     345    CloseHandle(h);
     346
     347    if(!ret)
     348        return FALSE;
     349
     350    ret = CreateStreamOnHGlobal(buffer, TRUE, &stream);
     351    if(!SUCCEEDED(ret))
     352    {
     353        if(stream)
     354            stream->lpVtbl->Release(stream);
     355        return FALSE;
     356    }
     357
     358    if(!stream)
     359        return FALSE;
     360
     361    if(*pic)
     362        (*pic)->lpVtbl->Release(*pic);
     363
     364    ret = OleLoadPicture(stream, size, FALSE, &IID_IPicture, (PVOID *)pic);
     365    stream->lpVtbl->Release(stream);
     366
     367    if(!SUCCEEDED(ret))
     368        return FALSE;
     369
     370    if(!*pic)
     371        return FALSE;
     372
     373    return TRUE;
     374}
     375#endif
     376
Note: See TracChangeset for help on using the changeset viewer.