Пример #1
0
static void
on_input_frame_ready (CamUnit *super, const CamFrameBuffer *inbuf,
                      const CamUnitFormat *infmt)
{
    dbg(DBG_FILTER, "[%s] iterate\n", cam_unit_get_name(super));
    CamConvertJpegCompress * self = (CamConvertJpegCompress*)super;
    const CamUnitFormat *outfmt = cam_unit_get_output_format(super);

    int width = infmt->width;
    int height = infmt->height;
    int outsize = self->outbuf->length;
    int quality = cam_unit_control_get_int (self->quality_control);

    if (infmt->pixelformat == CAM_PIXEL_FORMAT_RGB)
        _jpeg_compress_8u_rgb (inbuf->data, width, height, infmt->row_stride,
                               self->outbuf->data, &outsize, quality);
    else if (infmt->pixelformat == CAM_PIXEL_FORMAT_BGRA)
        _jpeg_compress_8u_bgra (inbuf->data, width, height, infmt->row_stride,
                                self->outbuf->data, &outsize, quality);
    else if (infmt->pixelformat == CAM_PIXEL_FORMAT_GRAY)
        _jpeg_compress_8u_gray (inbuf->data, width, height, infmt->row_stride,
                                self->outbuf->data, &outsize, quality);

    cam_framebuffer_copy_metadata(self->outbuf, inbuf);
    self->outbuf->bytesused = outsize;

    cam_unit_produce_frame (super, self->outbuf, outfmt);
}
Пример #2
0
static void
on_frame_ready (CamUnitChain *chain, CamUnit *unit, 
        const CamFrameBuffer *buf, void *user_data)
{
    state_t *s = (state_t*) user_data;

    const CamUnitFormat *fmt = cam_unit_get_output_format (unit);

    int64_t now = _timestamp_now ();
    if (now > s->next_publish_utime) {
        camlcm_image_t msg;
        memset (&msg, 0, sizeof (msg));
        msg.width = fmt->width;
        msg.height = fmt->height;
        msg.row_stride = fmt->row_stride;
        msg.data = buf->data;
        msg.size = buf->bytesused;
        msg.pixelformat = fmt->pixelformat;

        camlcm_image_t_publish (s->lcm, "PHONE_THUMB", &msg);

        s->next_publish_utime = now + (int64_t) PUBLISH_INTERVAL_USEC;

        printf ("publish\n");
    }
}
Пример #3
0
static gboolean 
cam_input_example_try_produce_frame (CamUnit *super)
{
    dbg(DBG_INPUT, "iterate\n");
    CamInputExample *self = (CamInputExample*)super;

    int64_t now = _timestamp_now ();
    if (now < self->next_frame_time) return FALSE;

    int64_t frame_delay_usec = 1000000. / self->fps;
    self->next_frame_time += frame_delay_usec;

    const CamUnitFormat *outfmt = cam_unit_get_output_format(super);
    int buf_sz = outfmt->height * outfmt->row_stride;
    CamFrameBuffer *outbuf = cam_framebuffer_new_alloc (buf_sz);
    memset (outbuf->data, 0, buf_sz);
    
    self->x += self->dx;
    int w = cam_unit_control_get_int (self->int1_ctl);
    int excess = self->x + w - outfmt->width + 1;
    if (excess > 0) {
        self->x = outfmt->width - 1 - excess - w;
        self->dx *= -1;
    } else if (self->x < 0) {
        self->x = - self->x;
        self->dx *= -1;
    }

    self->y += self->dy;
    excess = self->y + w - outfmt->height + 1;
    if (excess > 0) {
        self->y = outfmt->height - 1 - excess - w;
        self->dy *= -1;
    } else if (self->y < 0) {
        self->y = - self->y;
        self->dy *= -1;
    }

    uint8_t rgb[3];

    if (cam_unit_control_get_boolean (self->bool_ctl)) {
        rgb[0] = cam_unit_control_get_int (self->int2_ctl);
        rgb[1] = 0;
        rgb[2] = 0;
    } else {
        rgb[0] = 0;
        rgb[1] = rgb[2] = cam_unit_control_get_int (self->int2_ctl);
    };
    _draw_rectangle (outbuf, outfmt, self->x, self->y, w, w, rgb);

    outbuf->bytesused = buf_sz;
    outbuf->timestamp = now;

    cam_unit_produce_frame (super, outbuf, outfmt);
    g_object_unref (outbuf);
    return TRUE;
}