Example #1
0
/** @This loads a uref picture into the specified texture
 * @param uref uref structure describing the picture
 * @param texture GL texture
 * @return false in case of error
 */
bool upipe_gl_texture_load_uref(struct uref *uref, GLuint texture)
{
    const uint8_t *data = NULL;
    size_t width, height;
    uref_pic_size(uref, &width, &height, NULL);
    if(!ubase_check(uref_pic_plane_read(uref, "r8g8b8", 0, 0, -1, -1, &data))) {
        return false;
    }
    glBindTexture(GL_TEXTURE_2D, texture);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, 
            height, 0, GL_RGB, GL_UNSIGNED_BYTE, 
            data);
    uref_pic_plane_unmap(uref, "r8g8b8", 0, 0, -1, -1);

    return true;
}
Example #2
0
/** @This is the rendering function of the Thumbnail
 *
 */
void Thumbnail::render()
{
    if ((uqueue_pop(uqueue2, void *)) != (void *)0){
        printf("send QT signal to terminate the QT thread\n");
        finished();
        return;
    }

    size_t h, v, stride;
    uint8_t hsub, vsub, macropixel_size, macropixel;
    uint8_t *data;
    struct uref *uref = uref_pic_alloc(this->uref_mgr, this->ubuf_mgr, H, V);
    uref_pic_size(uref, &h, &v, &macropixel);
    uref_pic_plane_size(uref, "b8g8r8a8", &stride, &hsub, &vsub, &macropixel_size);
    uref_pic_plane_write(uref, "b8g8r8a8", 0, 0, -1, -1, &data);
    QSize S  = QSize(H, V);
    view.resize(S);

    QPalette palette = view.palette();
    palette.setBrush(QPalette::Background, Qt::transparent);
    view.page()->setPalette(palette);
    view.setAttribute(Qt::WA_OpaquePaintEvent, false);
    view.setAttribute(Qt::WA_NoSystemBackground, false);
    view.setAttribute(Qt::WA_TranslucentBackground, true);
    view.setAutoFillBackground(false);

    QImage image = QImage (data, h, v, stride, QImage::Format_ARGB32);
    image.fill(Qt::transparent);
    QPainter painter(&image);
    view.render(&painter);
    painter.end();

#if 0
    printf("%d %d %d %d \n", data[0], data[1], data[2], data[3]);
#endif

    uref_pic_plane_unmap(uref, "b8g8r8a8", 0, 0, -1, -1);
    uqueue_push(uqueue, uref);
}
Example #3
0
static void fill_pic(struct uref *uref, int counter)
{
    size_t hsize, vsize;
    uint8_t macropixel;
    assert(ubase_check(uref_pic_size(uref, &hsize, &vsize, &macropixel)));

    const char *chroma = NULL;
    while (ubase_check(uref_pic_plane_iterate(uref, &chroma)) && chroma != NULL) {
        size_t stride;
        uint8_t hsub, vsub, macropixel_size;
        assert(ubase_check(uref_pic_plane_size(uref, chroma, &stride, &hsub, &vsub,
                                   &macropixel_size)));
        int hoctets = hsize * macropixel_size / hsub / macropixel;
        uint8_t *buffer;
        assert(ubase_check(uref_pic_plane_write(uref, chroma, 0, 0, -1, -1, &buffer)));

        for (int y = 0; y < vsize / vsub; y++) {
            for (int x = 0; x < hoctets; x++)
                buffer[x] = 1 + (y * hoctets) + x + counter * 5;
            buffer += stride;
        }
        assert(ubase_check(uref_pic_plane_unmap(uref, chroma, 0, 0, -1, -1)));
    }
}
Example #4
0
/** @internal @This handles data from pic allocator.
 *
 * @param upipe description structure of the pipe
 * @param uref uref structure
 * @param upump_p reference to pump that generated the buffer
 */
static void upipe_tblk_handle_pic(struct upipe *upipe, struct uref *uref,
                                  struct upump **upump_p)
{
    struct upipe_tblk *upipe_tblk = upipe_tblk_from_upipe(upipe);

    /* Always operate on the first chroma plane. */
    const char *chroma = NULL;
    if (unlikely(uref->ubuf == NULL ||
                 !ubase_check(ubuf_pic_plane_iterate(uref->ubuf, &chroma)) ||
                 chroma == NULL)) {
        uref_free(uref);
        upipe_throw_error(upipe, UBASE_ERR_INVALID);
        return;
    }

    /* First try the ubuf_mem_shared method. */
    struct ubuf *ubuf = ubuf_block_mem_alloc_from_pic(upipe_tblk->ubuf_mgr,
                                                      uref->ubuf, chroma);
    if (unlikely(ubuf == NULL)) {
        /* We have to memcpy the thing. */
        size_t hsize, vsize, stride;
        uint8_t macropixel, hsub, vsub, macropixel_size;
        if (unlikely(!ubase_check(uref_pic_size(uref, NULL, &vsize,
                                                NULL)) ||
                     !ubase_check(uref_pic_plane_size(uref, chroma,
                             &stride, NULL, &vsub, NULL)))) {
            uref_free(uref);
            upipe_throw_error(upipe, UBASE_ERR_INVALID);
            return;
        }

        size_t size = stride * vsize / vsub;
        ubuf = ubuf_block_alloc(upipe_tblk->ubuf_mgr, size);
        if (unlikely(ubuf == NULL)) {
            uref_free(uref);
            upipe_throw_error(upipe, UBASE_ERR_ALLOC);
            return;
        }

        const uint8_t *r;
        if (unlikely(!ubase_check(uref_pic_plane_read(uref, chroma,
                            0, 0, -1, -1, &r)))) {
            ubuf_free(ubuf);
            uref_free(uref);
            upipe_throw_error(upipe, UBASE_ERR_ALLOC);
            return;
        }

        uint8_t *w;
        int end = -1;
        if (unlikely(!ubase_check(ubuf_block_write(ubuf, 0, &end, &w)))) {
            uref_pic_plane_unmap(uref, chroma, 0, 0, -1, -1);
            ubuf_free(ubuf);
            uref_free(uref);
            upipe_throw_error(upipe, UBASE_ERR_ALLOC);
            return;
        }

        memcpy(w, r, size);
        ubuf_block_unmap(ubuf, 0);
        uref_pic_plane_unmap(uref, chroma, 0, 0, -1, -1);
    }

    uref_attach_ubuf(uref, ubuf);
    upipe_tblk_output(upipe, uref, upump_p);
}
Example #5
0
/** @internal @This handles input.
 *
 * @param upipe description structure of the pipe
 * @param uref uref structure
 * @param upump_p reference to upump structure
 * @return always true
 */
static bool upipe_filter_blend_handle(struct upipe *upipe, struct uref *uref,
                                      struct upump **upump_p)
{
    struct upipe_filter_blend *upipe_filter_blend = upipe_filter_blend_from_upipe(upipe);
    const char *def;
    if (unlikely(ubase_check(uref_flow_get_def(uref, &def)))) {
        upipe_filter_blend_store_flow_def(upipe, NULL);
        upipe_filter_blend_require_ubuf_mgr(upipe, uref);
        return true;
    }

    if (upipe_filter_blend->flow_def == NULL)
        return false;

    const uint8_t *in;
    uint8_t *out;
    uint8_t hsub, vsub, macropixel_size;
    size_t stride_in = 0, stride_out = 0, width, height;
    const char *chroma = NULL;
    struct ubuf *ubuf_deint = NULL;

    // Now process frames
    uref_pic_size(uref, &width, &height, NULL);
    upipe_verbose_va(upipe, "received pic (%zux%zu)", width, height);

    assert(upipe_filter_blend->ubuf_mgr);
    ubuf_deint = ubuf_pic_alloc(upipe_filter_blend->ubuf_mgr, width, height);
    if (unlikely(!ubuf_deint)) {
        upipe_throw_fatal(upipe, UBASE_ERR_ALLOC);
        goto error;
    }

    // Iterate planes
    while (ubase_check(uref_pic_plane_iterate(uref, &chroma)) && chroma) {
        // map all
        if (unlikely(!ubase_check(uref_pic_plane_size(uref, chroma, &stride_in,
                                                &hsub, &vsub, &macropixel_size)))) {
            upipe_err_va(upipe, "Could not read origin chroma %s", chroma);
            goto error;
        }
        if (unlikely(!ubase_check(ubuf_pic_plane_size(ubuf_deint, chroma, &stride_out,
                                                  NULL, NULL, NULL)))) {
            upipe_err_va(upipe, "Could not read dest chroma %s", chroma);
            goto error;
        }
        uref_pic_plane_read(uref, chroma, 0, 0, -1, -1, &in);
        ubuf_pic_plane_write(ubuf_deint, chroma, 0, 0, -1, -1, &out);

        // process plane
        upipe_filter_blend_plane(in, out, stride_in, stride_out, (size_t) height/vsub, macropixel_size);

        // unmap all
        uref_pic_plane_unmap(uref, chroma, 0, 0, -1, -1);
        ubuf_pic_plane_unmap(ubuf_deint, chroma, 0, 0, -1, -1);
    }

    // Attach new ubuf and output frame
    uref_attach_ubuf(uref, ubuf_deint);
    uref_pic_set_progressive(uref);
    uref_pic_delete_tff(uref);

    upipe_filter_blend_output(upipe, uref, upump_p);
    return true;

error:
    uref_free(uref);
    if (ubuf_deint) {
        ubuf_free(ubuf_deint);
    }
    return true;
}