Example #1
0
float* VideoDevice::capture(FrameFormat ff, uchar** cpRawFrame){
    if(!(*cpRawFrame = bgrFrame())) return NULL;

    switch(ff){
      case MONOCHROME:
        bgr_to_monochrome();
        break;
      case HSV:
        bgr_to_hsv();
        break;
      case RGB:
        bgr_to_rgb();
        break;
    }

    return fpFrame;
}
Example #2
0
RGBator::RGBator(unsigned char *data, int width, int height, buffer_type buf_type) {
    memory = (GifByteType *)malloc(sizeof(GifFileType)*width*height*3);
    if (!memory) throw "malloc in RGBator::RGBator failed";
    red = memory;
    green = memory + width*height;
    blue = memory + width*height*2;

    switch (buf_type) {
    case BUF_RGB:
        rgb_to_rgb(data, width, height);
        break;
    case BUF_BGR:
        bgr_to_rgb(data, width, height);
        break;
    case BUF_RGBA:
        rgba_to_rgb(data, width, height);
        break;
    case BUF_BGRA:
        bgra_to_rgb(data, width, height);
        break;
    default:
        throw "Unexpected buf_type in RGBator::RGBator";
    }
};
Example #3
0
void
JpegEncoder::encode()
{
    struct jpeg_compress_struct cinfo;
    struct jpeg_error_mgr jerr;

    cinfo.err = jpeg_std_error(&jerr);

    jpeg_create_compress(&cinfo);
    jpeg_mem_dest(&cinfo, &jpeg, &jpeg_len);

    if (offset.isNull()) {
        cinfo.image_width = width;
        cinfo.image_height = height;
    }
    else {
        cinfo.image_width = offset.w;
        cinfo.image_height = offset.h;
    }
    cinfo.input_components = 3;
    cinfo.in_color_space = JCS_RGB;

    jpeg_set_defaults(&cinfo);
    jpeg_set_quality(&cinfo, quality, TRUE);
    cinfo.smoothing_factor = smoothing;
    jpeg_start_compress(&cinfo, TRUE);

    unsigned char *rgb_data;
    switch (buf_type) {
    case BUF_RGBA:
        rgb_data = rgba_to_rgb(data, width*height*4);
        if (!rgb_data) throw "malloc failed in JpegEncoder::encode/rgba_to_rgb.";
        break;

    case BUF_BGRA:
        rgb_data = bgra_to_rgb(data, width*height*4);
        if (!rgb_data) throw "malloc failed in JpegEncoder::encode/bgra_to_rgb.";
        break;

    case BUF_BGR:
        rgb_data = bgr_to_rgb(data, width*height*3);
        if (!rgb_data) throw "malloc failed in JpegEncoder::encode/bgr_to_rgb.";
        break;

    case BUF_RGB:
        rgb_data = data;
        break;

    default:
        throw "Unexpected buf_type in JpegEncoder::encode";
    }

    JSAMPROW row_pointer;
    int start = 0;
    if (!offset.isNull()) {
        start = offset.y*width*3 + offset.x*3;
    }
    while (cinfo.next_scanline < cinfo.image_height) {
        row_pointer = &rgb_data[start + cinfo.next_scanline*3*width];
        jpeg_write_scanlines(&cinfo, &row_pointer, 1);
    }

    jpeg_finish_compress(&cinfo);
    jpeg_destroy_compress(&cinfo);

    if (buf_type == BUF_BGR || buf_type == BUF_RGBA || buf_type == BUF_BGRA)
        free(rgb_data);
}