示例#1
0
文件: support.c 项目: AbiWord/wv
wvStream *
wvStream_TMP_create (size_t size)
{
  wvStream * stm = NULL;

  char * buf;
  
  buf = wvMalloc(size);
  
  if (buf)
    wvStream_memory_create (&stm, buf, size);

  return stm;
}
示例#2
0
文件: support.c 项目: Distrotech/wv
wvStream *
wvStream_TMP_create (size_t size)
{
  FILE * fp;
  wvStream * stm = NULL;

  fp = tmpfile ();
  
  if (fp) {
    wvStream_FILE_create (&stm, fp);
  } else {
    char * buf;
    
    buf = malloc(size);
    
    if (buf)
      wvStream_memory_create (&stm, buf, size);
  }

  return stm;
}
示例#3
0
U32
wvGetMetafile(MetaFileBlip *amf, MSOFBH *amsofbh, wvStream *fd) {
    char     extra = 0;
    U32      i, count;
    wvStream *stm = 0;
    char     *buf, *p;

    for (i = 0; i < 16; i++)
        amf->m_rgbUid[i] = read_8ubit(fd);
    count = 16;

    amf->m_rgbUidPrimary[0] = 0;

    switch (amsofbh->fbt - msofbtBlipFirst) {
        case msoblipEMF:
            wvTrace(("msoblipEMF\n"));

            /*
               sprintf(buffer,"%s-wv-%d.emf",aimage,no++);
             */
            if (amsofbh->inst ^ msobiEMF)
                extra = 1;
            break;

        case msoblipWMF:
            wvTrace(("msoblipWMF\n"));

            /*
               sprintf(buffer,"%s-wv-%d.wmf",aimage,no++);
             */
            if (amsofbh->inst ^ msobiWMF)
                extra = 1;
            break;

        case msoblipPICT:
            wvTrace(("msoblipPICT\n"));

            /*
               sprintf(buffer,"%s-wv-%d.pict",aimage,no++);
             */
            if (amsofbh->inst ^ msobiPICT)
                extra = 1;
            break;
    }

    if (extra) {
        for (i = 0; i < 16; i++)
            amf->m_rgbUidPrimary[i] = read_8ubit(fd);
        count += 16;
    }


    amf->m_cb = read_32ubit(fd);
    amf->m_rcBounds.bottom = read_32ubit(fd);
    amf->m_rcBounds.top    = read_32ubit(fd);
    amf->m_rcBounds.right  = read_32ubit(fd);
    amf->m_rcBounds.left   = read_32ubit(fd);
    amf->m_ptSize.y        = read_32ubit(fd);
    amf->m_ptSize.x        = read_32ubit(fd);
    amf->m_cbSave          = read_32ubit(fd);
    amf->m_fCompression    = read_8ubit(fd);
    amf->m_fFilter         = read_8ubit(fd);
    amf->m_pvBits          = NULL;
    count += 34;

    buf = malloc(amsofbh->cbLength);
    p   = buf;

    for (i = count; i < amsofbh->cbLength; i++)
        *p++ = read_8ubit(fd);
    count += i;

    wvStream_memory_create(&stm, buf, amsofbh->cbLength);

    amf->m_pvBits = stm;

    return count;
}
示例#4
0
文件: picf.c 项目: gxf/heigong
/* return value: 1 == success 0 == failure */
int
wvGetPICF (wvVersion ver, PICF * apicf, wvStream * fd)
{
    U8 temp;
    U32 i;
    U8 *buf,*p;
    size_t size;

    long pos = wvStream_tell (fd);

    apicf->lcb = read_32ubit (fd);
    apicf->cbHeader = read_16ubit (fd);
    wvTrace (("size of pic is %x (%d)\n", apicf->cbHeader, apicf->cbHeader));
    apicf->mfp_mm = (S16) read_16ubit (fd);
    wvTrace (("mm type is %d\n", apicf->mfp_mm));
    apicf->mfp_xExt = (S16) read_16ubit (fd);
    apicf->mfp_yExt = (S16) read_16ubit (fd);
    apicf->mfp_hMF = (S16) read_16ubit (fd);
    if (apicf->mfp_mm == 99)
	wvGetBITMAP (&(apicf->obj.bitmap), fd);
    else
	wvGetrc (&(apicf->obj.arc), fd);
    apicf->dxaGoal = (S16) read_16ubit (fd);
    apicf->dyaGoal = (S16) read_16ubit (fd);
    apicf->mx = read_16ubit (fd);
    apicf->my = read_16ubit (fd);
    apicf->dxaCropLeft = (S16) read_16ubit (fd);
    apicf->dyaCropTop = (S16) read_16ubit (fd);
    apicf->dxaCropRight = (S16) read_16ubit (fd);
    apicf->dyaCropBottom = (S16) read_16ubit (fd);
    temp = read_8ubit (fd);

    apicf->brcl = temp & 0x0F;
    apicf->fFrameEmpty = (temp & 0x10) >> 4;
    apicf->fBitmap = (temp & 0x20) >> 5;
    wvTrace (("bitmap is %d\n", apicf->fBitmap));
    apicf->fDrawHatch = (temp & 0x40) >> 6;
    apicf->fError = (temp & 0x80) >> 7;

    apicf->bpp = read_8ubit (fd);
    wvGetBRC (ver, &(apicf->brcTop), fd);
    wvGetBRC (ver, &(apicf->brcLeft), fd);
    wvGetBRC (ver, &(apicf->brcBottom), fd);
    wvGetBRC (ver, &(apicf->brcRight), fd);
    apicf->dxaOrigin = (S16) read_16ubit (fd);
    apicf->dyaOrigin = (S16) read_16ubit (fd);
    if (ver == WORD8)
	apicf->cProps = (S16) read_16ubit (fd);
    else
	apicf->cProps = 0;
    pos = wvStream_tell (fd) - pos;
    for (i = pos; i < apicf->cbHeader; i++)
	read_8ubit (fd);
    wvTrace (("pos is finally %x\n", wvStream_tell (fd)));
    wvTrace (("len of data is %d\n", apicf->lcb - apicf->cbHeader));
    wvTrace (
	     ("ends at %x\n",
	      wvStream_tell (fd) + apicf->lcb - apicf->cbHeader));

    i = 0;

    if (apicf->mfp_mm < 90){
	  MSOFBH bse_pic_amsofbh;
	  size_t lHeaderSize;
	  size_t lWordStructsSize;
	  U8 *pHeader;
	  U8 *pWordStructs;

	  U32 len;
	  U32 j;
	  U8 bmp_header[40];
	  U32 header_len;
	  U32 colors_used;
	  U16 bpp;

	  pWordStructs = pHeader = 0;

	  wvTrace (("test\n"));
	  len = apicf->lcb - apicf->cbHeader;
	  
	  /*[email protected] store*/
	  pos = wvStream_tell (fd);

	  i = wvEatOldGraphicHeader (fd, len);
  	  if(i!=-1)/*Found BMP */
	  {
		wvTrace (("len is %d, header len guess is %d\n", len, i));
		if (i + 2 >= len)
		{
			wvTrace (("all read ok methinks\n"));
			apicf->rgb = NULL;
			return 1;
		}
	    len -= i;
		
		pos = wvStream_tell (fd);

		for(j=0;j< sizeof(bmp_header);j++)
			bmp_header[j] = read_8ubit (fd);

		bpp = bmp_header[14] + (bmp_header[15] << 8);

		if ( bpp < 9)
		{
		    colors_used = bmp_header[32] 
			+ (bmp_header[33] << 8)
			+ (bmp_header[34] << 16)
			+ (bmp_header[35] << 24);
		}
		else
		{
		colors_used = 0;
		}
	
		wvStream_goto(fd,pos);  
		
		header_len = 14 + 40 + 4 * colors_used;
		

		/*Get Blip Header Size*/
		lHeaderSize = PutWord8BitmapHeader(apicf, 0, len + i-14, header_len);
		pHeader = malloc(lHeaderSize);
		/*Write Blip Header*/
		PutWord8BitmapHeader(apicf, pHeader, len, header_len);
		
		/*Set Type of FBSE Header*/
		bse_pic_amsofbh.ver  = 0;
		bse_pic_amsofbh.inst = msobiDIB;
		bse_pic_amsofbh.fbt  = msofbtBlipFirst + msoblipDIB;/*msoblipJPEG msoblipPNG*/
		bse_pic_amsofbh.cbLength = lHeaderSize+len;
	  }else{/*must be WMF*/ 

		/*Get Blip Header Size*/
		lHeaderSize = PutWord8MetafileHeader(apicf, 0);
		pHeader = malloc(lHeaderSize);
		/*Write Blip Header*/
		PutWord8MetafileHeader(apicf, pHeader);

		/*Set Type of FBSE Header*/
		bse_pic_amsofbh.ver  = 0;
		bse_pic_amsofbh.inst = msobiWMF; 
		bse_pic_amsofbh.fbt  = msofbtBlipFirst + msoblipWMF; 
		bse_pic_amsofbh.cbLength = lHeaderSize+len;

		i = 0;
  	    wvStream_goto(fd,pos); 
	  }
	  
	  lWordStructsSize = PutWord8Structs(&bse_pic_amsofbh, 0,0);
	  pWordStructs = malloc(lWordStructsSize);	  
	  PutWord8Structs(&bse_pic_amsofbh, pWordStructs, lWordStructsSize);

 	  size = lHeaderSize + lWordStructsSize + apicf->lcb - apicf->cbHeader;
	  p = buf = malloc(size);

	  if(!p)
	  {
		free(pWordStructs);
		free(pHeader);
		return 0;
	  }

	  memcpy(p, pWordStructs, lWordStructsSize);
	  p+= lWordStructsSize;
	  memcpy(p, pHeader, lHeaderSize);
	  p+=lHeaderSize;

	  free(pWordStructs);
	  free(pHeader);
	}
	else{
 		size = apicf->lcb - apicf->cbHeader;
		p = buf = malloc(size);
	}
	
#if 0
	for (; i < apicf->lcb - apicf->cbHeader; i++)
	  *p++ = read_8ubit (fd);
#endif
    U32 length = apicf->lcb - apicf->cbHeader - i; 
    if (fd->kind == GSF_STREAM)
    {
        gsf_input_read (GSF_INPUT (fd->stream.gsf_stream), length, p);
        p += length;
    }
    else if (fd->kind == FILE_STREAM)
    {
        fread(p, sizeof(guint8), length, fd->stream.file_stream);
        p += length;
    }
    else
    {
	    memorystream_read(fd->stream.memory_stream, p, length);
        p += length;
    }
	
/*	f = fopen("test.dat","wb");
	fwrite(buf, 1,size, f);
	fclose(f);
*/	

    wvStream_memory_create(&apicf->rgb, (char*)buf, size); 
    return 1;
}
示例#5
0
文件: picf.c 项目: gxf/heigong
U32 PutWord8Structs(MSOFBH *bse_pic_amsofbh, U8* buf, size_t size)
{
	long count;
	MSOFBH amsofbh,opt_amsofbh,bse_amsofbh;
	FBSE afbse;
	FOPTE *fopte;
	
	wvStream OutStream;
	wvStream *fd;
	U8* int_buf;
	int i;

	if(!bse_pic_amsofbh)
		 return 0;

	count = 0;

	
    if(buf){
		fd = &OutStream;
		int_buf = wvMalloc(size);
		wvStream_memory_create(&fd, (char*)int_buf, size); 
	}
	else
		fd = 0;
	/*Container Data*/
	
	/*Init Data
	*OPT amsofbh*/
	opt_amsofbh.ver=0;
	opt_amsofbh.inst=0;
	opt_amsofbh.fbt = msofbtOPT;
	opt_amsofbh.cbLength = sizeof(FOPTE);
	
	/*OPT*/
	fopte = (FOPTE *) wvMalloc (sizeof (FOPTE) * 2);
	for(i=0;i<2;i++){
	 (fopte)[i].pid=0;
	 (fopte)[i].op=1;/*-i;*/
	 (fopte)[i].fComplex=0;
	 (fopte)[i].fBid=1;/*+i*(79999);*/
	 (fopte)[i].entry=0;
	}

	/*Container amsofbh*/
	amsofbh.ver=0;
	amsofbh.inst=0;
	amsofbh.fbt = msofbtSpContainer;
	amsofbh.cbLength = sizeof(opt_amsofbh) + opt_amsofbh.cbLength;
	
	/*Write Data*/
	/*Container amsofbh*/
	count+=wvPutMSOFBH(&amsofbh, fd); 
	
	/*OPT amsofbh*/
	count+=wvPutMSOFBH(&opt_amsofbh, fd);
	
	/*OPT */
	if(buf)
		wvPutFOPTEArray(&fopte,&opt_amsofbh,fd);
	count+=opt_amsofbh.cbLength;
	wvFree(fopte);

	/*Set Blip Data */
	memset(&afbse,0,sizeof(afbse));
	afbse.btMacOS = 3;
	afbse.btWin32 = 4;
	afbse.cRef    = 1;
	afbse.tag     = 0xff;
	afbse.size = sizeof(*bse_pic_amsofbh) + bse_pic_amsofbh->cbLength;
	
	/*msofbtBSE amsofbh*/
	bse_amsofbh.ver=0;
	bse_amsofbh.inst=0;
	bse_amsofbh.fbt = msofbtBSE;
	bse_amsofbh.cbLength = sizeof(afbse) + afbse.size;

	count+=wvPutMSOFBH(&bse_amsofbh, fd);
	
	if(buf)
	 wvPutFBSE (&afbse, fd);
	count+=sizeof(afbse);
	
	count+=wvPutMSOFBH(bse_pic_amsofbh, fd);
	
	if(buf){
		memcpy(buf, int_buf, size);
	}
	return count;
}