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; }
filelist_t *get_filelist(const char *path, const char *filter) { DIR *d; struct stat st_in; struct dirent *de; char **names = 0, **tmp; size_t cnt = 0, len = 0; filelist_t *filelist; if (stat(path, &st_in) != 0 ) { OPENDCP_LOG(LOG_DEBUG, "path not found %s", path); return NULL; } if (!S_ISDIR(st_in.st_mode)) { OPENDCP_LOG(LOG_DEBUG, "single file mode"); filelist = filelist_alloc(1); snprintf(filelist->files[0], MAX_FILENAME_LENGTH, "%s", path); return filelist; } if ((d = opendir(path)) == NULL) { return(NULL); } OPENDCP_LOG(LOG_DEBUG, "reading directory"); while ((de = readdir(d))) { if (!file_selector(de->d_name, filter)) { continue; } if (cnt >= len) { len = 2 * len + 1; if (len > SIZE_MAX / sizeof * names) { break; } tmp = realloc(names, len * sizeof * names); if (!tmp) { break; } names = tmp; } names[cnt] = malloc(strlen(de->d_name) + 1); if (!names[cnt]) { break; } snprintf(names[cnt++], strlen(de->d_name) + 1, "%s", de->d_name); OPENDCP_LOG(LOG_DEBUG, "Found %s", de->d_name); } closedir(d); OPENDCP_LOG(LOG_DEBUG, "found %d files", cnt); filelist = filelist_alloc(cnt); if (names) { while (cnt-- > 0) { OPENDCP_LOG(LOG_DEBUG, "Adding file %s", names[cnt]); snprintf(filelist->files[cnt], MAX_FILENAME_LENGTH, "%s/%s", path, names[cnt]); free(names[cnt]); } free(names); } return filelist; }