PassRefPtr<Evas_Object> evasObjectFromCairoImageSurface(Evas* canvas, cairo_surface_t* surface)
{
    EINA_SAFETY_ON_NULL_RETURN_VAL(canvas, 0);
    EINA_SAFETY_ON_NULL_RETURN_VAL(surface, 0);

    cairo_status_t status = cairo_surface_status(surface);
    if (status != CAIRO_STATUS_SUCCESS) {
        EINA_LOG_ERR("cairo surface is invalid: %s", cairo_status_to_string(status));
        return 0;
    }

    cairo_surface_type_t type = cairo_surface_get_type(surface);
    if (type != CAIRO_SURFACE_TYPE_IMAGE) {
        EINA_LOG_ERR("unknown surface type %d, required %d (CAIRO_SURFACE_TYPE_IMAGE).",
            type, CAIRO_SURFACE_TYPE_IMAGE);
        return 0;
    }

    cairo_format_t format = cairo_image_surface_get_format(surface);
    if (format != CAIRO_FORMAT_ARGB32 && format != CAIRO_FORMAT_RGB24) {
        EINA_LOG_ERR("unknown surface format %d, expected %d or %d.",
            format, CAIRO_FORMAT_ARGB32, CAIRO_FORMAT_RGB24);
        return 0;
    }

    int width = cairo_image_surface_get_width(surface);
    int height = cairo_image_surface_get_height(surface);
    int stride = cairo_image_surface_get_stride(surface);
    if (width <= 0 || height <= 0 || stride <= 0) {
        EINA_LOG_ERR("invalid image size %dx%d, stride=%d", width, height, stride);
        return 0;
    }

    void* data = cairo_image_surface_get_data(surface);
    if (!data) {
        EINA_LOG_ERR("could not get source data.");
        return 0;
    }

    RefPtr<Evas_Object> image = adoptRef(evas_object_image_filled_add(canvas));
    if (!image) {
        EINA_LOG_ERR("could not add image to canvas.");
        return 0;
    }

    evas_object_image_colorspace_set(image.get(), EVAS_COLORSPACE_ARGB8888);
    evas_object_image_size_set(image.get(), width, height);
    evas_object_image_alpha_set(image.get(), format == CAIRO_FORMAT_ARGB32);

    if (evas_object_image_stride_get(image.get()) != stride) {
        EINA_LOG_ERR("evas' stride %d diverges from cairo's %d.",
            evas_object_image_stride_get(image.get()), stride);
        return 0;
    }

    evas_object_image_data_copy_set(image.get(), data);

    return image.release();
}
Ejemplo n.º 2
0
static PassRefPtr<Evas_Object> readImageFromStdin(Evas* evas, long imageSize)
{
    OwnArrayPtr<unsigned char> imageBuffer = adoptArrayPtr(new unsigned char[imageSize]);
    if (!imageBuffer)
        abortWithErrorMessage("cannot allocate image");

    const size_t bytesRead = fread(imageBuffer.get(), 1, imageSize, stdin);
    if (!bytesRead)
        return PassRefPtr<Evas_Object>();

    Evas_Object* image = evas_object_image_filled_add(evas);
    evas_object_image_colorspace_set(image, EVAS_COLORSPACE_ARGB8888);
    evas_object_image_memfile_set(image, imageBuffer.get(), bytesRead, 0, 0);

    resizeEcoreEvasIfNeeded(image);

    return adoptRef(image);
}
Ejemplo n.º 3
0
static Evas_Object* differenceImageFromDifferenceBuffer(Evas* evas, unsigned char* buffer, int width, int height)
{
    Evas_Object* image = evas_object_image_filled_add(evas);
    if (!image)
        abortWithErrorMessage("could not create difference image");

    evas_object_image_size_set(image, width, height);
    evas_object_image_colorspace_set(image, EVAS_COLORSPACE_ARGB8888);

    unsigned char* diffPixels = static_cast<unsigned char*>(evas_object_image_data_get(image, EINA_TRUE));
    const int rowStride = evas_object_image_stride_get(image);
    for (int x = 0; x < width; x++) {
        for (int y = 0; y < height; y++) {
            unsigned char* diffPixel = pixelFromImageData(diffPixels, rowStride, x, y);
            diffPixel[Red] = diffPixel[Green] = diffPixel[Blue] = *buffer++;
            diffPixel[Alpha] = 0xff;
        }
    }

    evas_object_image_data_set(image, diffPixels);

    return image;
}
EINTERN Eina_Bool
e_mod_comp_pixmap_rotation_handler_message(Ecore_X_Event_Client_Message *ev)
{
   Ecore_X_Atom type;
   Ecore_X_Window win;
   E_Comp_Win *cw = NULL;
   Ecore_X_Damage dmg;
   Eina_Bool r;

   cw = e_mod_comp_border_client_find(ev->win);
   if (!cw)
     {
        cw = e_mod_comp_win_find(ev->win);
        E_CHECK_RETURN(cw, 0);
     }

   type = ev->message_type;
   win = ev->win;

   if (type == ATOM_CM_PIXMAP_ROTATION_BEGIN)
     {
        E_CHECK_RETURN((!cw->pixrot), 0);

        cw->pixrot = e_mod_comp_pixmap_rotation_new();
        E_CHECK_RETURN(cw->pixrot, 0);

        e_mod_comp_pixmap_rotation_state_set(cw->pixrot, 1);

        edje_object_part_unswallow(cw->shobj, cw->obj);
        _win_unredirect(cw);

        e_mod_comp_pixmap_rotation_done_send
           (win, ATOM_CM_PIXMAP_ROTATION_BEGIN_DONE);
     }
   else if (type == ATOM_CM_PIXMAP_ROTATION_END)
     {
        E_CHECK_RETURN(cw->pixrot, 0);
        e_mod_comp_effect_animating_set(cw->c, cw, EINA_FALSE);
        e_mod_comp_pixmap_rotation_handler_release(cw);
     }
   else if (type == ATOM_CM_PIXMAP_ROTATION_REQUEST)
     {
        E_CHECK_RETURN(cw->pixrot, 0);

        r = e_mod_comp_pixmap_rotation_state_get(cw->pixrot);
        E_CHECK_RETURN(r, 0);

        dmg = e_mod_comp_pixmap_rotation_damage_get(cw->pixrot);
        if (dmg) e_mod_comp_win_del_damage(cw, dmg);

        if (cw->obj)
          edje_object_part_unswallow(cw->shobj, cw->obj);
        else
          {
             E_CHECK_RETURN(cw->c, 0);
             cw->obj = evas_object_image_filled_add(cw->c->evas);
             evas_object_image_colorspace_set(cw->obj, EVAS_COLORSPACE_ARGB8888);

             if (cw->argb)
               evas_object_image_alpha_set(cw->obj, 1);
             else
               evas_object_image_alpha_set(cw->obj, 0);

             evas_object_show(cw->obj);
             evas_object_pass_events_set(cw->obj, 1);
          }

        r = e_mod_comp_pixmap_rotation_request
              (cw->pixrot, ev, cw->c->evas, cw->shobj,
              cw->obj, cw->vis, cw->w, cw->h);
        E_CHECK_RETURN(r, 0);

        e_mod_comp_update_resize(cw->up, cw->w, cw->h);
        e_mod_comp_update_add(cw->up, 0, 0, cw->w, cw->h);

        cw->native = 1;
        dmg = e_mod_comp_pixmap_rotation_damage_get(cw->pixrot);
        E_CHECK_RETURN(dmg, 0);
        e_mod_comp_win_add_damage(cw, dmg);
        e_mod_comp_pixmap_rotation_done_send
          (win, ATOM_CM_PIXMAP_ROTATION_REQUEST_DONE);
     }
   else
     return EINA_FALSE;

   return EINA_TRUE;
}
EINTERN Eina_Bool
e_mod_comp_pixmap_rotation_handler_configure(E_Comp_Win *cw,
                                             int w, int h)
{
   Ecore_X_Window win;
   E_CHECK_RETURN(cw, 0);
   E_CHECK_RETURN(cw->pixrot, 0);
   E_CHECK_RETURN(((w == cw->w) && (h == cw->h)), 0);

   win = e_mod_comp_util_client_xid_get(cw);

   /* backup below obj */
   Eina_Bool bottom = EINA_FALSE;

   Evas_Object *below_obj = evas_object_below_get(cw->shobj);
   if (!below_obj)
     {
        if (evas_object_bottom_get(cw->c->evas) == cw->shobj)
          {
             L(LT_EVENT_X,
               "[COMP] %31s w:0x%08x bd:%s shobj is bottom.\n",
               "PIX_ROT", e_mod_comp_util_client_xid_get(cw),
               cw->bd ? "O" : "X");
             bottom = EINA_TRUE;
          }
     }

   if (cw->obj)
     {
        evas_object_hide(cw->obj);
        evas_object_del(cw->obj);
        cw->obj = NULL;
     }
   if (cw->shobj)
     {
        evas_object_hide(cw->obj);
        evas_object_del(cw->shobj);
        cw->shobj = NULL;
     }

   cw->shobj = edje_object_add(cw->c->evas);
   cw->obj = evas_object_image_filled_add(cw->c->evas);
   evas_object_image_colorspace_set(cw->obj, EVAS_COLORSPACE_ARGB8888);

   if (cw->argb)
     evas_object_image_alpha_set(cw->obj, 1);
   else
     evas_object_image_alpha_set(cw->obj, 0);

   e_mod_comp_win_type_setup(cw);
   e_mod_comp_win_shadow_setup(cw);
   e_mod_comp_win_cb_setup(cw);

   evas_object_show(cw->obj);
   evas_object_pass_events_set(cw->obj, 1);
   evas_object_pass_events_set(cw->shobj, 1);

   /* restore stack */
   if (bottom)
     below_obj = evas_object_below_get(cw->shobj);

   evas_object_stack_above(cw->shobj, below_obj);
   L(LT_EVENT_X,
     "[COMP] %31s w:0x%08x bd:%s shobj restore stack.\n",
     "PIX_ROT", e_mod_comp_util_client_xid_get(cw),
     cw->bd ? "O" : "X");

   e_mod_comp_pixmap_rotation_done_send
     (win, ATOM_CM_PIXMAP_ROTATION_RESIZE_PIXMAP);

   return EINA_TRUE;
}
Ejemplo n.º 6
0
static int
EvasImageSetup( vout_display_t *vd )
{
    vout_display_sys_t *sys = vd->sys;
    char *psz_fcc = var_InheritString( vd, "evas-image-chroma" );

    if( psz_fcc )
    {
        vd->fmt.i_chroma = vlc_fourcc_GetCodecFromString( VIDEO_ES, psz_fcc );
        free( psz_fcc );
    }

    switch( vd->fmt.i_chroma )
    {
        case VLC_CODEC_RGB32:
            sys->u.evas.i_colorspace = EVAS_COLORSPACE_ARGB8888;
            break;
        /* Not implemented yet */
#if 0
        case VLC_CODEC_RGB16:
            sys->u.evas.i_colorspace = EVAS_COLORSPACE_RGB565_A5P;
            break;
#endif
        case VLC_CODEC_YUYV:
            sys->u.evas.i_colorspace = EVAS_COLORSPACE_YCBCR422601_PL;
            sys->u.evas.b_yuv = true;
            break;
        /* FIXME: SIGSEGV in evas_gl_common_texture_nv12_update */
#if 0
        case VLC_CODEC_NV12:
            sys->u.evas.i_colorspace = EVAS_COLORSPACE_YCBCR420NV12601_PL;
            sys->u.evas.b_yuv = true;
            break;
#endif
        case VLC_CODEC_YV12:
            sys->u.evas.i_colorspace = EVAS_COLORSPACE_YCBCR422P601_PL;
            sys->u.evas.b_yuv = true;
            break;
        default:
        case VLC_CODEC_I420:
            sys->u.evas.i_colorspace = EVAS_COLORSPACE_YCBCR422P601_PL;
            vd->fmt.i_chroma = VLC_CODEC_I420;
            sys->u.evas.b_yuv = true;
            break;
    }

    evas_object_image_colorspace_set( sys->p_evas, sys->u.evas.i_colorspace );
    evas_object_image_data_set( sys->p_evas, NULL );

    /* No rotation support with EvasImage */
    sys->b_apply_rotation = true;
    FmtUpdate( vd );

    /* No aspect ratio support with EvasImage */
    vd->info.has_pictures_invalid = true;

    sys->pf_set_data = EvasImageSetData;
    sys->pf_buffers_alloc = EvasImageBuffersAlloc;
    sys->pf_buffers_free = EvasImageBuffersFree;

    msg_Dbg( vd, "using evas_image" );
    return 0;
}