Example #1
0
String ImageBuffer::toDataURL(const String& mimeType, Optional<double> quality, CoordinateSystem) const
{
    ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType));

    cairo_surface_t* image = cairo_get_target(context().platformContext()->cr());

    Vector<char> encodedImage;

    if (!image)
        return "data:,";

    if (mimeType == "image/png") {
        if (!encodeImagePNG(image, &encodedImage))
            return "data:,";
    }

    if (mimeType == "image/jpeg") {
        int width = cairo_image_surface_get_width(image);
        int height = cairo_image_surface_get_height(image);

        IntSize size(width, height);
        IntRect dataRect(IntPoint(), size);
        RefPtr<Uint8ClampedArray> myData = getPremultipliedImageData(dataRect);

        if (!encodeImageJPEG(myData->data(), size, &encodedImage, quality))
            return "data:,";
    }

    Vector<char> base64Data;
    base64Encode(encodedImage, base64Data);

    return "data:" + mimeType + ";base64," + base64Data;
}
void GraphicsContext3D::readPixelsIMG(GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height, GC3Denum format, GC3Denum type, void* data)
{
    // Currently only format=RGBA, type=UNSIGNED_BYTE is supported by the specification: http://www.khronos.org/registry/webgl/specs/latest/
    // If this ever changes, this code will need to be updated.

    // Calculate the strides of our data and canvas
    unsigned formatSize = 4; // RGBA UNSIGNED_BYTE
    unsigned dataStride = width * formatSize;
    unsigned canvasStride = m_currentWidth * formatSize;

    // If we are using a pack alignment of 8, then we need to align our strides to 8 byte boundaries
    // See: http://en.wikipedia.org/wiki/Data_structure_alignment (computing padding)
    int packAlignment;
    glGetIntegerv(GL_PACK_ALIGNMENT, &packAlignment);
    if (8 == packAlignment) {
        dataStride = (dataStride + 7) & ~7;
        canvasStride = (canvasStride + 7) & ~7;
    }

    unsigned char* canvasData = new unsigned char[canvasStride * m_currentHeight];
    ::glReadPixels(0, 0, m_currentWidth, m_currentHeight, format, type, canvasData);

    // If we failed to read our canvas data due to a GL error, don't continue
    int error = glGetError();
    if (GL_NO_ERROR != error) {
        synthesizeGLError(error);
        return;
    }

    // Clear our data in case some of it lies outside the bounds of our canvas
    // TODO: don't do this if all of the data lies inside the bounds of the canvas
    memset(data, 0, dataStride * height);

    // Calculate the intersection of our canvas and data bounds
    IntRect dataRect(x, y, width, height);
    IntRect canvasRect(0, 0, m_currentWidth, m_currentHeight);
    IntRect nonZeroDataRect = intersection(dataRect, canvasRect);

    unsigned xDataOffset = x < 0 ? -x * formatSize : 0;
    unsigned yDataOffset = y < 0 ? -y * dataStride : 0;
    unsigned xCanvasOffset = nonZeroDataRect.x() * formatSize;
    unsigned yCanvasOffset = nonZeroDataRect.y() * canvasStride;
    unsigned char* dst = static_cast<unsigned char*>(data) + xDataOffset + yDataOffset;
    unsigned char* src = canvasData + xCanvasOffset + yCanvasOffset;
    for (int row = 0; row < nonZeroDataRect.height(); row++) {
        memcpy(dst, src, nonZeroDataRect.width() * formatSize);
        dst += dataStride;
        src += canvasStride;
    }

    delete [] canvasData;
}
bool SingleCellViewGraphPanelPlotWidget::resetAxes(const bool &pCanReplot)
{
    // Reset our axes by setting their values to either default ones or to some
    // that allow to see all the graphs

    QRectF dRect = dataRect();

    if (dRect == QRectF()) {
        return setAxes(QRectF(DefMinAxis, DefMinAxis,
                              DefMaxAxis-DefMinAxis, DefMaxAxis-DefMinAxis),
                       pCanReplot);
    } else {
        return setAxes(optimisedRect(dRect), pCanReplot);
    }
}
void SingleCellViewGraphPanelPlotWidget::updateActions()
{
    // Update our actions

    double crtMinX = minX();
    double crtMaxX = maxX();
    double crtMinY = minY();
    double crtMaxY = maxY();

    double crtRangeX = crtMaxX-crtMinX;
    double crtRangeY = crtMaxY-crtMinY;

    mCanZoomInX  = crtRangeX > MinAxisRange;
    mCanZoomOutX = crtRangeX < MaxAxisRange;

    mCanZoomInY  = crtRangeY > MinAxisRange;
    mCanZoomOutY = crtRangeY < MaxAxisRange;

    // Update the enabled status of our actions

    mGui->actionZoomIn->setEnabled(mCanZoomInX || mCanZoomInY);
    mGui->actionZoomOut->setEnabled(mCanZoomOutX || mCanZoomOutY);

    QRectF dRect = dataRect();

    if (dRect == QRectF())
        dRect = QRectF(DefMinAxis, DefMinAxis,
                       DefMaxAxis-DefMinAxis, DefMaxAxis-DefMinAxis);
    else
        dRect = optimisedRect(dRect);

    mGui->actionResetZoom->setEnabled(   (crtMinX != dRect.left())
                                      || (crtMaxX != dRect.left()+dRect.width())
                                      || (crtMinY != dRect.top())
                                      || (crtMaxY != dRect.top()+dRect.height()));
}
/*!
   \brief Calculate a hint for the canvas margin

   Bar charts need to reserve some space for displaying the bars
   for the first and the last sample.  The hint is calculated
   from the layoutHint() depending on the layoutPolicy().

   The margins are in target device coordinates ( pixels on screen )

   \param xMap Maps x-values into pixel coordinates.
   \param yMap Maps y-values into pixel coordinates.
   \param canvasRect Contents rectangle of the canvas in painter coordinates
   \param left Returns the left margin
   \param top Returns the top margin
   \param right Returns the right margin
   \param bottom Returns the bottom margin

   \return Margin

   \sa layoutPolicy(), layoutHint(), QwtPlotItem::Margins
       QwtPlot::getCanvasMarginsHint(), QwtPlot::updateCanvasMargins()
 */
void QwtPlotAbstractBarChart::getCanvasMarginHint( const QwtScaleMap &xMap, 
    const QwtScaleMap &yMap, const QRectF &canvasRect,
    double &left, double &top, double &right, double &bottom ) const
{
    double hint = -1.0;

    switch( layoutPolicy() )
    {
        case ScaleSampleToCanvas:
        {
            if ( orientation() == Qt::Vertical )
                hint = 0.5 * canvasRect.width() * d_data->layoutHint;
            else
                hint = 0.5 * canvasRect.height() * d_data->layoutHint;

            break;
        }
        case FixedSampleSize:
        {
            hint = 0.5 * d_data->layoutHint;
            break;
        }
        case AutoAdjustSamples:
        case ScaleSamplesToAxes:
        default:
        {
            const size_t numSamples = dataSize();
            if ( numSamples <= 0 )
                break;

            // doesn't work for nonlinear scales

            const QRectF br = dataRect();
            double spacing = 0.0;
            double sampleWidthS = 1.0;

            if ( layoutPolicy() == ScaleSamplesToAxes )
            {
                sampleWidthS = qMax( d_data->layoutHint, 0.0 );
            }
            else
            {
                spacing = d_data->spacing;

                if ( numSamples > 1 )
                {
                    sampleWidthS = qAbs( br.width() / ( numSamples - 1 ) );
                }
            }

            double ds, w;
            if ( orientation() == Qt::Vertical )
            {
                ds = qAbs( xMap.sDist() );
                w = canvasRect.width();
            }
            else
            {
                ds = qAbs( yMap.sDist() );
                w = canvasRect.height();
            }

            const double sampleWidthP = ( w - spacing * ds ) 
                * sampleWidthS / ( ds + sampleWidthS );

            hint = 0.5 * sampleWidthP;
            hint += qMax( d_data->margin, 0 );
        }
    }

    if ( orientation() == Qt::Vertical )
    {
        left = right = hint;
        top = bottom = -1.0; // no hint
    }
    else
    {
        left = right = -1.0; // no hint
        top = bottom = hint;
    }
}
Example #6
0
int32
AppView::AddRefsThreadFunc(void* data)
{
	PRINT(("AppView::AddRefsThreadFunc(void*)\n"));

	signal(SIGQUIT,quit_requested);

	BList* dataList = (BList*)data;
	AppView* view = (AppView*)dataList->ItemAt(0);
	BMessage* refsMessage = (BMessage*)dataList->ItemAt(1);

	if(view->LockLooper())
	{
		view->m_list_view->DeselectAll();
		view->UnlockLooper();
	}

	// recurse on refs message
	entry_ref tmp_ref;
	int numRefs = 0;
	EntryRefItem * ref_item = NULL;

	while(refsMessage->FindRef("refs", numRefs++, & tmp_ref) == B_NO_ERROR)
	{
		ref_item = new EntryRefItem (& tmp_ref);
		view->AddRefsHelper(view, ref_item);
	}

	if(view->LockLooper())
	{
		int numItems = view->m_list_view->CountItems();
		float frameWidth = 0.0;
		float frameHeight= 0.0;
		for(int i=0;i<numItems;i++)
		{
			BRect frame = view->m_list_view->ItemFrame(i);
			frameHeight += (frame.Height() + 1.00);

			EntryRefItem* item = (EntryRefItem*)view->m_list_view->ItemAt(i);
			float width = view->m_list_view->StringWidth(item->Text());
			if(width > frameWidth)
			{
				frameWidth = width;
			}
		}
		BRect dataRect(0,0,frameWidth,frameHeight);

		view->m_list_view->SortItems(&AppView::SortFunc);

		view->m_list_view->SetSelectionMessage(NULL);
		AddOnView* addOnView = dynamic_cast<AddOnView*>(view->m_pick_list_view->SelectedView());
		addOnView->ListContentAdded();
		view->m_list_view->SetSelectionMessage(new BMessage(SELECTION_CHANGED));
		view->SelectionChanged();

		view->m_barberpole->Stop();

		view->m_adding--;

		view->UnlockLooper();
	}

	return(B_OK);
}
QRectF QwtPlotSeriesItem::boundingRect() const
{
    return dataRect();
}