Skip to content

RGBA capture support#48

Open
bpacholek wants to merge 1 commit intocedricve:masterfrom
bpacholek:rgba_capture_support
Open

RGBA capture support#48
bpacholek wants to merge 1 commit intocedricve:masterfrom
bpacholek:rgba_capture_support

Conversation

@bpacholek
Copy link
Copy Markdown

@bpacholek bpacholek commented Jun 30, 2018

Adds support for the RGBA encoding. Useful for usage together with the Broadcom VideoCore JPEG Encoder (brcmjpeg) from RPi Userland.

For example together with this lib:
https://github.com/ideaconnect/raspijpeg/blob/master/raspijpeg.cpp

For example:

int main()
{
    raspicam::RaspiCam Camera; //Camera object
    Camera.setWidth(1920);
    Camera.setHeight(1080);
    Camera.setCaptureSize(1920, 1080);
    Camera.setFormat(raspicam::RASPICAM_FORMAT_RGBA);
    Camera.open();
    //waiting 3 secs for camera to settle
    sleep(3);
    //capture
    int bufsize = Camera.getImageTypeSize(Camera.getFormat());
    unsigned char *data = new unsigned char[bufsize];
    Camera.grab();
    Camera.retrieve(data); 

  //here some interaction with the data: check, amendments: easier to do with RGBA than YUV

    raspijpeg::jpegdata returndata = raspijpeg::encode(data, bufsize, 1920, 1080, 90, PIXEL_FORMAT_RGBA);
    for (int i = 0; i < returndata.length; i++) {
        cout << returndata.data[i];
    }
}

Without RGBA support it would be needed to add the alpha channel to the RGB array using for example:

void addalpha(unsigned char* rgba, unsigned char* rgb, const int count) {
    for(int i = 0, rgbai = 0 ;i < count; i=i+3, rgbai = rgbai+4) {
        rgba[rgbai] = rgb[i];
        rgba[rgbai+1] = rgb[i+1];
        rgba[rgbai+2] = rgb[i+2];
        rgba[rgbai+3] = 0;
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant