/******************************************************************************
 * Function: usbCamSetThumbnailSize
 * Description: This function parses picture width and height from the input
 *              parameters and stores into the context
 *
 * Input parameters:
 *  camHal              - camera HAL handle
 *  params              - QCameraParameters reference
 *
 * Return values:
 *      0   If parameters are valid
 *      -1  If parameters are invalid
 *
 * Notes: none
 *****************************************************************************/
static int usbCamSetThumbnailSize(  camera_hardware_t           *camHal,
                                    const QCameraParameters&    params)
{
    int rc = 0, width, height, i, numThumbnailSizes, validSize;
    char tempStr[FILENAME_LENGTH];
    ALOGD("%s: E", __func__);

    /* parse for thumbnail width and height */
    width = params.getInt(QCameraParameters::KEY_JPEG_THUMBNAIL_WIDTH);
    height = params.getInt(QCameraParameters::KEY_JPEG_THUMBNAIL_HEIGHT);
    ALOGI("%s: Requested thumbnail size %d x %d", __func__, width, height);

    // Validate the thumbnail size
    numThumbnailSizes = sizeof(thumbnail_sizes) / sizeof(camera_size_type);
    for (i = 0, validSize = 0; i <  numThumbnailSizes; i++) {
        if (width ==  thumbnail_sizes[i].width
           && height ==  thumbnail_sizes[i].height) {
            validSize = 1;

            camHal->thumbnailWidth   = width;
            camHal->thumbnailHeight  = height;
            sprintf(tempStr, "%d", camHal->thumbnailWidth);
            camHal->qCamParams.set(QCameraParameters::KEY_JPEG_THUMBNAIL_WIDTH,
                                                        width);
            sprintf(tempStr, "%d", camHal->thumbnailHeight);
            camHal->qCamParams.set(QCameraParameters::KEY_JPEG_THUMBNAIL_HEIGHT,
                                                        height);

        }
    }
    if(!validSize)
        ALOGE("%s: Invalid picture size %dx%d requested", __func__,
            width, height);
    rc = (validSize == 0)? -1:0;
    ALOGD("%s: X", __func__);

    return rc;
} /* usbCamSetThumbnailSize */
/******************************************************************************
 * Function: usbCamSetJpegQlty
 * Description: This function parses picture and thumbnail JPEG quality and
 *              validates before storing in the context
 *
 * Input parameters:
 *  camHal              - camera HAL handle
 *  params              - QCameraParameters reference
 *
 * Return values:
 *      0   If parameters are valid
 *      -1  If parameters are invalid
 *
 * Notes: none
 *****************************************************************************/
static int usbCamSetJpegQlty(   camera_hardware_t           *camHal,
                                const QCameraParameters&    params)
{
    int rc = 0, quality = 0;
    char tempStr[FILENAME_LENGTH];
    ALOGD("%s: E", __func__);

    /**/
    quality = params.getInt(QCameraParameters::KEY_JPEG_QUALITY);
    ALOGI("%s: Requested picture qlty %d", __func__, quality);

    if (quality >= 0 && quality <= 100) {
        camHal->pictJpegQlty = quality;
        sprintf(tempStr, "%d", camHal->pictJpegQlty);
        camHal->qCamParams.set(QCameraParameters::KEY_JPEG_QUALITY, quality);
    } else {
        ALOGE("Invalid jpeg quality=%d", quality);
        rc = -1;
    }

    quality = params.getInt(QCameraParameters::KEY_JPEG_THUMBNAIL_QUALITY);
    ALOGI("%s: Requested thumbnail qlty %d", __func__, quality);

    if (quality >= 0 && quality <= 100) {
        camHal->thumbnailJpegQlty = quality;
        sprintf(tempStr, "%d", camHal->thumbnailJpegQlty);
        camHal->qCamParams.set(QCameraParameters::KEY_JPEG_THUMBNAIL_QUALITY,
                                    tempStr);
    } else {
        ALOGE("Invalid jpeg thumbnail quality=%d", quality);
        rc = -1;
    }

    ALOGD("%s: X rc:%d", __func__, rc);

    return rc;
}