Changeset 10266 for trunk/src


Ignore:
Timestamp:
Oct 6, 2003, 12:09:20 PM (22 years ago)
Author:
sandervl
Message:

PF: GIF and JPEG static libs for IPicture interface implementation

Location:
trunk/src/oleaut32
Files:
80 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/oleaut32/makefile

    r8450 r10266  
    1 # $Id: makefile,v 1.34 2002-05-17 10:16:58 sandervl Exp $
    2 
    3 #
    4 # Odin32 API
    5 #
    6 #       ole32aut.dll makefile
    7 #
     1# Common tools macros. (MAKE_CMD)
     2!include ../../makefile.inc
    83
    94
    10 !if "$(DEBUG)" == "1"
    11 DEFFILE    = oleaut32dbg.def
    12 ORGDEFFILE = oleaut32.def
    13 !endif
    14 
    15 #
    16 # Compiler, tools, and interference rules.
    17 #
    18 !include ../../makefile.inc
    19 
    20 #
    21 # Object files. Prefix with OBJDIR and one space before the '\'.
    22 #
    23 OBJS = \
    24 $(OBJDIR)\oleaut.obj \
    25 $(OBJDIR)\olefont.obj \
    26 $(OBJDIR)\variant.obj \
    27 $(OBJDIR)\ole2disp.obj \
    28 $(OBJDIR)\parsedt.obj \
    29 $(OBJDIR)\olepicture.obj \
    30 $(OBJDIR)\asmutil.obj \
    31 $(OBJDIR)\typelib.obj \
    32 $(OBJDIR)\tmarshal.obj \
    33 $(OBJDIR)\hash.obj \
    34 $(OBJDIR)\safearray.obj \
    35 $(OBJDIR)\connpt.obj \
    36 $(OBJDIR)\dispatch.obj \
    37 $(OBJDIR)\stubs.obj \
    38 !if "$(DEBUG)" == "1"
    39 $(OBJDIR)\dbgwrap.obj \
    40 !endif
    41 $(DLLENTRY) \
    42 $(OBJDIR)\oleaut32rsrc.obj
     5# dummy all rule - invoking nmake withtout target caused it to do all of the targets below..
     6_all: all
    437
    448
    45 #
    46 # Libraries. One space before the '\'.
    47 #
    48 LIBS = \
    49 $(ODIN32_LIB)/advapi32.lib \
    50 $(ODIN32_LIB)/kernel32.lib \
    51 $(ODIN32_LIB)/user32.lib \
    52 $(ODIN32_LIB)/ole32.lib \
    53 $(ODIN32_LIB)/comctl32.lib \
    54 $(ODIN32_LIB)/gdi32.lib \
    55 $(ODIN32_LIB)/guidlib.lib \
    56 $(ODIN32_LIB)/$(ODINCRT).lib \
    57 OS2386.LIB \
    58 $(RTLLIB_O)
     9# Subdirectories.
     10SUBDIRS = \
     11libgif \
     12libjpeg
    5913
    6014
    61 #
    62 # Target and original target names - names of the dll without extention and path
    63 #
    64 TARGET      = olautos2
    65 ORGTARGET   = oleaut32
     15# All the common rules like all, lib, clean and dep.
     16$(COMMONRULES):
     17    @$(DODIRS) "$(SUBDIRS)" $(MAKE_CMD) $@
     18    @$(DOMAKES) "oleautos2.mak" $(MAKE_CMD) $@
    6619
    6720
    68 #
    69 # Includes the common rules.
    70 #
    71 !include $(ODIN32_POST_INC)
    72 
  • trunk/src/oleaut32/olepicture.c

    r9400 r10266  
    4141# include <unistd.h>
    4242#endif
     43#include <stdarg.h>
    4344#include <stdio.h>
    4445#include <string.h>
     46
     47/* Must be before wine includes, the header has things conflicting with
     48 * WINE headers.
     49 */
     50#ifdef HAVE_GIF_LIB_H
     51# include <gif_lib.h>
     52#endif
     53
     54#define NONAMELESSUNION
     55#define NONAMELESSSTRUCT
    4556#include "winerror.h"
     57#include "windef.h"
    4658#include "winbase.h"
    4759#include "wingdi.h"
     
    5062#include "olectl.h"
    5163#include "oleauto.h"
    52 #include "wine/obj_picture.h"
    53 #include "wine/obj_connection.h"
    5464#include "connpt.h"
    5565#include "wine/debug.h"
     
    6373#define UINT8 JPEG_UINT8
    6474#define UINT16 JPEG_UINT16
     75#undef FAR
    6576#ifdef HAVE_JPEGLIB_H
    6677# include <jpeglib.h>
     
    218229        newObject->himetricWidth = pictDesc->u.wmf.xExt;
    219230        newObject->himetricHeight = pictDesc->u.wmf.yExt;
     231        break;
     232
     233      case PICTYPE_NONE:
     234        /* not sure what to do here */
     235        newObject->himetricWidth = newObject->himetricHeight = 0;
    220236        break;
    221237
     
    499515        This, hdc, x, y, cx, cy, xSrc, ySrc, cxSrc, cySrc, prcWBounds);
    500516  if(prcWBounds)
    501     TRACE("prcWBounds (%d,%d) - (%d,%d)\n", prcWBounds->left, prcWBounds->top,
     517    TRACE("prcWBounds (%ld,%ld) - (%ld,%ld)\n", prcWBounds->left, prcWBounds->top,
    502518          prcWBounds->right, prcWBounds->bottom);
    503519
     
    796812
    797813static void _jpeg_skip_input_data(j_decompress_ptr cinfo,long num_bytes) {
    798     ERR("(%ld), should not get here.\n",num_bytes);
     814    TRACE("Skipping %ld bytes...\n", num_bytes);
     815    cinfo->src->next_input_byte += num_bytes;
     816    cinfo->src->bytes_in_buffer -= num_bytes;
    799817}
    800818
     
    805823static void _jpeg_term_source(j_decompress_ptr cinfo) { }
    806824#endif /* HAVE_LIBJPEG */
     825
     826#ifdef HAVE_LIBGIF
     827struct gifdata {
     828    unsigned char *data;
     829    unsigned int curoff;
     830    unsigned int len;
     831};
     832
     833static int _gif_inputfunc(GifFileType *gif, GifByteType *data, int len) {
     834    struct gifdata *gd = (struct gifdata*)gif->UserData;
     835
     836    if (len+gd->curoff > gd->len) {
     837        FIXME("Trying to read %d bytes, but only %d available.\n",len, gd->len-gd->curoff);
     838        len = gd->len - gd->curoff;
     839    }
     840    memcpy(data, gd->data+gd->curoff, len);
     841    gd->curoff += len;
     842    return len;
     843}
     844#endif
    807845
    808846/************************************************************************
     
    822860  DWORD         header[2];
    823861  WORD          magic;
     862  STATSTG       statstg;
    824863  ICOM_THIS_From_IPersistStream(OLEPictureImpl, iface);
    825 
     864 
    826865  TRACE("(%p,%p)\n",This,pStm);
    827866
     867  /* Sometimes we have a header, sometimes we don't. Apply some guesses to find
     868   * out whether we do.
     869   */
     870  hr=IStream_Stat(pStm,&statstg,STATFLAG_NONAME);
     871  if (hr)
     872    FIXME("Stat failed with hres %lx\n",hr);
    828873  hr=IStream_Read(pStm,header,8,&xread);
    829874  if (hr || xread!=8) {
     
    831876      return hr;
    832877  }
    833   xread = 0;
    834   xbuf = This->data = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,header[1]);
    835   This->datalen = header[1];
    836   while (xread < header[1]) {
    837     ULONG nread;
    838     hr = IStream_Read(pStm,xbuf+xread,header[1]-xread,&nread);
    839     xread+=nread;
    840     if (hr || !nread)
    841       break;
    842   }
    843   if (xread != header[1])
    844     FIXME("Could only read %ld of %ld bytes?\n",xread,header[1]);
    845 
     878  if (header[1] > statstg.cbSize.QuadPart) {/* Incorrect header, assume none. */
     879    xread = 8;
     880#ifdef __WIN32OS2__
     881    // PF Can't understand problem here.. Using QuadPart causes all sorts of corruptions.
     882    // Anyway we use only LowPart currently.
     883    xbuf = This->data = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,statstg.cbSize.s.LowPart);
     884#else
     885    xbuf = This->data = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,statstg.cbSize.QuadPart);
     886#endif
     887    memcpy(xbuf,&header,8);
     888#ifdef __WIN32OS2__
     889    This->datalen = statstg.cbSize.s.LowPart;
     890#else
     891    This->datalen = statstg.cbSize.QuadPart;
     892#endif
     893    while (xread < This->datalen) {
     894      ULONG nread;
     895      hr = IStream_Read(pStm,xbuf+xread,This->datalen-xread,&nread);
     896      xread+=nread;
     897      if (hr || !nread)
     898        break;
     899    }
     900    if (xread != This->datalen)
     901      FIXME("Could only read %ld of %d bytes in no-header case?\n",xread,This->datalen);
     902  } else {
     903    xread = 0;
     904    xbuf = This->data = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,header[1]);
     905    This->datalen = header[1];
     906    while (xread < header[1]) {
     907      ULONG nread;
     908      hr = IStream_Read(pStm,xbuf+xread,header[1]-xread,&nread);
     909      xread+=nread;
     910      if (hr || !nread)
     911        break;
     912    }
     913    if (xread != header[1])
     914      FIXME("Could only read %ld of %ld bytes?\n",xread,header[1]);
     915  }
    846916  magic = xbuf[0] + (xbuf[1]<<8);
    847917  switch (magic) {
     918  case 0x4947: { /* GIF */
     919#ifdef HAVE_LIBGIF
     920    struct gifdata      gd;
     921    GifFileType         *gif;
     922    BITMAPINFO          *bmi;
     923    HDC                 hdcref;
     924    LPBYTE              bytes;
     925    int                 i,j,ret;
     926    GifImageDesc        *gid;
     927    SavedImage          *si;
     928    ColorMapObject      *cm;
     929   
     930    gd.data   = xbuf;
     931    gd.curoff = 0;
     932    gd.len    = xread;
     933    gif = DGifOpen((void*)&gd, _gif_inputfunc);
     934    ret = DGifSlurp(gif);
     935    if (ret == GIF_ERROR) {
     936      FIXME("Failed reading GIF using libgif.\n");
     937      return E_FAIL;
     938    }
     939    TRACE("screen height %d, width %d\n", gif->SWidth, gif->SHeight);
     940    TRACE("color res %d, backgcolor %d\n", gif->SColorResolution, gif->SBackGroundColor);
     941    TRACE("imgcnt %d\n", gif->ImageCount);
     942    if (gif->ImageCount<1) {
     943      FIXME("GIF stream does not have images inside?\n");
     944      return E_FAIL;
     945    }
     946    TRACE("curimage: %d x %d, on %dx%d, interlace %d\n",
     947      gif->Image.Width, gif->Image.Height,
     948      gif->Image.Left, gif->Image.Top,
     949      gif->Image.Interlace
     950    );
     951    /* */
     952    bmi  = HeapAlloc(GetProcessHeap(),0,sizeof(BITMAPINFOHEADER)+(1<<gif->SColorResolution)*sizeof(RGBQUAD));
     953    bytes= HeapAlloc(GetProcessHeap(),0,gif->SWidth*gif->SHeight);
     954    si   = gif->SavedImages+0;
     955    gid  = &(si->ImageDesc);
     956    cm   = gid->ColorMap;
     957    if (!cm) cm = gif->SColorMap;
     958    for (i=0;i<(1<<gif->SColorResolution);i++) {
     959      bmi->bmiColors[i].rgbRed = cm->Colors[i].Red;
     960      bmi->bmiColors[i].rgbGreen = cm->Colors[i].Green;
     961      bmi->bmiColors[i].rgbBlue = cm->Colors[i].Blue;
     962    }
     963    /* Map to in picture coordinates */
     964    for (i=0;i<gid->Height;i++)
     965      for (j=0;j<gid->Width;j++)
     966        bytes[(gid->Top+i)*gif->SWidth+gid->Left+j]=si->RasterBits[i*gid->Width+j];
     967    bmi->bmiHeader.biSize               = sizeof(BITMAPINFOHEADER);
     968    bmi->bmiHeader.biWidth              = gif->SWidth;
     969    bmi->bmiHeader.biHeight             = gif->SHeight;
     970    bmi->bmiHeader.biPlanes             = 1;
     971    bmi->bmiHeader.biBitCount           = 8;
     972    bmi->bmiHeader.biCompression        = BI_RGB;
     973    bmi->bmiHeader.biSizeImage          = gif->SWidth*gif->SHeight;
     974    bmi->bmiHeader.biXPelsPerMeter      = 0;
     975    bmi->bmiHeader.biYPelsPerMeter      = 0;
     976    bmi->bmiHeader.biClrUsed            = 1 << gif->SColorResolution;
     977    bmi->bmiHeader.biClrImportant       = 0;
     978
     979    hdcref = GetDC(0);
     980    This->desc.u.bmp.hbitmap=CreateDIBitmap(
     981            hdcref,
     982            &bmi->bmiHeader,
     983            CBM_INIT,
     984            bytes,
     985            bmi,
     986            DIB_PAL_COLORS
     987    );
     988    DeleteDC(hdcref);
     989    This->desc.picType = PICTYPE_BITMAP;
     990    OLEPictureImpl_SetBitmap(This);
     991    DGifCloseFile(gif);
     992    HeapFree(GetProcessHeap(),0,bytes);
     993    return S_OK;
     994#else
     995    FIXME("Trying to load GIF, but no support for libgif/libungif compiled in.\n");
     996    return E_FAIL;
     997#endif
     998    break;
     999  }
    8481000  case 0xd8ff: { /* JPEG */
    8491001#ifdef HAVE_LIBJPEG
     
    8521004    int                                 ret;
    8531005    JDIMENSION                          x;
    854     JSAMPROW                            samprow;
     1006    JSAMPROW                            samprow,oldsamprow;
    8551007    BITMAPINFOHEADER                    bmi;
    8561008    LPBYTE                              bits;
    8571009    HDC                                 hdcref;
    8581010    struct jpeg_source_mgr              xjsm;
     1011    LPBYTE                              oldbits;
     1012    int i;
    8591013
    8601014    /* This is basically so we can use in-memory data for jpeg decompression.
     
    8731027    jd.src = &xjsm;
    8741028    ret=jpeg_read_header(&jd,TRUE);
     1029    jd.out_color_space = JCS_RGB;
    8751030    jpeg_start_decompress(&jd);
    8761031    if (ret != JPEG_HEADER_OK) {
     
    8791034        return E_FAIL;
    8801035    }
    881     bits = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,(jd.output_height+1)*jd.output_width*jd.output_components);
     1036
     1037    bits = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,
     1038                     (jd.output_height+1) * ((jd.output_width*jd.output_components + 3) & ~3) );
    8821039    samprow=HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,jd.output_width*jd.output_components);
     1040
     1041    oldbits = bits;
     1042    oldsamprow = samprow;
    8831043    while ( jd.output_scanline<jd.output_height ) {
    8841044      x = jpeg_read_scanlines(&jd,&samprow,1);
     
    8871047        break;
    8881048      }
    889       memcpy( bits+jd.output_scanline*jd.output_width*jd.output_components,
    890               samprow,
    891               jd.output_width*jd.output_components
    892       );
     1049      /* We have to convert from RGB to BGR, see MSDN/ BITMAPINFOHEADER */
     1050      for(i=0;i<jd.output_width;i++,samprow+=jd.output_components) {
     1051        *(bits++) = *(samprow+2);
     1052        *(bits++) = *(samprow+1);
     1053        *(bits++) = *(samprow);
     1054      }
     1055#ifdef __WIN32OS2__
     1056      bits = (LPBYTE)((unsigned long)(bits + 3) & ~3);
     1057#else
     1058      bits = (LPBYTE)(((UINT_PTR)bits + 3) & ~3);
     1059#endif
     1060      samprow = oldsamprow;
    8931061    }
     1062    bits = oldbits;
     1063
    8941064    bmi.biSize          = sizeof(bmi);
    8951065    bmi.biWidth         =  jd.output_width;
     
    9981168        This->desc.picType = PICTYPE_ICON;
    9991169        This->desc.u.icon.hicon = hicon;
     1170        This->himetricWidth = cifd->idEntries[i].bWidth;
     1171        This->himetricHeight = cifd->idEntries[i].bHeight;
    10001172        hr = S_OK;
    10011173    }
     
    10031175  }
    10041176  default:
    1005     FIXME("Unknown magic %04x\n",magic);
     1177  {
     1178    int i;
     1179    FIXME("Unknown magic %04x, %ld read bytes:\n",magic,xread);
    10061180    hr=E_FAIL;
     1181    for (i=0;i<xread+8;i++) {
     1182        if (i<8) MESSAGE("%02x ",((unsigned char*)&header)[i]);
     1183        else MESSAGE("%02x ",xbuf[i-8]);
     1184        if (i % 10 == 9) MESSAGE("\n");
     1185    }
     1186    MESSAGE("\n");
    10071187    break;
     1188  }
    10081189  }
    10091190
     
    13091490  return hr;
    13101491}
     1492
     1493/*******************************************************************************
     1494 * StdPic ClassFactory
     1495 */
     1496typedef struct
     1497{
     1498    /* IUnknown fields */
     1499    ICOM_VFIELD(IClassFactory);
     1500    DWORD                       ref;
     1501} IClassFactoryImpl;
     1502
     1503static HRESULT WINAPI
     1504SPCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
     1505        ICOM_THIS(IClassFactoryImpl,iface);
     1506
     1507        FIXME("(%p)->(%s,%p),stub!\n",This,debugstr_guid(riid),ppobj);
     1508        return E_NOINTERFACE;
     1509}
     1510
     1511static ULONG WINAPI
     1512SPCF_AddRef(LPCLASSFACTORY iface) {
     1513        ICOM_THIS(IClassFactoryImpl,iface);
     1514        return ++(This->ref);
     1515}
     1516
     1517static ULONG WINAPI SPCF_Release(LPCLASSFACTORY iface) {
     1518        ICOM_THIS(IClassFactoryImpl,iface);
     1519        /* static class, won't be  freed */
     1520        return --(This->ref);
     1521}
     1522
     1523static HRESULT WINAPI SPCF_CreateInstance(
     1524        LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj
     1525) {
     1526        PICTDESC        pd;
     1527
     1528        FIXME("(%p,%p,%s,%p), creating stdpic with PICTYPE_NONE.\n",iface,pOuter,debugstr_guid(riid),ppobj);
     1529        pd.cbSizeofstruct = sizeof(pd);
     1530        pd.picType = PICTYPE_NONE;
     1531        return OleCreatePictureIndirect(&pd,riid,TRUE,ppobj);
     1532
     1533}
     1534
     1535static HRESULT WINAPI SPCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
     1536        ICOM_THIS(IClassFactoryImpl,iface);
     1537        FIXME("(%p)->(%d),stub!\n",This,dolock);
     1538        return S_OK;
     1539}
     1540
     1541static ICOM_VTABLE(IClassFactory) SPCF_Vtbl = {
     1542        ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
     1543        SPCF_QueryInterface,
     1544        SPCF_AddRef,
     1545        SPCF_Release,
     1546        SPCF_CreateInstance,
     1547        SPCF_LockServer
     1548};
     1549static IClassFactoryImpl STDPIC_CF = {&SPCF_Vtbl, 1 };
     1550
     1551void _get_STDPIC_CF(LPVOID *ppv) { *ppv = (LPVOID)&STDPIC_CF; }
Note: See TracChangeset for help on using the changeset viewer.