I need to implement a slice-mode JPEG encoding on DM355. The input data frame 2592x1944 is in Bayer format. IPIPE will be used to generate YUV slices from the Bayer data. Later each slice will be fed into the encoder.
My problem is that I cannot figure out the correct way of using slice-mode. Example in the JPEG encoder user guide (in the imgenc\docs\ folder of the codec) is very bad. It is unclear how the input data buffer is specified for the first call to process function.
I tried to compress an image but I the first call to process returns an error.
The entire image corresponds to 39366 MCUs, which corresponds to 128 pixels (256 bytes of YUV) per MCU. In my code, I have defined the slice size to be (2592/16 * 2) * 8 = 2592 MCUs which if I understand correctly corresponds to 128 lines.
dynamicparams.size = sizeof(dynamicparams);
dynamicparams.numAU = XDM_DEFAULT; // number of Access units to encode. // (if want to feed the data in chunks to save buffer space) dynamicparams.inputChromaFormat = XDM_YUV_422ILE; // format of the input data. see enum XDM_ChromaFormat for all formats dynamicparams.inputHeight = height; dynamicparams.inputWidth = width; dynamicparams.captureWidth = 0; // set to zero to use image width. don't know what it's for. dynamicparams.generateHeader = XDM_ENCODE_AU; // don't knwo what it's for but this is what dvtb used. dynamicparams.qValue = Q; // compress JPEG qith quality = 75% memset(&status, 0, sizeof(status)); status.size = sizeof(status); // define the size of status structure res = IMGENC1_control(ieh, XDM_SETPARAMS, &dynamicparams, &status); if (res != IMGENC1_EOK) { printf("Error (%d), Extended Error (%d) in image Encoder Control:setparams\n", res, (int)status.extendedError); IMGENC1_delete(ieh); Engine_close(ceh); CERuntime_exit(); return -1; } printf("CE params set OK\n"); res = IMGENC1_control(ieh, XDM_GETSTATUS, &dynamicparams, &status); if (res != IMGENC1_EOK) { printf("Error (%d), Extended Error (%d) in image Encoder Control:setparams\n", res, (int)status.extendedError); IMGENC1_delete(ieh); Engine_close(ceh); CERuntime_exit(); return -1; } printf("CE get status OK\n"); printf("Total numAU=%d\n", (int)status.totalAU); totalAUslice = status.totalAU; numAUslice = width/16*2 * 8; // multiple value corresponds to 16 lines, we process x8 of that , i.e. 128 lines dynamicparams.size = sizeof(dynamicparams); dynamicparams.numAU = numAUslice; res = IMGENC1_control(ieh, XDM_SETPARAMS, &dynamicparams, &status); if (res != IMGENC1_EOK) { printf("Error (%d), Extended Error (%d) in image Encoder Control:setparams\n", res, (int)status.extendedError); IMGENC1_delete(ieh); Engine_close(ceh); CERuntime_exit(); return -1; } printf("CE params set OK to slice mode\n");
|
Then the slice is encoded using the following code:
int res; IJPEGENC_InArgs inargs; IJPEGENC_OutArgs outargs; if (totalAUslice - currAUslice < numAUslice * 2) { if (totalAUslice - currAUslice != numAUslice) { dynamicparams.size = sizeof(dynamicparams); numAUslice = totalAUslice - currAUslice; dynamicparams.numAU = numAUslice; res = IMGENC1_control(ieh, XDM_SETPARAMS, &dynamicparams, &status); if (res != IMGENC1_EOK) { printf("Error (%d), Extended Error (%d) in image Encoder Control:setparams\n", res, (int)status.extendedError); IMGENC1_delete(ieh); Engine_close(ceh); CERuntime_exit(); return -1; } printf("CE params set OK to slice mode\n"); } inargs.sliceNum = -1; } else inargs.sliceNum = sliceNumber; inargs.imgencInArgs.size = sizeof(inargs); outargs.imgencOutArgs.size = sizeof(outargs); outargs.imgencOutArgs.bytesGenerated = 0; inbufdesc.numBufs = 1; inbufdesc.descs[0].buf = ptr; // pointer to 2592 x 128 x 2 of YUV data inbufdesc.descs[0].bufSize = jpegEncWidth*jpegEncSliceHeight*2; // i.e., 2592*128*2 outbufdesc.numBufs = 1; outbufdesc.descs[0].buf = tmpbuf; // temp buffer outbufdesc.descs[0].bufSize = jpegEncWidth*jpegEncSliceHeight*2; // i.e., 2592*128*2 res = IMGENC1_process(ieh, &inbufdesc, &outbufdesc, (IIMGENC1_InArgs*)&inargs, (IIMGENC1_OutArgs*)&outargs) ; if (res != IMGENC1_EOK) { printf("Error encoding image\n"); IMGENC1_delete(ieh); Engine_close(ceh); CERuntime_exit(); return -1; } currAUslice += numAUslice; sliceNumber++; |
IMGENC1_process return an error.
What could be the problem?
Is there an example or maybe an explanation of the slice-mode method?