Exemplo n.º 1
0
    virtual ~LVRtfPictDestination()
    {
        if (!_fmt || _buf.empty())
            return;
        // add Image BLOB
        lString16 name(BLOB_NAME_PREFIX); // L"@blob#"
        name << L"image";
        name << lString16::itoa(m_parser.nextImageIndex());
        name << (_fmt==rtf_img_jpeg ? L".jpg" : L".png");
        m_callback->OnBlob(name, _buf.get(), _buf.length());
#if 0
        {
            LVStreamRef stream = LVOpenFileStream((lString16(L"/tmp/") + name).c_str(), LVOM_WRITE);
            stream->Write(_buf.get(), _buf.length(), NULL);
        }
#endif
        m_callback->OnTagOpen(LXML_NS_NONE, L"img");
        m_callback->OnAttribute(LXML_NS_NONE, L"src", name.c_str());
        m_callback->OnTagClose(LXML_NS_NONE, L"img");
    }
Exemplo n.º 2
0
void SaveBitmapToFile( const char * fname, LVGrayDrawBuf * bmp )
{
    if (!bmp)
        return;
    LVStreamRef stream = LVOpenFileStream(fname, LVOM_WRITE);
    if (!stream)
        return;
    int rowsize = ((bmp->GetWidth()+1)/2);
    int img_size = rowsize * bmp->GetHeight();
    int padding = rowsize - rowsize;
    BITMAPFILEHEADER fh;
    struct {
        BITMAPINFOHEADER hdr;
        RGBQUAD colors[16];
    } bmi;
    memset(&fh, 0, sizeof(fh));
    memset(&bmi, 0, sizeof(bmi));
    fh.bfType = 0x4D42;
    fh.bfSize = sizeof(fh) + sizeof(bmi) + img_size;
    fh.bfOffBits = sizeof(fh) + sizeof(bmi);
    bmi.hdr.biSize = sizeof(bmi.hdr);
    bmi.hdr.biWidth = bmp->GetWidth();
    bmi.hdr.biHeight = bmp->GetHeight();
    bmi.hdr.biPlanes = 1;
    bmi.hdr.biBitCount = 4;
    bmi.hdr.biCompression = 0;
    bmi.hdr.biSizeImage = img_size;
    bmi.hdr.biXPelsPerMeter = 0xEC4;
    bmi.hdr.biYPelsPerMeter = 0xEC4;
    bmi.hdr.biClrUsed = 16;
    bmi.hdr.biClrImportant = 16;
    static lUInt8 gray[8] = { 0xFF, 0x00, 0x00, 0x00, 0xFF, 0xAA, 0x55, 0x00 };
    lUInt8 * pal = bmp->GetBitsPerPixel()==1?gray+0:gray+4;
    for (int i=0; i<4; i++)
    {
        bmi.colors[i].rgbBlue = pal[i];
        bmi.colors[i].rgbGreen = pal[i];
        bmi.colors[i].rgbRed = pal[i];
    }
    stream->Write( &fh, sizeof(fh), NULL );
    stream->Write( &bmi, sizeof(bmi), NULL );
    static const lUInt8 dummy[3] = {0,0,0};
    for (int y=0; y<bmp->GetHeight(); y++)
    {
        LVArray<lUInt8> row( (bmp->GetWidth()+1)/2, 0 );
        for ( int x=0; x<bmp->GetWidth(); x++)
        {
            int cl = bmp->GetPixel(x, bmp->GetHeight()-1-y);
            //int cl = (src[x/8] >> ((1-(x&3))*2)) & 3;
            row[x/2] = row[x/2] | (cl << ((x&1)?0:4));
        }
        row[0] = 0x11;
        row[1] = 0x11;
        row[2] = 0x22;
        row[3] = 0x22;
        row[4] = 0x33;
        row[5] = 0x33;
        *stream << row;
        if (padding)
            stream->Write( dummy, padding, NULL );
    }
}