Example #1
0
static
void OpenCGATSFiles(int argc, char *argv[])
{    
    int nParams = argc - xoptind;

    if (nParams >= 1)  {

        hIT8in = cmsIT8LoadFromFile(0, argv[xoptind]);

        if (hIT8in == NULL) 
            FatalError("'%s' is not recognized as a CGATS file", argv[xoptind]);

        nMaxPatches = (int) cmsIT8GetPropertyDbl(hIT8in, "NUMBER_OF_SETS");     
    }

    if (nParams == 2) {

        hIT8out = cmsIT8Alloc(NULL);            
        SetOutputDataFormat();
        strncpy(CGATSoutFilename, argv[xoptind+1], cmsMAX_PATH-1);      
    }

    if (nParams > 2) FatalError("Too many CGATS files");
}
Example #2
0
int parse_it8(const char *filename, chart_t *chart)
{
  int result = 1;
  cmsHANDLE hIT8 = cmsIT8LoadFromFile(NULL, filename);
  if(!hIT8)
  {
    fprintf(stderr, "error loading IT8 file `%s'\n", filename);
    goto error;
  }

  if(cmsIT8TableCount(hIT8) != 1)
  {
    fprintf(stderr, "error with the IT8 file, we only support files with one table at the moment\n");
    goto error;
  }

  dt_colorspaces_color_profile_type_t color_space = DT_COLORSPACE_NONE;
  int column_SAMPLE_ID = -1, column_X = -1, column_Y = -1, column_Z = -1, column_L = -1, column_a = -1,
      column_b = -1;
  char **sample_names = NULL;
  int n_columns = cmsIT8EnumDataFormat(hIT8, &sample_names);

  if(n_columns == -1)
  {
    fprintf(stderr, "error with the IT8 file, can't get column types\n");
    goto error;
  }

  for(int i = 0; i < n_columns; i++)
  {
    if(!g_strcmp0(sample_names[i], "SAMPLE_ID"))
      column_SAMPLE_ID = i;
    else if(!g_strcmp0(sample_names[i], "XYZ_X"))
      column_X = i;
    else if(!g_strcmp0(sample_names[i], "XYZ_Y"))
      column_Y = i;
    else if(!g_strcmp0(sample_names[i], "XYZ_Z"))
      column_Z = i;
    else if(!g_strcmp0(sample_names[i], "LAB_L"))
      column_L = i;
    else if(!g_strcmp0(sample_names[i], "LAB_A"))
      column_a = i;
    else if(!g_strcmp0(sample_names[i], "LAB_B"))
      column_b = i;
  }

  if(column_SAMPLE_ID == -1)
  {
    fprintf(stderr, "error with the IT8 file, can't find the SAMPLE_ID column\n");
    goto error;
  }

  char *columns[3] = { 0 };
  if(column_X != -1 && column_Y != -1 && column_Z != -1)
  {
    color_space = DT_COLORSPACE_XYZ;
    columns[0] = "XYZ_X";
    columns[1] = "XYZ_Y";
    columns[2] = "XYZ_Z";
  }
  else if(column_L != -1 && column_a != -1 && column_b != -1)
  {
    color_space = DT_COLORSPACE_LAB;
    columns[0] = "LAB_L";
    columns[1] = "LAB_A";
    columns[2] = "LAB_B";
  }
  else
  {
    fprintf(stderr, "error with the IT8 file, can't find XYZ or Lab columns\n");
    goto error;
  }

  GHashTableIter table_iter;
  gpointer key, value;

  g_hash_table_iter_init(&table_iter, chart->box_table);
  while(g_hash_table_iter_next(&table_iter, &key, &value))
  {
    box_t *box = (box_t *)value;

    if(cmsIT8GetData(hIT8, key, "SAMPLE_ID") == NULL)
    {
      fprintf(stderr, "error with the IT8 file, can't find sample `%s'\n", (char *)key);
      goto error;
    }

    set_color(box, color_space, cmsIT8GetDataDbl(hIT8, key, columns[0]), cmsIT8GetDataDbl(hIT8, key, columns[1]),
              cmsIT8GetDataDbl(hIT8, key, columns[2]));
  }

  fprintf(stderr, "it8 `%s' done\n", filename);
  goto end;

error:
  result = 0;
end:
  if(hIT8) cmsIT8Free(hIT8);
  return result;
}