Esempio n. 1
0
int convert_to_j2k(opendcp_t *opendcp, char *sfile, char *dfile) {
    opendcp_image_t *opendcp_image;
    opendcp_encoder_t *encoder;
    char *extension;
    int result = 0;

    extension = strrchr(dfile, '.');
    extension++;

    if (opendcp_encoder_enable(extension, NULL, opendcp->j2k.encoder)) {
        OPENDCP_LOG(LOG_ERROR, "could not enabled encoder");
    }

    encoder = opendcp_encoder_find(NULL, extension, 0);
    OPENDCP_LOG(LOG_INFO, "using %s encoder (%s) to convert file %s to %s", encoder->name, extension, basename(sfile), basename(dfile));

    OPENDCP_LOG(LOG_DEBUG, "reading input file %s", basename(sfile));
    result = read_image(&opendcp_image, sfile);

    if (result != OPENDCP_NO_ERROR) {
        OPENDCP_LOG(LOG_ERROR, "unable to read file %s", basename(sfile));
        return OPENDCP_ERROR;
    }

    if (!opendcp_image) {
        OPENDCP_LOG(LOG_ERROR, "could not load image");
        return OPENDCP_ERROR;
    }

    /* verify image is dci compliant */
    if (check_image_compliance(opendcp->cinema_profile, opendcp_image, NULL) != OPENDCP_NO_ERROR) {

        /* resize image */
        if (opendcp->j2k.resize) {
            if (resize(&opendcp_image, opendcp->cinema_profile, opendcp->j2k.resize) != OPENDCP_NO_ERROR) {
                opendcp_image_free(opendcp_image);
                return OPENDCP_ERROR;
            }
        }
        else {
            OPENDCP_LOG(LOG_WARN, "the image resolution of %s is not DCI compliant", sfile);
            opendcp_image_free(opendcp_image);
            return OPENDCP_ERROR;
        }
    }

    if (opendcp->j2k.xyz) {
        OPENDCP_LOG(LOG_INFO, "RGB->XYZ color conversion %s", basename(sfile));

        if (rgb_to_xyz(opendcp_image, opendcp->j2k.lut, opendcp->j2k.xyz_method)) {
            OPENDCP_LOG(LOG_ERROR, "color conversion failed %s", basename(sfile));
            opendcp_image_free(opendcp_image);
            return OPENDCP_ERROR;
        }
    }

    result = encoder->encode(opendcp, opendcp_image, dfile);

    opendcp_image_free(opendcp_image);

    if ( result != OPENDCP_NO_ERROR) {
        OPENDCP_LOG(LOG_ERROR, "JPEG2000 conversion failed %s", basename(sfile));
        return OPENDCP_ERROR;
    }

    return OPENDCP_NO_ERROR;
}
Esempio n. 2
0
int convert_to_j2k(opendcp_t *opendcp, char *in_file, char *out_file, char *tmp_path) {
    odcp_image_t *odcp_image;
    int result = 0;

    if (tmp_path == NULL) {
        tmp_path = "./";
    }
    dcp_log(LOG_DEBUG,"%-15.15s: reading input file %s","convert_to_j2k",in_file);
     
    #ifdef OPENMP
    #pragma omp critical
    #endif
    {
    result = read_image(&odcp_image,in_file); 
    }

    if (result != OPENDCP_NO_ERROR) {
        dcp_log(LOG_ERROR,"Unable to read file %s",in_file);
        return OPENDCP_ERROR;
    }

    if (!odcp_image) {
        dcp_log(LOG_ERROR,"Unable to load file %s",in_file);
        return OPENDCP_ERROR;
    }

    /* verify image is dci compliant */
    if (check_image_compliance(opendcp->cinema_profile, odcp_image, NULL) != OPENDCP_NO_ERROR) {
        dcp_log(LOG_WARN,"The image resolution of %s is not DCI Compliant",in_file);

        /* resize image */
        if (opendcp->j2k.resize) {
            if (resize(&odcp_image, opendcp->cinema_profile, opendcp->j2k.resize) != OPENDCP_NO_ERROR) {
                odcp_image_free(odcp_image);
                return OPENDCP_ERROR;
            }
        } else {
            odcp_image_free(odcp_image);
            return OPENDCP_ERROR;
        }
    }
    
    if (opendcp->j2k.xyz) {
        dcp_log(LOG_INFO,"RGB->XYZ color conversion %s",in_file);
        if (rgb_to_xyz(odcp_image,opendcp->j2k.lut,opendcp->j2k.xyz_method)) {
            dcp_log(LOG_ERROR,"Color conversion failed %s",in_file);
            odcp_image_free(odcp_image);
            return OPENDCP_ERROR;
        }
    }

    if ( opendcp->j2k.encoder == J2K_KAKADU ) {
        char tempfile[255];
        sprintf(tempfile,"%s/tmp_%s",tmp_path,basename(in_file));
        dcp_log(LOG_DEBUG,"%-15.15s: Writing temporary tif %s","convert_to_j2k",tempfile);
        result = write_tif(odcp_image,tempfile,0);
        odcp_image_free(odcp_image);
        
        if (result != OPENDCP_NO_ERROR) {
            dcp_log(LOG_ERROR,"Writing temporary tif failed");
            return OPENDCP_ERROR;
        }

        result = encode_kakadu(opendcp, tempfile, out_file);
        if ( result != OPENDCP_NO_ERROR) {
            dcp_log(LOG_ERROR,"Kakadu JPEG2000 conversion failed %s",in_file);
            remove(tempfile);
            return OPENDCP_ERROR;
        }
        remove(tempfile);
    } else {
        opj_image_t *opj_image;
        odcp_to_opj(odcp_image, &opj_image); 
        odcp_image_free(odcp_image);
        if (encode_openjpeg(opendcp,opj_image,out_file) != OPENDCP_NO_ERROR) {
            dcp_log(LOG_ERROR,"OpenJPEG JPEG2000 conversion failed %s",in_file);
            opj_image_destroy(opj_image);
            return OPENDCP_ERROR;
        }        
        opj_image_destroy(opj_image);
    }

    return OPENDCP_NO_ERROR;
}