コード例 #1
0
/** @brief  create_profile.white_point_adjust.bradford
 *
 *  The profile will be generated in many different shades, which will explode
 *  conversion cache.
 */
int      oyProfileAddWhitePointEffect( oyProfile_s       * monitor_profile,
                                       oyOptions_s      ** module_options )
{
  oyProfile_s * wtpt = NULL;
  double        src_XYZ[3] = {0.0, 0.0, 0.0}, dst_XYZ[3] = {0.0, 0.0, 0.0},
                scale = 1.0;
  int error = oyProfile_GetWhitePoint( monitor_profile, src_XYZ );
  int32_t display_white_point = oyGetBehaviour( oyBEHAVIOUR_DISPLAY_WHITE_POINT );
  oyOptions_s * result_opts = NULL, * opts = NULL;
  const char * desc = NULL;

  if(*module_options)
  {
    const char * value = oyOptions_FindString( *module_options, "display_white_point", 0 );
    if(value)
    {
      int c = atoi( value );
      if(c >= 0)
        display_white_point = c;
    }
  }

  if(!display_white_point)
    return 0;

  if(!error)
    error = oyGetDisplayWhitePoint( display_white_point, dst_XYZ );
  if(isnan(dst_XYZ[0]))
    error = 1;
  if(error)
  {
    oyMessageFunc_p( oyMSG_WARN,(oyStruct_s*)monitor_profile, OY_DBG_FORMAT_
                   "automatic display_white_point: not readable", OY_DBG_ARGS_);
    return error;
  }

  desc = oyProfile_GetText( monitor_profile, oyNAME_DESCRIPTION );

  error = oyOptions_SetFromString( &opts, "//" OY_TYPE_STD "/src_name", desc, OY_CREATE_NEW );
  if(error)
    return error;
  DBG_S_( oyPrintTime() );
  {
    int current = -1, choices = 0;
    const char ** choices_string_list = NULL;
    uint32_t flags = 0;
#ifdef HAVE_LOCALE_H
    char * old_loc = strdup(setlocale(LC_ALL,NULL));
    setlocale(LC_ALL,"C");
#endif
    error = oyOptionChoicesGet2( oyWIDGET_DISPLAY_WHITE_POINT, flags,
                                 oyNAME_NAME, &choices,
                                 &choices_string_list, &current );
    if(error > 0)
      oyMessageFunc_p( oyMSG_WARN,(oyStruct_s*)monitor_profile, OY_DBG_FORMAT_
                   "oyOptionChoicesGet2 failed %d", OY_DBG_ARGS_,
                   error);
#ifdef HAVE_LOCALE_H
    setlocale(LC_ALL,old_loc);
    if(old_loc) { free(old_loc); } old_loc = NULL;
#endif
    if(current > 0 && current < choices && choices_string_list)
    {
      if(current == 1) /* automatic */
      {
        double temperature = oyGetTemperature(-1);
        char k[12];
        sprintf(k, "%dK", (int)temperature);
        oyOptions_SetFromString( &opts, "//" OY_TYPE_STD "/illu_name", k, OY_CREATE_NEW );
        if(temperature <= 0.1)
          oyMessageFunc_p( oyMSG_WARN,(oyStruct_s*)monitor_profile, OY_DBG_FORMAT_
                   "automatic display_white_point: [%g %g %g] %s", OY_DBG_ARGS_,
                   dst_XYZ[0], dst_XYZ[1], dst_XYZ[2], k);
      }
      else
        oyOptions_SetFromString( &opts, "//" OY_TYPE_STD "/illu_name", choices_string_list[current], OY_CREATE_NEW );
      if(oy_debug)
        oyMessageFunc_p( oyMSG_DBG,(oyStruct_s*)monitor_profile, OY_DBG_FORMAT_
                   "illu_name: %s", OY_DBG_ARGS_,
                   oyOptions_FindString( opts, "illu_name", 0) );
    }
    oyOptionChoicesFree( oyWIDGET_DISPLAY_WHITE_POINT, &choices_string_list, choices );
  }

  if(oy_debug)
    oyMessageFunc_p( oyMSG_WARN, NULL, OY_DBG_FORMAT_
                   "src_name: %s -> illu_name: %s",
                   OY_DBG_ARGS_, oyOptions_FindString(opts, "src_name", 0), oyOptions_FindString(opts, "illu_name", 0) );
  oyOptions_SetFromDouble( &opts, "//" OY_TYPE_STD "/src_iccXYZ", src_XYZ[0], 0, OY_CREATE_NEW );
  oyOptions_SetFromDouble( &opts, "//" OY_TYPE_STD "/src_iccXYZ", src_XYZ[1], 1, OY_CREATE_NEW );
  oyOptions_SetFromDouble( &opts, "//" OY_TYPE_STD "/src_iccXYZ", src_XYZ[2], 2, OY_CREATE_NEW );
  oyOptions_SetFromDouble( &opts, "//" OY_TYPE_STD "/illu_iccXYZ", dst_XYZ[0], 0, OY_CREATE_NEW );
  oyOptions_SetFromDouble( &opts, "//" OY_TYPE_STD "/illu_iccXYZ", dst_XYZ[1], 1, OY_CREATE_NEW );
  oyOptions_SetFromDouble( &opts, "//" OY_TYPE_STD "/illu_iccXYZ", dst_XYZ[2], 2, OY_CREATE_NEW );
  /* cache the display white point abstract profile */
  error = oyOptions_Handle( "//" OY_TYPE_STD "/create_profile.white_point_adjust.bradford",
                            opts,             "create_profile.white_point_adjust.bradford.file_name",
                            &result_opts );
  DBG_S_( oyPrintTime() );
  if(error > 0)
    oyMessageFunc_p( oyMSG_WARN,(oyStruct_s*)monitor_profile, OY_DBG_FORMAT_
                   "oyOptions_Handle(white_point_adjust.bradford.file_name) failed %d", OY_DBG_ARGS_,
                   error);

  /* write cache profile for slightly better speed and useful for debugging */
  if(error == 0)
  {
    const char * file_name = oyOptions_FindString( result_opts, "file_name", 0 );
    char * cache_path = oyGetInstallPath( oyPATH_CACHE, oySCOPE_USER, oyAllocateFunc_ ), *t;
    if(strstr( cache_path, "device_link") != NULL)
    {
      t = strstr( cache_path, "device_link");
      t[0] = '\000';
      oyStringAddPrintf( &cache_path, 0,0, "white_point_adjust/%s.icc", file_name );
    }

    if(oyIsFile_(cache_path))
    {
      if(oy_debug)
        oyMessageFunc_p( oyMSG_DBG,(oyStruct_s*)monitor_profile, OY_DBG_FORMAT_
                     "found file_name: %s -> %s\n", OY_DBG_ARGS_, file_name, cache_path );
      wtpt = oyProfile_FromFile( cache_path, 0,0 );
      DBG_S_( oyPrintTime() );
    }
  }

  if(!error && wtpt)
  {
    oyOptions_MoveInStruct( module_options,
                          OY_STD "/icc_color/display.icc_profile.abstract.white_point.automatic.oy-monitor",
                          (oyStruct_s**) &wtpt, OY_CREATE_NEW );
    oyOptions_Release( &result_opts );
    oyOptions_Release( &opts );

    return error;
  }

  if(!error && !wtpt)
  {
    /* detect scaling factor
     * - convert monitor device RGB to XYZ,
     * - apply white point adaption matrix,
     * - convert back to monitor device RGB and
     * - again to XYZ to detect clipping and
     * - use that information for scaling inside the white point effect profile */
    oyProfile_s * xyz_profile = oyProfile_FromStd( oyASSUMED_XYZ, 0, 0 );
    float rgb[9] = {1,0,0, 0,1,0, 0,0,1},
          xyz[9] = {0,0,0, 0,0,0, 0,0,0};
    oyDATATYPE_e buf_type = oyFLOAT;
    oyConversion_s * cc_moni2xyz = oyConversion_CreateBasicPixelsFromBuffers(
                              monitor_profile, rgb, oyDataType_m(buf_type),
                              xyz_profile, xyz, oyDataType_m(buf_type),
                              0, 3 );
    oyConversion_s * cc_xyz2moni = oyConversion_CreateBasicPixelsFromBuffers(
                              xyz_profile, xyz, oyDataType_m(buf_type),
                              monitor_profile, rgb, oyDataType_m(buf_type),
                              0, 3 );
    oyMAT3 wtpt_adapt;
    oyCIEXYZ srcWtpt = {src_XYZ[0], src_XYZ[1], src_XYZ[2]},
             dstIllu = {dst_XYZ[0], dst_XYZ[1], dst_XYZ[2]};
    error = !oyAdaptationMatrix( &wtpt_adapt, NULL, &srcWtpt, &dstIllu );
    int i,j;
    for(j = 0; j < 100; ++j)
    {
      oyConversion_RunPixels( cc_moni2xyz, 0 );
      if(oy_debug)
        oyMessageFunc_p( oyMSG_DBG,(oyStruct_s*)cc_moni2xyz, OY_DBG_FORMAT_
                   "rgb->xyz:\nR[%g %g %g] G[%g %g %g] B[%g %g %g]",
                   OY_DBG_ARGS_, xyz[0], xyz[1], xyz[2], xyz[3], xyz[4], xyz[5], xyz[6], xyz[7], xyz[8]);
      oyVEC3 rXYZ, srcXYZ[3] = { {{xyz[0], xyz[1], xyz[2]}}, {{xyz[3], xyz[4], xyz[5]}}, {{xyz[6], xyz[7], xyz[8]}} };
      oyMAT3 wtpt_adapt_scaled,
             scale_mat = {{ {{scale,0,0}}, {{0,scale,0}}, {{0,0,scale}} }};
      oyMAT3per( &wtpt_adapt_scaled, &wtpt_adapt, &scale_mat );
      oyMAT3eval( &rXYZ, &wtpt_adapt_scaled, &srcXYZ[0] ); for(i = 0; i < 3; ++i) xyz[0+i] = rXYZ.n[i];
      oyMAT3eval( &rXYZ, &wtpt_adapt_scaled, &srcXYZ[1] ); for(i = 0; i < 3; ++i) xyz[3+i] = rXYZ.n[i];
      oyMAT3eval( &rXYZ, &wtpt_adapt_scaled, &srcXYZ[2] ); for(i = 0; i < 3; ++i) xyz[6+i] = rXYZ.n[i];
      if(oy_debug)
        oyMessageFunc_p( oyMSG_DBG,(oyStruct_s*)cc_moni2xyz, OY_DBG_FORMAT_
                   "srcWtpt->Illu:\nR[%g %g %g] G[%g %g %g] B[%g %g %g]", OY_DBG_ARGS_,
          xyz[0], xyz[1], xyz[2], xyz[3], xyz[4], xyz[5], xyz[6], xyz[7], xyz[8]);
      oyConversion_RunPixels( cc_xyz2moni, 0 );
      if(oy_debug)
        oyMessageFunc_p( oyMSG_WARN,(oyStruct_s*)cc_moni2xyz, OY_DBG_FORMAT_
                   "xyz->rgb:\nR[%g %g %g] G[%g %g %g] B[%g %g %g] %g",
                   OY_DBG_ARGS_, rgb[0], rgb[1], rgb[2], rgb[3], rgb[4], rgb[5], rgb[6], rgb[7], rgb[8], scale);
      if(rgb[0+0] < 0.99 && rgb[3+1] < 0.99 && rgb[6+2] < 0.99)
      {
        if(scale < 1.00) scale += 0.01;
        break;
      }
      scale -= 0.01;
    }
  }

  oyMessageFunc_p( /*error ?*/ oyMSG_WARN/*:oyMSG_DBG*/,(oyStruct_s*)monitor_profile, OY_DBG_FORMAT_
                   "%s display_white_point: %d [%g %g %g] -> [%g %g %g] * %g %d", OY_DBG_ARGS_,
          desc, display_white_point,
          src_XYZ[0], src_XYZ[1], src_XYZ[2], dst_XYZ[0], dst_XYZ[1], dst_XYZ[2], scale, error);
  if(error > 0)
    return error;

  /* write cache profile for slightly better speed and useful for debugging */
  if(error == 0)
  {
    const char * file_name = oyOptions_FindString( result_opts, "file_name", 0 );
    char * cache_path = oyGetInstallPath( oyPATH_CACHE, oySCOPE_USER, oyAllocateFunc_ ), *t;
    if(strstr( cache_path, "device_link") != NULL)
    {
      t = strstr( cache_path, "device_link");
      t[0] = '\000';
      oyStringAddPrintf( &cache_path, 0,0, "white_point_adjust/%s.icc", file_name );
    }

    {
      error = oyOptions_SetFromDouble( &opts, "//" OY_TYPE_STD "/scale", scale, 0, OY_CREATE_NEW );
      if(oy_debug)
        oyMessageFunc_p( oyMSG_DBG,(oyStruct_s*)monitor_profile, OY_DBG_FORMAT_
                     "creating file_name: %s -> %s\n", OY_DBG_ARGS_, file_name, cache_path );
      error = oyOptions_Handle( "//" OY_TYPE_STD "/create_profile.white_point_adjust.bradford",
                            opts,             "create_profile.white_point_adjust.bradford",
                            &result_opts );
      wtpt = (oyProfile_s*) oyOptions_GetType( result_opts, -1, "icc_profile",
                                           oyOBJECT_PROFILE_S );
      error = !wtpt;
      if(!error)
        oyProfile_ToFile_( (oyProfile_s_*) wtpt, cache_path );
      DBG_S_( oyPrintTime() );
    }
  }

  error = !wtpt;
  if(error == 0)
    oyOptions_MoveInStruct( module_options,
                          OY_STD "/icc_color/display.icc_profile.abstract.white_point.automatic.oy-monitor",
                          (oyStruct_s**) &wtpt, OY_CREATE_NEW );
  oyOptions_Release( &result_opts );
  oyOptions_Release( &opts );

  return error;
}
コード例 #2
0
ファイル: oyranos_policy.c プロジェクト: a17r/oyranos
int main( int argc , char** argv )
{
  int error = 0;
  const char* save_policy = NULL,
            * import_policy = NULL;
  oySCOPE_e scope = oySCOPE_USER;
  size_t size = 0;
  char * xml = NULL;
  char * import_policy_fn = NULL;
  int current_policy = 0, list_policies = 0, list_paths = 0,
      dump_policy = 0;
  int long_help = 0,
      internal_name = 0,
      file_name = 0;
  int verbose = 0;

#ifdef USE_GETTEXT
  setlocale(LC_ALL,"");
#endif
  oyExportStart_(EXPORT_CHECK_NO);

  if(argc >= 2)
  {
    int pos = 1, i;
    char *wrong_arg = 0;
    DBG_PROG1_S("argc: %d\n", argc);
    while(pos < argc)
    {
      switch(argv[pos][0])
      {
        case '-':
            for(i = 1; i < strlen(argv[pos]); ++i)
            switch (argv[pos][i])
            {
              case 'c': current_policy = 1; break;
              case 'd': dump_policy = 1; break;
              case 'e': internal_name = 1; break;
              case 'f': file_name = 1; break;
              case 'i': OY_PARSE_STRING_ARG(import_policy); break;
              case 'l': list_policies = 1; break;
              case 'p': list_paths = 1; break;
              case 's': OY_PARSE_STRING_ARG(save_policy); break;
              case 'v': if(verbose) oy_debug += 1; verbose = 1; break;
              case '-':
                        if(i == 1)
                        {
                             if(OY_IS_ARG("help"))
                        { long_help = 1; i=100; break; }
                        else if(OY_IS_ARG("path"))
                        { list_paths = 1; i=100; break; }
                        else if(OY_IS_ARG("system-wide"))
                        { scope = oySCOPE_SYSTEM; i=100; break; }
                        }
              case 'h':
              default:
                        printfHelp(argc, argv);
                        exit (0);
                        break;
            }
            break;
        default:
                        printfHelp(argc, argv);
                        exit (0);
                        break;
      }
      if( wrong_arg )
      {
       fprintf(stderr, "%s %s\n", _("wrong argument to option:"), wrong_arg);
       printfHelp(argc, argv);
       exit(1);
      }
      ++pos;
    }
  } else
  {
                        printfHelp(argc, argv);
                        exit (0);
  }

  if(verbose)
    fprintf( stderr, "  Oyranos v%s\n",
                  oyNoEmptyName_m_(oyVersionString(1,0)));

  /* check the default paths */
  /*oyPathAdd( OY_PROFILE_PATH_USER_DEFAULT );*/


  /* load the policy file into memory */
  import_policy_fn = oyMakeFullFileDirName_(import_policy);
  if(oyIsFile_(import_policy_fn))
  {
    xml = oyReadFileToMem_( oyMakeFullFileDirName_(import_policy), &size,
                            oyAllocateFunc_ );
    oyDeAllocateFunc_( import_policy_fn );
  }
  /* parse and set policy */
  if(xml)
  {
    oyReadXMLPolicy( oyGROUP_ALL, xml );
    oyDeAllocateFunc_( xml );
  }
  else if ( import_policy )
  {
    error = oyPolicySet( import_policy, 0 );
    if(error)
      fprintf( stderr, "%s:%d could not read file: %s\n",__FILE__,__LINE__, import_policy);
    return 1;
  }

  if(save_policy)
  {
    error = oyPolicySaveActual( oyGROUP_ALL, scope, save_policy );
    if(!error)
      fprintf( stdout, "%s \"%s\"\n",
               _("installed new policy"), save_policy);
    else
      fprintf( stdout, "\"%s\" %s %d\n", save_policy,
               _("installation of new policy file failed with error:"), error);

  } else
  if(current_policy || list_policies || list_paths)
  {
    const char ** names = NULL;
    int count = 0, i, current = -1;
    oyOptionChoicesGet( oyWIDGET_POLICY, &count, &names, &current );

    if(list_policies)
      for(i = 0; i < count; ++i)
      {
        if(file_name)
        {
          char * full_name = NULL;
          error = oyPolicyFileNameGet_( names[i],
                                            &full_name,
                                            oyAllocateFunc_ );
          if(error)
            fprintf(stderr, "%s error: %d\n", names[i], error);
          if(internal_name)
            fprintf(stdout, "%s (%s)\n", names[i], full_name);
          else
            fprintf(stdout, "%s\n", full_name);
          oyFree_m_( full_name );
        } else
          fprintf(stdout, "%s\n", names[i]);
      }

    if(current_policy)
    {
      fprintf( stderr, "%s\n", _("Currently active policy:"));
      if(current >= 0 && file_name)
      {
        char * full_name = NULL;
        error = oyPolicyFileNameGet_( names[current], &full_name,
                                          oyAllocateFunc_ );
        if(internal_name)
          fprintf(stdout, "%s (%s)\n", names[current], full_name);
        else
          fprintf(stdout, "%s\n", full_name);
        oyFree_m_( full_name );
      } else
        fprintf( stdout, "%s\n", current>=0?names[current]:"---");
    }

    if(list_paths)
    {
      char ** path_names = oyDataPathsGet_( &count, "color/settings",
                                              oyALL, oySCOPE_USER_SYS,
                                              oyAllocateFunc_ );
      fprintf(stdout, "%s:\n", _("Policy search paths"));
      for(i = 0; i < count; ++i)
        fprintf(stdout, "%s\n", path_names[i]);

      oyStringListRelease_(&path_names, count, oyDeAllocateFunc_);
    }

  } else
  if(dump_policy)
  {
    size = 0;
    xml = oyPolicyToXML( oyGROUP_ALL, 1, oyAllocateFunc_ );
    DBG_PROG2_S("%s:%d new policy:\n\n",__FILE__,__LINE__);
    fprintf(stdout, "%s\n", xml);

    if(xml) oyDeAllocateFunc_( xml );

  } else
  if(long_help)
  {
    const char * opts[] = {"add_html_header","1",
                           "add_oyranos_title","1",
                           "add_oyranos_copyright","1",
                           NULL};
    size = 0;
    xml = oyDescriptionToHTML( oyGROUP_ALL, opts, oyAllocateFunc_ );
    fprintf(stdout, "%s\n", xml);

    if(xml) oyDeAllocateFunc_( xml );
  }

  oyFinish_( FINISH_IGNORE_I18N | FINISH_IGNORE_CACHES );

  return error;
}