Exemplo n.º 1
0
/*
 * vCopy2File
 */
static void
vCopy2File(FILE *pInFile, ULONG ulFileOffset, size_t tPictureLen)
{
    static int	iPicCounter = 0;
    FILE	*pOutFile;
    size_t	tIndex;
    int	iTmp;
    char	szFilename[30];

    if (!bSetDataOffset(pInFile, ulFileOffset)) {
        return;
    }

    sprintf(szFilename, "/tmp/pic/pic%04d.bmp", ++iPicCounter);
    pOutFile = fopen(szFilename, "wb");
    if (pOutFile == NULL) {
        return;
    }
    /* Turn a dib into a bmp by adding a fake 14 byte header */
    (void)putc('B', pOutFile);
    (void)putc('M', pOutFile);
    for (iTmp = 0; iTmp < 12; iTmp++) {
        if (putc(0, pOutFile) == EOF) {
            break;
        }
    }
    for (tIndex = 0; tIndex < tPictureLen; tIndex++) {
        iTmp = iNextByte(pInFile);
        if (putc(iTmp, pOutFile) == EOF) {
            break;
        }
    }
    (void)fclose(pOutFile);
} /* end of vCopy2File */
Exemplo n.º 2
0
/*
 * bTranslateJPEG - translate a JPEG picture
 *
 * This function translates a picture from jpeg to sprite
 *
 * return TRUE when sucessful, otherwise FALSE
 */
BOOL
bTranslateJPEG(diagram_type *pDiag, FILE *pFile,
	ULONG ulFileOffset, size_t tPictureLen, const imagedata_type *pImg)
{
  	/* Seek to start position of JPEG data */
	if (!bSetDataOffset(pFile, ulFileOffset)) {
		return FALSE;
	}

	if (iGetRiscOsVersion() >= 360) {
		return bSave2Draw(pDiag, pFile, tPictureLen, pImg);
	}
  	/* JPEG is not supported until RISC OS 3.6 */
	return bAddDummyImage(pDiag, pImg);
} /* end of bTranslateJPEG */
Exemplo n.º 3
0
/*
 * bTranslateDIB - translate a DIB picture
 *
 * This function translates a picture from dib to eps
 *
 * return TRUE when sucessful, otherwise FALSE
 */
BOOL
bTranslateDIB(diagram_type *pDiag, FILE *pInFile,
              ULONG ulFileOffset, const imagedata_type *pImg)
{
#if defined(DEBUG)
    fail(pImg->tPosition > pImg->tLength);
    vCopy2File(pInFile, ulFileOffset, pImg->tLength - pImg->tPosition);
#endif /* DEBUG */

    /* Seek to start position of DIB data */
    if (!bSetDataOffset(pInFile, ulFileOffset)) {
        return FALSE;
    }

    vImagePrologue(pDiag, pImg);
    vDecodeDIB(pInFile, pDiag->pOutFile, pImg);
    vImageEpilogue(pDiag);

    return TRUE;
} /* end of bTranslateDIB */
Exemplo n.º 4
0
/*
 * bTranslateImage - translate the image
 *
 * This function reads the type of the given image and and gets it translated.
 *
 * return TRUE when sucessful, otherwise FALSE
 */
BOOL
bTranslateImage(diagram_type *pDiag, FILE *pFile, BOOL bMinimalInformation,
        ULONG ulFileOffsetImage, const imagedata_type *pImg)
{
    options_type    tOptions;

    DBG_MSG("bTranslateImage");

    fail(pDiag == NULL);
    fail(pFile == NULL);
    fail(ulFileOffsetImage == FC_INVALID);
    fail(pImg == NULL);
    fail(pImg->iHorSizeScaled <= 0);
    fail(pImg->iVerSizeScaled <= 0);

    vGetOptions(&tOptions);
    fail(tOptions.eImageLevel == level_no_images);

    if (bMinimalInformation) {
        return bAddDummyImage(pDiag, pImg);
    }

    switch (pImg->eImageType) {
    case imagetype_is_jpeg:
    case imagetype_is_png:
        {
            lUInt32 offset = ulFileOffsetImage + pImg->tPosition;
            lUInt32 len = pImg->tLength - pImg->tPosition;

            if (!bSetDataOffset(pFile, offset)) {
                return FALSE;
            }

            lUInt8 *pucJpeg, *pucTmp;
            size_t  tLen;
            int     iByte;

            pucJpeg = (lUInt8*)malloc(len);
            for (pucTmp = pucJpeg, tLen = 0; tLen < len; pucTmp++, tLen++) {
                iByte = iNextByte(pFile);
                if (iByte == EOF) {
                        return FALSE;
                }
                *pucTmp = (UCHAR)iByte;
            }

            // add Image BLOB
            lString16 name(BLOB_NAME_PREFIX); // L"@blob#"
            name << "image";
            name << fmt::decimal(image_index++);
            name << (pImg->eImageType==imagetype_is_jpeg ? ".jpg" : ".png");
            writer->OnBlob(name, pucJpeg, len);
            writer->OnTagOpen(LXML_NS_NONE, L"img");
            writer->OnAttribute(LXML_NS_NONE, L"src", name.c_str());
            writer->OnTagClose(LXML_NS_NONE, L"img");

            free(pucJpeg);
            return TRUE;
        }
     case imagetype_is_dib:
     case imagetype_is_emf:
     case imagetype_is_wmf:
     case imagetype_is_pict:
     case imagetype_is_external:
         /* FIXME */
         return bAddDummyImage(pDiag, pImg);
     case imagetype_is_unknown:
     default:
         DBG_DEC(pImg->eImageType);
         return bAddDummyImage(pDiag, pImg);
     }
} /* end of bTranslateImage */