Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RGBA capture support #48

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

RGBA capture support #48

wants to merge 1 commit into from

Conversation

bpacholek
Copy link

@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