/** Function oyFilterNode_ConnectorMatch * @memberof oyFilterNode_s * @brief Check if a connector match to a FilterNode * * @param node_first first node * @param pos_first position of connector from first node * @param plug second connector * * @version Oyranos: 0.1.8 * @since 2008/07/29 (Oyranos: 0.1.8) * @date 2008/07/29 */ OYAPI int OYEXPORT oyFilterNode_ConnectorMatch ( oyFilterNode_s * node_first, int pos_first, oyFilterPlug_s * plug ) { int match = 0; oyConnector_s * a = 0, * b = oyFilterPlugPriv_m(plug)->pattern; char * reg = 0, * tmp = 0; if(node_first && node_first->type_ == oyOBJECT_FILTER_NODE_S && oyFilterNodePriv_m(node_first)->core) a = oyFilterNode_ShowConnector( node_first, pos_first, 0 ); if(a && b) { oyFilterSocket_s * sock_first = oyFilterNode_GetSocket( node_first, pos_first ); oyConnector_s * sock_first_pattern = oyFilterSocketPriv_m(sock_first)->pattern; match = 1; if(!oyConnectorPriv_m(b)->is_plug) match = 0; if(match) { /** Check if basic types match. */ reg = oyStringCopy_( "//", oyAllocateFunc_ ); tmp = oyFilterRegistrationToText( oyConnector_GetReg(a), oyFILTER_REG_TYPE, 0 ); STRING_ADD( reg, tmp ); if(tmp) oyFree_m_( tmp ); match = oyFilterRegistrationMatch( reg, oyConnector_GetReg(b), 0 ); if(reg) oyFree_m_(reg); } /** More detailed checking is done in oyCMMapi5_s. */ if(match && oyConnector_GetMatch(sock_first_pattern)) oyConnector_GetMatch(sock_first_pattern)( sock_first, plug ); oyFilterSocket_Release( &sock_first ); } oyConnector_Release( &a ); return match; }
char * oyFilterNode_GetFallback_( oyFilterNode_s_ * node, int select_core ) { char * fallback = NULL; oyCMMapiFilters_s * apis; int apis_n = 0, i; oyCMMapi9_s_ * cmm_api9_ = 0; char * class_name, * api_reg; oyFilterCore_s_ * core_ = node->core; const char * pattern = core_->registration_; class_name = oyFilterRegistrationToText( pattern, oyFILTER_REG_APPLICATION,0); api_reg = oyStringCopy_("///", oyAllocateFunc_ ); STRING_ADD( api_reg, class_name ); oyFree_m_( class_name ); apis = oyCMMsGetFilterApis_( api_reg, oyOBJECT_CMM_API9_S, oyFILTER_REG_MODE_STRIP_IMPLEMENTATION_ATTR, 0,0 ); oyFree_m_( api_reg ); apis_n = oyCMMapiFilters_Count( apis ); for(i = 0; i < apis_n; ++i) { cmm_api9_ = (oyCMMapi9_s_*) oyCMMapiFilters_Get( apis, i ); if(oyFilterRegistrationMatch( cmm_api9_->pattern, pattern, 0 )) { if(cmm_api9_->oyCMMGetFallback) fallback = cmm_api9_->oyCMMGetFallback( (oyFilterNode_s*)node, 0, select_core, oyAllocateFunc_ ); if(!fallback) WARNc2_S( "%s %s",_("error in module:"), cmm_api9_->registration ); } if(cmm_api9_->release) cmm_api9_->release( (oyStruct_s**)&cmm_api9_ ); } oyCMMapiFilters_Release( &apis ); return fallback; }
uint16_t * oyProfileGetWhitePointRamp( int width, oyProfile_s * p, oyOptions_s * options ) { uint16_t * ramp = calloc( sizeof(uint16_t), width*3); oyImage_s * input = oyImage_Create( width, 1, ramp, OY_TYPE_123_16, p, 0 ); oyImage_s * output = oyImage_Create( width, 1, ramp, OY_TYPE_123_16, p, 0 ); int i,j, error, mul = 65536/width; oyConversion_s * cc = oyConversion_CreateBasicPixels( input, output, options, NULL); for(i = 0; i < width; ++i) { for(j = 0; j < 3; ++j) ramp[i*3 + j] = i * mul; } if(getenv("OY_DEBUG_WRITE")) oyImage_WritePPM( input, "wtpt-effect-raw.ppm", "unaltered gray ramp" ); oyConversion_Correct( cc, "//" OY_TYPE_STD "/icc_color", 0, NULL); error = oyConversion_RunPixels( cc, 0 ); if(error) oyMessageFunc_p( oyMSG_WARN,(oyStruct_s*)p, OY_DBG_FORMAT_ "found issue while converting ramp: %d", OY_DBG_ARGS_, error ); if(getenv("OY_DEBUG_WRITE")) { oyFilterGraph_s * cc_graph = oyConversion_GetGraph( cc ); oyFilterNode_s * icc = oyFilterGraph_GetNode( cc_graph, -1, "///icc_color", 0 ); char * comment = oyjlStringCopy("gray ramp", oyAllocateFunc_); const char * ndesc = oyFilterNode_GetText( icc, oyNAME_NAME ); oyjlStringAdd( &comment, oyAllocateFunc_, oyDeAllocateFunc_, "\n%s", ndesc ); oyImage_WritePPM( input, "wtpt-effect-gray.ppm", comment ); oyFree_m_(comment); oyFilterGraph_Release( &cc_graph ); oyFilterNode_Release( &icc ); } oyImage_Release( &input ); oyImage_Release( &output ); return ramp; }
/** Function oyDeviceSetup2 * @brief activate the device using the stored configuration * * @param[in] device the device * @param[in] options additional options, * - "skip_ask_for_profile == "yes" - skips oyDeviceAskProfile2() call; useful for systems, where no empty profile is possible like CS * @return error * * @version Oyranos: 0.9.7 * @date 2018/02/23 * @since 2009/01/30 (Oyranos: 0.1.10) */ int oyDeviceSetup2 ( oyConfig_s * device, oyOptions_s * options ) { int error = oyDeviceSetup( device, options ); /* modify the VCGT tag */ /* 1. detect if a XCM color server is active */ int active = oyDisplayColorServerIsActive( ); /* 1.1. stop if XCM is active*/ if(active) return error; else { char * tmpname = oyGetTempFileName_( NULL, "vcgt.icc", 0, oyAllocateFunc_ ); oyProfile_s * prof = NULL; const char * profile_name; oyDeviceAskProfile2( device, options, &prof ); profile_name = oyProfile_GetFileName( prof, -1 ); if(oyProfile_CreateEffectVCGT( prof )) oyMessageFunc_p( oyMSG_WARN,(oyStruct_s*)device, OY_DBG_FORMAT_ "Create Effect VCGT failed: %s", OY_DBG_ARGS_, profile_name ); if(oy_debug) oyMessageFunc_p( oyMSG_DBG,(oyStruct_s*)device, OY_DBG_FORMAT_ "%s + modified VCGT -> %s", OY_DBG_ARGS_, profile_name, tmpname ); /* dump altered profile tag to clean memory */ oyProfile_GetSize( prof,0 ); /* write the profile */ oyProfile_ToFile_( (oyProfile_s_*) prof, tmpname ); /* set the gamma table */ oyDeviceSetupVCGT( device, options, tmpname ); if(oy_debug == 0) remove( tmpname ); oyFree_m_( tmpname ); } return error; }
/** @internal * @brief initialise internationalisation * * @since Oyranos: version 0.x.x * @date 26 november 2007 (API 0.0.1) */ void oyI18NInit_() { DBG_PROG_START oy_lang_ = oyStringCopy_("C", oyAllocateFunc_); #ifdef USE_GETTEXT if(!oy_country_ || !oy_language_) { char * temp = 0; if(getenv("OY_LOCALEDIR") && oyStrlen_(getenv("OY_LOCALEDIR"))) oy_domain_path = oyStringCopy_(getenv("OY_LOCALEDIR"), oyAllocateFunc_); oyStringAdd_( &temp, "NLSPATH=", oyAllocateFunc_, oyDeAllocateFunc_); oyStringAdd_( &temp, oy_domain_path, oyAllocateFunc_, oyDeAllocateFunc_); putenv(temp); /* Solaris */ #if 0 if(oy_debug_memory) oyFree_m_(temp); /* putenv requires a static string ??? */ #endif if(oy_debug) WARNc2_S("bindtextdomain( %s, %s )", oy_domain, oy_domain_path ); bindtextdomain( oy_domain, oy_domain_path ); DBG_NUM2_S("oy_domain_path %s %s", oy_domain, oy_domain_path) if(oy_domain_codeset) { if(oy_debug) WARNc2_S("bindtextdomain( %s, %s )", oy_domain, oy_domain_codeset ); bind_textdomain_codeset(oy_domain, oy_domain_codeset); } DBG_NUM2_S("oy_domain_codeset %s %s", oy_domain, oyNoEmptyString_m(oy_domain_codeset)) /* we use the posix setlocale interface; * the environmental LANG variable is flacky */ if(setlocale(LC_MESSAGES, 0)) { if(oy_lang_) oyDeAllocateFunc_(oy_lang_); temp = oyStringCopy_(setlocale(LC_MESSAGES, 0), oyAllocateFunc_); oy_lang_ = temp; } if(oy_lang_) { if(oyStrchr_(oy_lang_,'_')) { char * tmp = 0; int len = oyStrlen_(oy_lang_); oyAllocHelper_m_( tmp, char, len + 5, 0, DBG_PROG_ENDE; return ); oySprintf_( tmp, "%s", oyStrchr_(oy_lang_,'_')+1 ); if(oyStrlen_(tmp) > 2) tmp[2] = 0; oy_country_ = tmp; tmp = 0; /*oy_country_ = oyStringCopy_(oyStrchr_(oy_lang_,'_')+1, oyAllocateFunc_); if(!oy_country_) return;*/ tmp = oyStrchr_(oy_country_,'.'); if(tmp) tmp[0] = 0; tmp = 0; oyAllocHelper_m_( tmp, char, len + 5, 0, DBG_PROG_ENDE; return ); oySprintf_( tmp, "%s", oy_lang_ ); oy_language_ = tmp; tmp = 0; /*oy_language_ = oyStringCopy_(oy_lang_, oyAllocateFunc_); if(!oy_language_) return;*/ tmp = oyStrchr_(oy_language_,'_'); if(tmp) tmp[0] = 0; } else
char * oyJsonFromModelAndUi ( const char * data, const char * ui_text, oyAlloc_f allocate_func ) { char * text = NULL; oyjl_val droot = oyJsonParse( data ), uiroot = oyJsonParse( ui_text ); int paths_n = 0, i; char ** paths = oyJsonPathsFromPattern( uiroot, "groups//options//key"); while(paths && paths[paths_n]) ++paths_n; if(!droot) oyMessageFunc_p( oyMSG_WARN, NULL, OY_DBG_FORMAT_ "ERROR: data\n%s\n", OY_DBG_ARGS_, data ); if(!uiroot) oyMessageFunc_p( oyMSG_WARN, NULL, OY_DBG_FORMAT_ "ERROR: ui_text\n%s\n", OY_DBG_ARGS_, ui_text ); for(i = 0; i < paths_n; ++i) { char * path = paths[i]; /* get the key node */ oyjl_val uiv = oyjlTreeGetValue( uiroot, 0, path ), dv = NULL, v = NULL; /* get the key name */ char * key = oyjlValueText( uiv, oyAllocateFunc_ ), * value = NULL; /* get the value node by the key */ if(key) dv = oyjlTreeGetValue( droot, 0, key ); /* get the value */ if(dv) value = oyjlValueText( dv, oyAllocateFunc_ ); /* write the value into the options "default" key */ if(value && key && strchr(key,'/')) { char * t = strrchr(path,'/'); t[0] = 0; v = oyjlTreeGetValueF( uiroot, OYJL_CREATE_NEW, "%s/default", path ); oyjlValueSetString( v, value ); } if(key) oyFree_m_( key ); if(value) oyFree_m_( value ); } i = 0; oyjlTreeToJson( uiroot, &i, &text ); oyjlTreeFree( uiroot ); oyjlTreeFree( droot ); oyjlStringListRelease( &paths, paths_n, free ); if(allocate_func && allocate_func != oyAllocateFunc_) { char * t = oyStringCopy( text, allocate_func ); oyDeAllocateFunc_(text); text = t; t = 0; } return text; }
int main( int argc , char** argv ) { char *display_name = 0; char *monitor_profile = 0; int error = 0; /* the functional switches */ int erase = 0; int unset = 0; int list = 0; int setup = 0; int daemon = 0; char * format = 0; char * output = 0; int server = 0; int x_color_region_target = 0; int device_meta_tag = 0; char * add_meta = 0, * prof_name = 0, * module_name = 0, * new_profile_name = 0; char * device_class = 0; int list_modules = 0; int list_taxi = 0; int verbose = 0; int simple = 0; char *ptr = NULL; int x = 0, y = 0; int device_pos = -1; char *oy_display_name = NULL; oyProfile_s * prof = 0; oyConfig_s * device = 0; oyConfigs_s * devices = 0; oyOptions_s * options = 0; oyConfig_s * c = 0; oyOption_s * o = 0; size_t size = 0; const char * filename = 0; char * data = 0; uint32_t n = 0; int i; uint32_t icc_profile_flags = 0; oySCOPE_e scope = oySCOPE_USER; if(getenv(OY_DEBUG)) { int value = atoi(getenv(OY_DEBUG)); if(value > 0) oy_debug += value; } #ifdef USE_GETTEXT setlocale(LC_ALL,""); #endif oyI18NInit_(); STRING_ADD( device_class, "monitor._native" ); if(getenv("DISPLAY")) display_name = strdup(getenv("DISPLAY")); if(argc != 1) { int pos = 1; const char *wrong_arg = 0; while(pos < argc) { switch(argv[pos][0]) { case '-': for(i = 1; i < strlen(argv[pos]); ++i) switch (argv[pos][i]) { case '2': icc_profile_flags |= OY_ICC_VERSION_2; break; case '4': icc_profile_flags |= OY_ICC_VERSION_4; break; case 'e': erase = 1; monitor_profile = 0; break; case 'c': x_color_region_target = 1; monitor_profile = 0; break; case 'd': server = 1; OY_PARSE_INT_ARG( device_pos ); break; case 'f': OY_PARSE_STRING_ARG(format); monitor_profile = 0; break; case 'l': list = 1; monitor_profile = 0; break; case 'm': device_meta_tag = 1; break; case 'o': OY_PARSE_STRING_ARG(output); monitor_profile = 0; break; case 'u': unset = 1; monitor_profile = 0; break; case 'x': server = 1; OY_PARSE_INT_ARG( x ); break; case 'y': server = 1; OY_PARSE_INT_ARG( y ); break; case 'v': if(verbose) oy_debug += 1; verbose = 1; break; case 's': setup = 1; break; /* implicite -> setup */ case 'h': case '-': if(i == 1) { if(OY_IS_ARG("erase")) { erase = 1; monitor_profile = 0; i=100; break; } else if(OY_IS_ARG("unset")) { unset = 1; monitor_profile = 0; i=100; break; } else if(strcmp(&argv[pos][2],"x_color_region_target") == 0) { x_color_region_target = 1; i=100; break; } else if(OY_IS_ARG("setup")) { setup = 1; i=100; break; } else if(OY_IS_ARG("daemon")) { daemon = 1; i=100; break; } else if(OY_IS_ARG("format")) { OY_PARSE_STRING_ARG2(format, "format"); break; } else if(OY_IS_ARG("output")) { OY_PARSE_STRING_ARG2(output, "output"); break; } else if(OY_IS_ARG("add-edid")) { OY_PARSE_STRING_ARG2(add_meta,"add-edid"); break; } else if(OY_IS_ARG("name")) { OY_PARSE_STRING_ARG2(new_profile_name, "name"); break; } else if(OY_IS_ARG("profile")) { OY_PARSE_STRING_ARG2(prof_name, "profile"); break; } else if(OY_IS_ARG("display")) { const char * t=0; OY_PARSE_STRING_ARG2(t, "display"); if(t) {display_name = strdup(t);} break; } else if(OY_IS_ARG("modules")) { list_modules = 1; i=100; break; } else if(OY_IS_ARG("module")) { OY_PARSE_STRING_ARG2(module_name, "module"); break; } else if(OY_IS_ARG("list")) { list = 1; monitor_profile = 0; i=100; break; } else if(OY_IS_ARG("list-taxi")) { list_taxi = 1; i=100; break; } else if(OY_IS_ARG("path")) { simple = 2; i=100; break;} else if(OY_IS_ARG("short")) { simple = 1; i=100; break;} else if(OY_IS_ARG("verbose")) { if(verbose) {oy_debug += 1;} verbose = 1; i=100; break;} else if(OY_IS_ARG("system-wide")) { scope = oySCOPE_SYSTEM; i=100; break; } } default: printf("\n"); printf("oyranos-monitor v%d.%d.%d %s\n", OYRANOS_VERSION_A,OYRANOS_VERSION_B,OYRANOS_VERSION_C, _("is a color profile administration tool for monitors")); printf("%s:\n", _("Usage")); printf(" %s\n", _("Set new profile:")); printf(" %s [-x pos -y pos | -d number] [--system-wide] %s\n", argv[0], _("profile name")); printf("\n"); printf(" %s\n", _("Erase profile:")); printf(" %s -e [-x pos -y pos | -d number] [--system-wide]\n", argv[0]); printf("\n"); printf(" %s\n", _("Activate profiles:")); printf(" %s [-x pos -y pos | -d number]\n", argv[0]); printf("\n"); printf(" %s\n", _("List devices:")); printf(" %s -l [-x pos -y pos | -d number] [--short|--path]\n", argv[0]); /* --short argument */ printf(" --short %s\n", _("print only the file name")); /* --path argument */ printf(" --path %s\n", _("print the full file name")); printf("\n"); printf(" %s\n", _("List Taxi DB profiles for selected device:")); printf(" %s --list-taxi [-x pos -y pos | -d number]\n", argv[0]); printf("\n"); printf(" %s\n", _("List modules:")); printf(" %s --modules\n", argv[0]); printf("\n"); printf(" %s\n", _("Dump data:")); printf(" %s -f=[edid|icc|edid_icc] [-o=edid.bin] [-x pos -y pos | -d number] [-m]\n", argv[0]); printf("\n"); printf(" %s\n", _("General options:")); printf(" %s\n", _("-v verbose")); printf(" %s\n", _("--module name")); printf(" %s\n", _("-d device_position_start_from_zero")); printf("\n"); printf(_("For more informations read the man page:")); printf("\n"); printf(" man oyranos-monitor\n"); exit (0); break; } break; default: monitor_profile = argv[pos]; erase = 0; unset = 0; } if( wrong_arg ) { printf("%s %s\n", _("wrong argument to option:"), wrong_arg); exit(1); } ++pos; } if(oy_debug) fprintf( stderr, "%s\n", argv[1] ); } if(verbose) fprintf(stderr, "oyranos-monitor v%d.%d.%d %s\n", OYRANOS_VERSION_A,OYRANOS_VERSION_B,OYRANOS_VERSION_C, _("is a color profile administration tool for monitors")); #ifdef HAVE_X11 if(module_name && strstr(module_name, "oyX1")) { #endif #ifndef __APPLE__ if(!display_name) { WARNc_S( _("DISPLAY variable not set: giving up.") ); error = 1; return error; } #endif /* cut off the screen information */ if(display_name && (ptr = strchr(display_name,':')) != 0) if( (ptr = strchr(ptr, '.')) != 0 ) ptr[0] = '\000'; #ifdef HAVE_X11 } #endif /* implicite selection for the most common default case */ if(!icc_profile_flags) icc_profile_flags = oyICCProfileSelectionFlagsFromOptions( OY_CMM_STD, "//" OY_TYPE_STD "/icc_color", NULL, 0 ); #ifdef XCM_HAVE_X11 if(daemon) { Display * display = XOpenDisplay( display_name ); if(XcmColorServerCapabilities( display ) & XCM_COLOR_SERVER_MANAGEMENT) daemon = 2; XCloseDisplay( display ); } /* we rely on any color server doing X11 setup by its own and do not want to interfere */ if(daemon != 2) #endif { if(!erase && !unset && !list && !setup && !format && !add_meta && !list_modules && !list_taxi) setup = 1; if(module_name) { STRING_ADD( device_class, "."); STRING_ADD( device_class, module_name); } /* by default a given monitor profile is used to setup the major monitor */ if(monitor_profile && !server && device_pos == -1) device_pos = 0; if(device_pos != -1) { error = oyOptions_SetFromText( &options, "//" OY_TYPE_STD "/config/command", "properties", OY_CREATE_NEW ); error = oyOptions_SetFromText( &options, "//"OY_TYPE_STD"/config/edid", "1", OY_CREATE_NEW ); #ifdef HAVE_X11 if(module_name && strstr(module_name, "oyX1")) { #endif if(server) error = oyOptions_SetFromText( &options, "//"OY_TYPE_STD"/config/device_name", oy_display_name, OY_CREATE_NEW ); else error = oyOptions_SetFromText( &options, "//"OY_TYPE_STD"/config/display_name", display_name, OY_CREATE_NEW ); #ifdef HAVE_X11 } #endif error = oyOptions_SetFromInt( &options, "//" OY_TYPE_STD "/icc_profile_flags", icc_profile_flags, 0, OY_CREATE_NEW ); error = oyDevicesGet( 0, device_class, options, &devices ); n = oyConfigs_Count( devices ); if(error <= 0 && 0 <= device_pos && device_pos < n ) { c = oyConfigs_Get( devices, device_pos ); oy_display_name = strdup( oyConfig_FindString( c, "device_name", 0 )); oyConfig_Release( &c ); } else fprintf( stderr, "%s %d. %s: %d\n", _("Could not resolve device"), device_pos, _("Available devices"), n); oyConfigs_Release( &devices ); oyOptions_Release( &options ); } else if(server) oy_display_name = oyGetDisplayNameFromPosition2 ( OY_TYPE_STD, device_class, display_name, x,y, oyAllocFunc); if(list_modules) { uint32_t count = 0, * rank_list = 0; char ** texts = 0; error = oyConfigDomainList( device_class, &texts, &count, &rank_list, 0 ); for(i = 0; i < count; ++i) printf("%s\n", strstr(texts[i],"monitor.") + 8 ); return error; } if(list_taxi) { oyConfig_s * taxi_dev; int32_t * ranks; int head = 0; devices = 0; if(!oy_display_name) { fprintf(stderr, "%s\n", _("Please specify a monitor with the -d option.") ); return error; } error = oyOptions_SetFromText( &options, "//" OY_TYPE_STD "/config/command", "properties", OY_CREATE_NEW ); error = oyDeviceGet( OY_TYPE_STD, device_class, oy_display_name, 0, &device ); oyDevicesFromTaxiDB( device, options, &devices, NULL ); n = oyConfigs_Count( devices ); if(n == 0) fprintf(stderr, "%s\n", _("Zero profiles found in Taxi ICC DB") ); ranks = calloc(sizeof(int32_t), n*2+1); for(i = 0; i < n; ++i) { taxi_dev = oyConfigs_Get( devices, i ); ranks[2*i+0] = i; error = oyConfig_Compare( device, taxi_dev, &ranks[2*i+1] ); oyConfig_Release( &taxi_dev ); } qsort( ranks, n, sizeof(int32_t)*2, compareRanks ); for(i = 0; i < n; ++i) { taxi_dev = oyConfigs_Get( devices, ranks[2*i+0] ); if(ranks[2*i+1] <= 0 && !verbose) { oyConfig_Release( &taxi_dev ); continue; } if(!head) { oyOptions_s * cs_options = 0; char * text = NULL, * report = NULL; head = 1; if(verbose) { if(x_color_region_target) { /* get XCM_ICC_COLOR_SERVER_TARGET_PROFILE_IN_X_BASE */ error = oyOptions_SetFromText( &cs_options, "//"OY_TYPE_STD"/config/icc_profile.x_color_region_target", "yes", OY_CREATE_NEW ); } error = oyDeviceGetInfo( device, oyNAME_NICK, cs_options, &text, oyAllocFunc ); oyStringAddPrintf_( &report, oyAllocFunc, oyDeAllocFunc, "\"%s\" ", text ? text : "???" ); error = oyDeviceGetInfo( device, oyNAME_NAME, cs_options, &text, oyAllocFunc ); oyStringAddPrintf_( &report, oyAllocFunc, oyDeAllocFunc, "%s", text ? text : "???" ); fprintf( stderr, "%s: %s\n", _("Taxi DB entries for device"), report ); } fprintf( stderr, "%s [%s] \"%s\"\n", _("Taxi ID"), _("match value"), _("description") ); oyOptions_Release( &cs_options ); } printf("%s/0 [%d] ", oyNoEmptyString_m_( oyConfig_FindString(taxi_dev, "TAXI_id", 0)), ranks[2*i+1]); printf("\"%s\"\n", oyNoEmptyString_m_( oyConfig_FindString(taxi_dev, "TAXI_profile_description", 0))); if(oy_debug) { char * json_text = 0; oyDeviceToJSON( taxi_dev, 0, &json_text, oyAllocateFunc_ ); fprintf(stderr, "%s\n", json_text ); oyFree_m_(json_text); } oyConfig_Release( &taxi_dev ); } oyConfig_Release( &device ); oyConfigs_Release( &devices ); oyOptions_Release( &options ); return error; } if(format && (strcmp(format,"edid") == 0 || strcmp(format,"icc") == 0 || strcmp(format,"edid_icc") == 0)) { icHeader * header = 0; char * out_name = 0; error = oyOptions_SetFromText( &options, "//" OY_TYPE_STD "/config/command", "properties", OY_CREATE_NEW ); error = oyOptions_SetFromText( &options, "//"OY_TYPE_STD"/config/edid", "1", OY_CREATE_NEW ); if(oy_display_name) error = oyOptions_SetFromText( &options, "//"OY_TYPE_STD"/config/device_name", oy_display_name, OY_CREATE_NEW ); #ifdef HAVE_X11 else if(module_name && strstr(module_name, "oyX1")) #endif error = oyOptions_SetFromText( &options, "//"OY_TYPE_STD"/config/display_name", display_name, OY_CREATE_NEW ); error = oyOptions_SetFromInt( &options, "//" OY_TYPE_STD "/icc_profile_flags", icc_profile_flags, 0, OY_CREATE_NEW ); error = oyDevicesGet( 0, device_class, options, &devices ); n = oyConfigs_Count( devices ); if(!error) { for(i = 0; i < n; ++i) { c = oyConfigs_Get( devices, i ); if(strcmp(format,"edid_icc") == 0) { o = oyConfig_Find( c, "color_matrix.from_edid." "redx_redy_greenx_greeny_bluex_bluey_whitex_whitey_gamma"); if(o) { oyOptions_s * opts = oyOptions_New(0), * result = 0; error = oyOptions_MoveIn( opts, &o, -1 ); error = oyOptions_SetFromInt( &opts, "//" OY_TYPE_STD "/icc_profile_flags", icc_profile_flags, 0, OY_CREATE_NEW ); oyOptions_Handle( "///create_profile.icc", opts,"create_profile.icc_profile.color_matrix", &result ); prof = (oyProfile_s*)oyOptions_GetType( result, -1, "icc_profile", oyOBJECT_PROFILE_S ); oyOptions_Release( &result ); } if(prof) { uint32_t model_id = 0; const char * t = 0; error = oyProfile_AddTagText( prof, icSigProfileDescriptionTag, (char*) output ? output : format ); t = oyConfig_FindString( c, "EDID_manufacturer", 0 ); if(t) error = oyProfile_AddTagText( prof, icSigDeviceMfgDescTag, t ); t = oyConfig_FindString( c, "EDID_model", 0 ); if(t) error = oyProfile_AddTagText( prof, icSigDeviceModelDescTag, t); if(device_meta_tag) { oyOptions_s * opts = 0; error = oyOptions_SetFromText( &opts, "///key_prefix_required", "EDID_.OPENICC_" , OY_CREATE_NEW ); error = oyOptions_SetFromText( oyConfig_GetOptions( c,"backend_core" ), OY_TOP_SHARED OY_SLASH OY_DOMAIN_STD OY_SLASH OY_TYPE_STD OY_SLASH "device" OY_SLASH "config.icc_profile.monitor" OY_SLASH "OPENICC_automatic_generated", "1", OY_CREATE_NEW ); error = oyOptions_SetFromText( oyConfig_GetOptions( c,"backend_core" ), OY_TOP_SHARED OY_SLASH OY_DOMAIN_STD OY_SLASH OY_TYPE_STD OY_SLASH "device" OY_SLASH "config.icc_profile.monitor" OY_SLASH "prefix", "EDID_.OPENICC_", OY_CREATE_NEW ); oyProfile_AddDevice( prof, c, opts ); oyOptions_Release( &opts ); } data = oyProfile_GetMem( prof, &size, 0, oyAllocFunc ); header = (icHeader*) data; t = oyConfig_FindString( c, "EDID_mnft", 0 ); if(t) sprintf( (char*)&header->manufacturer, "%s", t ); t = oyConfig_FindString( c, "EDID_model_id", 0 ); if(t) model_id = atoi( t ); model_id = oyValueUInt32( model_id ); memcpy( &header->model, &model_id, 4 ); oyOption_Release( &o ); } } else if(strcmp(format,"edid") == 0) { o = oyConfig_Find( c, "edid" ); data = oyOption_GetData( o, &size, oyAllocFunc ); } else if(strcmp(format,"icc") == 0) { oyOptions_s * cs_options = 0; if(x_color_region_target) { /* get XCM_ICC_COLOR_SERVER_TARGET_PROFILE_IN_X_BASE */ error = oyOptions_SetFromText( &cs_options, "//"OY_TYPE_STD"/config/icc_profile.x_color_region_target", "yes", OY_CREATE_NEW ); } oyDeviceAskProfile2( c, cs_options, &prof ); oyOptions_Release( &cs_options ); if(device_meta_tag) { oyOptions_s * opts = 0; error = oyOptions_SetFromText( &opts, "///set_device_attributes", "true", OY_CREATE_NEW ); error = oyOptions_SetFromText( &opts, "///key_prefix_required", "EDID_" , OY_CREATE_NEW ); oyProfile_AddDevice( prof, c, opts ); oyOptions_Release( &opts ); } data = oyProfile_GetMem( prof, &size, 0, oyAllocFunc ); } if(data && size) { if(output) error = oyWriteMemToFile2_( output, data, size, 0x01, &out_name, oyAllocFunc ); else fwrite( data, sizeof(char), size, stdout ); oyDeAllocFunc( data ); size = 0; } else error = 1; if(!error) { if(verbose) fprintf( stderr, " written to %s\n", out_name ); } else printf( "Could not write %d bytes to %s\n", (int)size, out_name?out_name:format); if(out_name){ oyDeAllocFunc(out_name); out_name = 0; } oyProfile_Release( &prof ); oyOption_Release( &o ); oyConfig_Release( &c ); } } else WARNc2_S("oyDevicesGet %s %d", _("found issues"),error); oyConfigs_Release( &devices ); oyOptions_Release( &options ); } else if(prof_name && add_meta) { uint32_t id[4]; oyBlob_s * edid = oyBlob_New(0); char * edid_fn = oyResolveDirFileName_(add_meta); data = oyReadFileToMem_( edid_fn, &size, oyAllocateFunc_ ); oyBlob_SetFromData( edid, data, size, "edid" ); oyFree_m_(data); prof = oyProfile_FromName( prof_name, OY_NO_CACHE_READ | icc_profile_flags, 0 ); device = 0; oyOptions_Release( &options ); error = oyOptions_SetFromText( &options, "//" OY_TYPE_STD "/config/command", "add_meta", OY_CREATE_NEW ); error = oyOptions_MoveInStruct( &options, "//" OY_TYPE_STD "/config/icc_profile", (oyStruct_s**)&prof, OY_CREATE_NEW ); error = oyOptions_MoveInStruct( &options, "//" OY_TYPE_STD "/config/edid", (oyStruct_s**)&edid, OY_CREATE_NEW ); error = oyDeviceGet( OY_TYPE_STD, device_class, ":0.0", options, &device); if(verbose && device) { /* We need a newly opened profile, otherwise we obtaine cached modifications. */ oyProfile_s * p = oyProfile_FromName( prof_name, OY_NO_CACHE_READ | icc_profile_flags, 0 ); oyConfig_s * p_device = oyConfig_FromRegistration( oyConfig_GetRegistration( device ), 0 ); int32_t rank = 0; int old_oy_debug = oy_debug; char * json = 0; oyProfile_GetDevice( p, p_device ); if(oy_debug > 1) { error = oyDeviceToJSON( p_device, 0, &json, oyAllocateFunc_ ); fprintf(stderr, "device from profile %s:\n%s\n", prof_name, json ); oyFree_m_( json ); } if(oy_debug > 1) { error = oyDeviceToJSON( device, 0, &json, oyAllocateFunc_ ); fprintf(stderr, "device from edid %s:\n%s\n", edid_fn, json ); oyFree_m_( json ); } /*p_device->db = oyOptions_Copy( p_device->backend_core, 0 ); device->db = oyOptions_Copy( device->backend_core, 0 );*/ if(oy_debug < 2) oy_debug = 2; error = oyConfig_Compare( p_device, device, &rank ); oy_debug = old_oy_debug; fprintf(stderr, "rank of edid to previous profile %d\n", rank); } oyConfig_Release( &device ); oyFree_m_(edid_fn); prof = (oyProfile_s*)oyOptions_GetType( options, -1, "icc_profile", oyOBJECT_PROFILE_S ); oyOptions_Release( &options ); if(new_profile_name) error = oyProfile_AddTagText( prof, icSigProfileDescriptionTag, new_profile_name ); /* serialise before requesting a ICC md5 */ data = oyProfile_GetMem( prof, &size, 0, oyAllocFunc ); oyFree_m_(data); oyProfile_GetMD5( prof, OY_COMPUTE, id ); oyProfile_ToFile_( (oyProfile_s_*)prof, prof_name ); oyProfile_Release( &prof ); } if(list) { char * text = 0, * report = 0; uint32_t n = 0, i; oyOptions_s * cs_options = 0; if(x_color_region_target) { /* get XCM_ICC_COLOR_SERVER_TARGET_PROFILE_IN_X_BASE */ error = oyOptions_SetFromText( &cs_options, "//"OY_TYPE_STD"/config/icc_profile.x_color_region_target", "yes", OY_CREATE_NEW ); } error = oyOptions_SetFromText( &options, "//" OY_TYPE_STD "/config/command", "properties", OY_CREATE_NEW ); error = oyDevicesGet( 0, device_class, options, &devices ); n = oyConfigs_Count( devices ); if(error <= 0) { const char * device_name = 0; for(i = 0; i < n; ++i) { c = oyConfigs_Get( devices, i ); device_name = oyConfig_FindString( c, "device_name", 0 ); if( oy_display_name && device_name && strcmp( oy_display_name, device_name ) != 0 ) { oyConfig_Release( &c ); device_name = 0; continue; } if(verbose) fprintf(stderr,"------------------------ %d ---------------------------\n",i); error = oyDeviceGetInfo( c, oyNAME_NICK, cs_options, &text, oyAllocFunc ); if(!simple) { oyStringAddPrintf_( &report, oyAllocFunc, oyDeAllocFunc, "%d: ", i ); oyStringAddPrintf_( &report, oyAllocFunc, oyDeAllocFunc, "\"%s\" ", text ? text : "???" ); error = oyDeviceGetInfo( c, oyNAME_NAME, cs_options, &text, oyAllocFunc ); oyStringAddPrintf_( &report, oyAllocFunc, oyDeAllocFunc, "%s%s", text ? text : "???", (i+1 == n) || device_pos != -1 ? "" : "\n" ); } else { oyDeviceAskProfile2( c, cs_options, &prof ); data = oyProfile_GetMem( prof, &size, 0, oyAllocFunc); if(size && data) oyDeAllocFunc( data ); filename = oyProfile_GetFileName( prof, -1 ); oyStringAddPrintf_( &report, oyAllocFunc, oyDeAllocFunc, "%s%s", filename ? (simple == 1)?(strrchr(filename,OY_SLASH_C) ? strrchr(filename,OY_SLASH_C)+1:filename):filename : OY_PROFILE_NONE, (i+1 == n) || device_pos != -1 ? "" : "\n" ); } if(verbose) { error = oyDeviceGetInfo( c, oyNAME_DESCRIPTION, cs_options, &text, oyAllocFunc ); fprintf( stderr,"%s\n", text ? text : "???" ); } if(text) free( text ); /* verbose adds */ if(verbose) { oyDeviceAskProfile2( c, cs_options, &prof ); data = oyProfile_GetMem( prof, &size, 0, oyAllocFunc); if(size && data) oyDeAllocFunc( data ); filename = oyProfile_GetFileName( prof, -1 ); fprintf( stderr, " server profile \"%s\" size: %d\n", filename?filename:OY_PROFILE_NONE, (int)size ); text = 0; oyDeviceProfileFromDB( c, &text, oyAllocFunc ); fprintf( stderr, " DB profile \"%s\"\n keys: %s\n", text?text:OY_PROFILE_NONE, oyConfig_FindString( c, "key_set_name", 0 ) ? oyConfig_FindString( c, "key_set_name", 0 ) : OY_PROFILE_NONE ); oyProfile_Release( &prof ); oyDeAllocFunc( text ); } oyConfig_Release( &c ); } if(report) fprintf( stdout, "%s\n", report ); oyDeAllocFunc( report ); report = 0; } else WARNc2_S("oyDevicesGet %s %d", _("found issues"),error); oyConfigs_Release( &devices ); oyOptions_Release( &cs_options ); } if(oy_display_name) /* make shure the display name is correctly including the screen number */ { error = oyDeviceGet( OY_TYPE_STD, device_class, oy_display_name, 0, &device ); error = oyOptions_SetFromInt( &options, "//" OY_TYPE_STD "/icc_profile_flags", icc_profile_flags, 0, OY_CREATE_NEW ); if(monitor_profile) { if(verbose) fprintf( stdout, "oyDeviceSetProfile()\n" ); oyDeviceSetProfile( device, scope, monitor_profile ); if(verbose) fprintf( stdout, "oyDeviceUnset()\n" ); oyDeviceUnset( device ); } else if(erase || unset) { if(verbose) fprintf( stdout, "oyDeviceUnset()\n" ); oyDeviceUnset( device ); } if(erase) { if(verbose) fprintf( stdout, "oyConfig_EraseFromDB()\n" ); oyConfig_EraseFromDB( device, scope ); } if(setup) { if(monitor_profile) error = oyOptions_SetFromText( &options, "//"OY_TYPE_STD"/config/skip_ask_for_profile", "yes", OY_CREATE_NEW ); if(verbose) fprintf( stdout, "oyDeviceSetup()\n" ); oyDeviceSetup( device, options ); } oyConfig_Release( &device ); } else if(erase || unset || setup) { error = oyOptions_SetFromText( &options, "//" OY_TYPE_STD "/config/command", "list", OY_CREATE_NEW ); #ifdef HAVE_X11 if(module_name && strstr(module_name, "oyX1")) #endif error = oyOptions_SetFromText( &options, "//"OY_TYPE_STD"/config/display_name", display_name, OY_CREATE_NEW ); error = oyOptions_SetFromInt( &options, "//" OY_TYPE_STD "/icc_profile_flags", icc_profile_flags, 0, OY_CREATE_NEW ); error = oyDevicesGet( 0, device_class, options, &devices ); n = oyConfigs_Count( devices ); if(!error) { for(i = 0; i < n; ++i) { device = oyConfigs_Get( devices, i ); if(erase || unset) oyDeviceUnset( device ); if(erase) oyConfig_EraseFromDB( device, scope ); if(setup) oyDeviceSetup( device, options ); oyConfig_Release( &device ); } } oyConfigs_Release( &devices ); oyOptions_Release( &options ); } } if(oy_display_name) oyDeAllocFunc(oy_display_name); #if defined(XCM_HAVE_X11) if(daemon) error = runDaemon( display_name ); #else if(daemon) fprintf( stderr, "daemon mode not supported on your OS\n" ); #endif oyFinish_( FINISH_IGNORE_I18N | FINISH_IGNORE_CACHES ); return error; }
/** Function oyFilterNode_SetContext_ * @memberof oyFilterNode_s * @brief Set module context in a filter * @internal * * The api4 data is passed to a interpolator specific transformer. The result * of this transformer will on request be cached by Oyranos as well. * * @param[in] node filter * @param[in,out] blob context to fill; expensive * @return error * * @version Oyranos: 0.9.6 * @date 2014/06/26 * @since 2008/11/02 (Oyranos: 0.1.8) */ int oyFilterNode_SetContext_( oyFilterNode_s_ * node, oyBlob_s_ * blob ) { int error = 0; oyFilterCore_s_ * core_ = node->core; if(error <= 0) { size_t size = 0; oyHash_s * hash4 = 0, /* public context provider */ * hash7 = 0; /* data processor part */ oyPointer ptr = 0; oyPointer_s * cmm_ptr4 = 0, * cmm_ptr7 = 0; /* Cache Search * 1. hash from input * 2. query for hash in cache * 3. check * 3a. eighter take cache entry * 3b. or ask CMM * 3b.1. update cache entry */ if(oy_debug && getenv("OY_DEBUG_WRITE")) { size = 0; ptr = oyFilterNode_TextToInfo_( node, &size, oyAllocateFunc_ ); if(ptr) oyWriteMemToFile_( "test_dbg_color.icc", ptr, size ); } /* 1. + 2. query in cache for api7 */ hash7 = oyFilterNode_GetHash_(node, 7); if(error <= 0) { /* select the module by option */ oyOption_s * ct = oyOptions_Find( node->core->options_, "////context", oyNAME_PATTERN ); const char * pattern = oyOption_GetValueString( ct, 0 ); if(pattern && !oyFilterRegistrationMatch( core_->registration_, pattern, 0 )) { oyMessageFunc_p( oyMSG_DBG, (oyStruct_s*) node, OY_DBG_FORMAT_ "create core from pattern: %s", OY_DBG_ARGS_, oyFilterNode_GetText( (oyFilterNode_s*)node,oyNAME_NICK) ); error = oyFilterNode_SetFromPattern_( node, 1, pattern ); if(error) { if(oyOption_GetFlags( ct ) & oyOPTIONATTRIBUTE_EDIT) { oyMessageFunc_p( oyMSG_WARN, (oyStruct_s*) node, OY_DBG_FORMAT_ "edited pattern not available: %d %s", OY_DBG_ARGS_, oyObject_GetId(ct->oy_), pattern ); error = 1; goto clean; } else error = 0; } else core_ = node->core; oyHash_Release( &hash7 ); hash7 = oyFilterNode_GetHash_(node, 7); } oyOption_Release( &ct ); ct = oyOptions_Find( node->core->options_, "////renderer", oyNAME_PATTERN ); pattern = oyOption_GetValueString( ct, 0 ); if(pattern && !oyFilterRegistrationMatch( node->api7_->registration, pattern, 0 )) { oyMessageFunc_p( oyMSG_DBG, (oyStruct_s*) node, OY_DBG_FORMAT_ "create node from pattern: %s", OY_DBG_ARGS_, oyFilterNode_GetText( (oyFilterNode_s*)node,oyNAME_NICK) ); error = oyFilterNode_SetFromPattern_( node, 0, pattern ); if(error) { if(oyOption_GetFlags( ct ) & oyOPTIONATTRIBUTE_EDIT) { error = 1; goto clean; } else error = 0; } else core_ = node->core; oyHash_Release( &hash7 ); hash7 = oyFilterNode_GetHash_(node, 7); } /* 3. check and 3.a take*/ cmm_ptr7 = (oyPointer_s*) oyHash_GetPointer( hash7, oyOBJECT_POINTER_S); if(!(cmm_ptr7 && oyPointer_GetPointer(cmm_ptr7)) || blob) { /* write the cmm4 context to memory */ if(blob) { if(oy_debug) error = oyOptions_SetFromString( &node->tags, "////verbose", "true", OY_CREATE_NEW ); /* oy_debug is used to obtain a complete data set */ ptr = oyFilterNode_ContextToMem_( node, &size, oyAllocateFunc_); oyBlob_SetFromData( (oyBlob_s*)blob, ptr, size, core_->api4_->context_type ); if(oy_debug) error = oyOptions_SetFromString( &node->tags, "////verbose", "false", 0 ); goto clean; } /* 2. query in cache for api4 */ hash4 = oyFilterNode_GetHash_(node, 4); cmm_ptr4 = (oyPointer_s*) oyHash_GetPointer( hash4, oyOBJECT_POINTER_S); if(!cmm_ptr4) { cmm_ptr4 = oyPointer_New(0); } if(!oyPointer_GetPointer(cmm_ptr4)) { size = 0; /* 3b. ask CMM */ ptr = oyFilterNode_ContextToMem_( node, &size, oyAllocateFunc_); if(!ptr || !size) { oyOption_s * ct = oyOptions_Find( core_->options_, "////context", oyNAME_PATTERN ); oyMessageFunc_p( oyMSG_DBG, (oyStruct_s*) node, OY_DBG_FORMAT_ "device link creation failed", OY_DBG_ARGS_); if(!(oyOption_GetFlags( ct ) & oyOPTIONATTRIBUTE_EDIT)) { char * pattern = oyFilterNode_GetFallback_( node, 1 ); oyMessageFunc_p( oyMSG_WARN, (oyStruct_s*) node, OY_DBG_FORMAT_ "create core from fallback: %s", OY_DBG_ARGS_, pattern ); error = oyFilterNode_SetFromPattern_( node, 1, pattern ); if(error) { error = 1; oyMessageFunc_p( oyMSG_ERROR, (oyStruct_s*) node, OY_DBG_FORMAT_ "no device link for caching\n%s", OY_DBG_ARGS_, oyFilterNode_GetText( (oyFilterNode_s*)node,oyNAME_NICK)); goto clean; } else core_ = node->core; ptr = oyFilterNode_ContextToMem_( node, &size, oyAllocateFunc_ ); oyFree_m_( pattern ); } if(!ptr || !size) { oyMessageFunc_p( oyMSG_ERROR, (oyStruct_s*) node, OY_DBG_FORMAT_ "no device link for caching\n%s", OY_DBG_ARGS_, oyFilterNode_GetText( (oyFilterNode_s*)node,oyNAME_NICK)); error = 1; oyPointer_Release( &cmm_ptr4 ); } else if(oy_debug) oyMessageFunc_p( oyMSG_WARN, (oyStruct_s*) node, OY_DBG_FORMAT_ "use fallback CMM\n%s", OY_DBG_ARGS_, oyFilterNode_GetText( (oyFilterNode_s*)node, oyNAME_NICK )); } if(!error) { /* 3b.1. update the hash as the CMM can change options */ hash4 = oyFilterNode_GetHash_( node, 4 ); oyPointer_Release( &cmm_ptr4 ); cmm_ptr4 = (oyPointer_s*) oyHash_GetPointer( hash4, oyOBJECT_POINTER_S); hash7 = oyFilterNode_GetHash_( node, 7 ); if(!cmm_ptr4) cmm_ptr4 = oyPointer_New(0); error = oyPointer_Set( cmm_ptr4, core_->api4_->id_, core_->api4_->context_type, ptr, "oyPointerRelease", oyPointerRelease); oyPointer_SetSize( cmm_ptr4, size ); /* 3b.2. update cmm4 cache entry */ error = oyHash_SetPointer( hash4, (oyStruct_s*) cmm_ptr4); } } if(error <= 0 && cmm_ptr4 && oyPointer_GetPointer(cmm_ptr4)) { if(node->backend_data && node->backend_data->release) node->backend_data->release( (oyStruct_s**)&node->backend_data); if( oyStrcmp_( node->api7_->context_type, core_->api4_->context_type ) != 0 ) { cmm_ptr7 = oyPointer_New(0); error = oyPointer_Set( cmm_ptr7, node->api7_->id_, node->api7_->context_type, 0, 0, 0); /* 3b.3. search for a convertor and convert */ oyPointer_ConvertData( cmm_ptr4, cmm_ptr7, (oyFilterNode_s*)node ); node->backend_data = cmm_ptr7; /* 3b.4. update cmm7 cache entry */ error = oyHash_SetPointer( hash7, (oyStruct_s*) cmm_ptr7); } else node->backend_data = oyPointer_Copy( cmm_ptr4, 0 ); } if(oy_debug && getenv("OY_DEBUG_WRITE")) { int id = oyFilterNode_GetId( (oyFilterNode_s*)node ); char * file_name = 0; oyAllocHelper_m_( file_name, char, 80, 0, return 1 ); sprintf( file_name, "dbg_color_dl-node[%d].icc", id ); if(ptr && size && node->backend_data) oyWriteMemToFile_( file_name, ptr, size ); oyFree_m_(file_name); } } else
/** @internal * Function oyFilterGraph_Release_ * @memberof oyFilterGraph_s_ * @brief release and possibly deallocate a FilterGraph object * * @param[in,out] filtergraph FilterGraph struct object * * @version Oyranos: 0.9.7 * @date 2018/10/03 * @since 2010/04/26 (Oyranos: 0.1.10) */ int oyFilterGraph_Release_( oyFilterGraph_s_ **filtergraph ) { const char * track_name = NULL; int observer_refs = 0, i; /* ---- start of common object destructor ----- */ oyFilterGraph_s_ *s = 0; if(!filtergraph || !*filtergraph) return 0; s = *filtergraph; /* static object */ if(!s->oy_) return 0; *filtergraph = 0; observer_refs = oyStruct_ObservationCount( (oyStruct_s*)s, 0 ); if(oy_debug_objects >= 0) { const char * t = getenv(OY_DEBUG_OBJECTS); int id_ = -1; if(t) id_ = atoi(t); else id_ = oy_debug_objects; if((id_ >= 0 && s->oy_->id_ == id_) || (t && (strstr(oyStructTypeToText(s->type_), t) != 0)) || id_ == 1) { oyStruct_s ** parents = NULL; int n = oyStruct_GetParents( (oyStruct_s*)s, &parents ); if(n != s->oy_->ref_) { int i; #ifdef HAVE_BACKTRACE int j, nptrs; void *buffer[BT_BUF_SIZE]; char **strings; nptrs = backtrace(buffer, BT_BUF_SIZE); /* The call backtrace_symbols_fd(buffer, nptrs, STDOUT_FILENO) would produce similar output to the following: */ strings = backtrace_symbols(buffer, nptrs); if( strings == NULL ) { perror("backtrace_symbols"); } else { int start = nptrs-1; do { --start; } while( start >= 0 && (strstr(strings[start], "(main+") == NULL) ); fprintf(stderr, "\n"); for(j = start; j >= 0; j--) { if(oy_debug) fprintf(stderr, "%s\n", strings[j]); else { char * t = NULL, * txt = NULL; const char * line = strings[j], * tmp = strchr( line, '(' ); if(tmp) t = oyStringCopy( &tmp[1], NULL ); else t = oyStringCopy( line, NULL ); txt = strchr( t, '+' ); if(txt) txt[0] = '\000'; if(j > 0 && (strstr(strings[j-1], t) != NULL) ) oyFree_m_(t); if(t) { if(j==0) fprintf(stderr, "%s() ", t); else fprintf(stderr, "%s()->", t); oyFree_m_(t); } } } free(strings); } #endif track_name = oyStructTypeToText(s->type_); fprintf( stderr, "%s[%d] unref with refs: %d observers: %d parents: %d\n", track_name, s->oy_->id_, s->oy_->ref_, observer_refs, n ); for(i = 0; i < n; ++i) { track_name = oyStructTypeToText(parents[i]->type_); fprintf( stderr, "parent[%d]: %s[%d]\n", i, track_name, parents[i]->oy_->id_ ); } } } } if((oyObject_UnRef(s->oy_) - observer_refs) > 0) return 0; /* ---- end of common object destructor ------- */ if(oy_debug_objects >= 0) { const char * t = getenv(OY_DEBUG_OBJECTS); int id_ = -1; if(t) id_ = atoi(t); else id_ = oy_debug_objects; if((id_ >= 0 && s->oy_->id_ == id_) || (t && s && (strstr(oyStructTypeToText(s->type_), t) != 0)) || id_ == 1) { track_name = oyStructTypeToText(s->type_); fprintf( stderr, "%s[%d] destruct\n", track_name, s->oy_->id_); } } /* ---- start of custom FilterGraph destructor ----- */ oyFilterGraph_Release__Members( s ); /* ---- end of custom FilterGraph destructor ------- */ /* model and observer reference each other. So release the object two times. * The models and and observers are released later inside the * oyObject_s::handles. */ for(i = 0; i < observer_refs; ++i) { oyObject_UnRef(s->oy_); oyObject_UnRef(s->oy_); } if(s->oy_->deallocateFunc_) { oyDeAlloc_f deallocateFunc = s->oy_->deallocateFunc_; int id = s->oy_->id_; int refs = s->oy_->ref_; if(refs > 1) fprintf( stderr, "!!!ERROR: node[%d]->object can not be untracked with refs: %d\n", id, refs); oyObject_Release( &s->oy_ ); if(track_name) fprintf( stderr, "%s[%d] destructed\n", track_name, id ); deallocateFunc( s ); } return 0; }
/** @internal * Function oyFilterGraph_Copy_ * @memberof oyFilterGraph_s_ * @brief copy or reference a FilterGraph object * * @param[in] filtergraph FilterGraph struct object * @param object the optional object * * @version Oyranos: * @since 2010/04/26 (Oyranos: 0.1.10) * @date 2010/04/26 */ oyFilterGraph_s_ * oyFilterGraph_Copy_ ( oyFilterGraph_s_ *filtergraph, oyObject_s object ) { oyFilterGraph_s_ *s = filtergraph; if(!filtergraph) return 0; if(filtergraph && !object) { s = filtergraph; if(oy_debug_objects >= 0 && s->oy_) { const char * t = getenv(OY_DEBUG_OBJECTS); int id_ = -1; if(t) id_ = atoi(t); else id_ = oy_debug_objects; if((id_ >= 0 && s->oy_->id_ == id_) || (t && s && (strstr(oyStructTypeToText(s->type_), t) != 0)) || id_ == 1) { oyStruct_s ** parents = NULL; int n = oyStruct_GetParents( (oyStruct_s*)s, &parents ); if(n != s->oy_->ref_) { int i; const char * track_name = oyStructTypeToText(s->type_); #ifdef HAVE_BACKTRACE int j, nptrs; void *buffer[BT_BUF_SIZE]; char **strings; nptrs = backtrace(buffer, BT_BUF_SIZE); /* The call backtrace_symbols_fd(buffer, nptrs, STDOUT_FILENO) would produce similar output to the following: */ strings = backtrace_symbols(buffer, nptrs); if( strings == NULL ) { perror("backtrace_symbols"); } else { int start = nptrs-1; do { --start; } while( start >= 0 && (strstr(strings[start], "(main+") == NULL) ); fprintf(stderr, "\n"); for(j = start; j >= 0; j--) { if(oy_debug) fprintf(stderr, "%s\n", strings[j]); else { char * t = NULL, * txt = NULL; const char * line = strings[j], * tmp = strchr( line, '(' ); if(tmp) t = oyStringCopy( &tmp[1], NULL ); else t = oyStringCopy( line, NULL ); txt = strchr( t, '+' ); if(txt) txt[0] = '\000'; if(j > 0 && (strstr(strings[j-1], t) != NULL) ) oyFree_m_(t); if(t) { if(j==0) fprintf(stderr, "%s() ", t); else fprintf(stderr, "%s()->", t); oyFree_m_(t); } } } free(strings); } #endif fprintf( stderr, "%s[%d] tracking refs: %d parents: %d\n", track_name, s->oy_->id_, s->oy_->ref_, n ); for(i = 0; i < n; ++i) { track_name = oyStructTypeToText(parents[i]->type_); fprintf( stderr, "parent[%d]: %s[%d]\n", i, track_name, parents[i]->oy_->id_ ); } } } } oyObject_Copy( s->oy_ ); return s; } s = oyFilterGraph_Copy__( filtergraph, object ); return s; }
/** * @internal * Function oyOption_GetValueText_ * @memberof oyOption_s * @brief get value as a text dump * * @param obj the option * @param allocateFunc user allocator * @return the text * * @version Oyranos: 0.1.9 * @since 2008/12/05 (Oyranos: 0.1.9) * @date 2009/08/17 */ char * oyOption_GetValueText_( oyOption_s_ * obj, oyAlloc_f allocateFunc ) { int error = !obj; char * erg = 0; oyValue_u * v = 0; oyStructList_s * oy_struct_list = 0; char * text = 0; char * save_locale = 0; if(error <= 0) v = obj->value; if(!allocateFunc) allocateFunc = oyAllocateFunc_; error = !v; save_locale = oyStringCopy_( setlocale(LC_NUMERIC, 0 ), oyAllocateFunc_ ); setlocale(LC_NUMERIC, "C"); if(error <= 0) { int n = 1, i = 0; char * tmp = oyAllocateFunc_(1024); const char * ct = 0; switch(obj->value_type) { case oyVAL_INT_LIST: n = v->int32_list[0]; break; case oyVAL_DOUBLE_LIST: n = (int)v->dbl_list[0]; break; case oyVAL_STRING_LIST: n = 0; while( v->string_list[n] ) ++n; break; case oyVAL_INT: case oyVAL_DOUBLE: case oyVAL_STRING: case oyVAL_STRUCT: n = 1; break; case oyVAL_NONE: case oyVAL_MAX: n = 0; break; } if(obj->value_type == oyVAL_STRUCT) { oy_struct_list = (oyStructList_s*) v->oy_struct; if(oy_struct_list) { if(oy_struct_list->type_ == oyOBJECT_STRUCT_LIST_S) n = oyStructList_Count( oy_struct_list ); } else WARNc2_S( "missed \"oy_struct\" member of \"%s\" [%d]", obj->registration, oyObject_GetId(obj->oy_) ); } for(i = 0; i < n; ++i) { if(obj->value_type == oyVAL_INT) oySprintf_(tmp, "%d", v->int32); if(obj->value_type == oyVAL_DOUBLE) oySprintf_(tmp, "%g", v->dbl); if(obj->value_type == oyVAL_INT_LIST) oySprintf_(tmp, "%d", v->int32_list[i+1]); if(obj->value_type == oyVAL_DOUBLE_LIST) oySprintf_(tmp, "%g", v->dbl_list[i+1]); if((obj->value_type == oyVAL_INT_LIST || obj->value_type == oyVAL_DOUBLE_LIST) && i) STRING_ADD( text, "," ); switch(obj->value_type) { case oyVAL_INT: case oyVAL_DOUBLE: case oyVAL_INT_LIST: case oyVAL_DOUBLE_LIST: STRING_ADD( text, tmp ); break; case oyVAL_STRING: STRING_ADD( text, v->string ); break; case oyVAL_STRING_LIST: STRING_ADD( text, v->string_list[i] ); break; case oyVAL_STRUCT: case oyVAL_NONE: case oyVAL_MAX: break; } if(obj->value_type == oyVAL_STRUCT) { oyStruct_s * oy_struct = 0; if(oy_struct_list && oy_struct_list->type_ == oyOBJECT_STRUCT_LIST_S) oy_struct = oyStructList_Get_( ( oyStructList_s_*)oy_struct_list, i ); else if(v->oy_struct) oy_struct = v->oy_struct; if(oy_struct) { ct = 0; /* get explicite name */ if(oy_struct->oy_) ct = oyObject_GetName( oy_struct->oy_, oyNAME_NICK ); if(!ct) /* fall back to oyCMMapi9_s object type lookup */ ct = oyStruct_GetText( oy_struct, oyNAME_NICK, 0 ); if(ct) STRING_ADD( text, ct ); if(!ct) /* fall back to plain struct type name, if known */ STRING_ADD ( text, oyStructTypeToText(oy_struct->type_) ); } } } if(text) erg = oyStringCopy_( text, allocateFunc ); oyFree_m_( tmp ); if(!text) { DBG_NUM2_S( "missed value in \"%s\" [%d]", obj->registration, oyObject_GetId(obj->oy_) ); } else oyFree_m_( text ); } setlocale(LC_NUMERIC, save_locale); oyFree_m_( save_locale ); return erg; }
char * oyReadFilepToMem_ ( FILE * fp, size_t * size, oyAlloc_f allocate_func) { char* mem = NULL; DBG_MEM_START DBG_MEM { if (fp) { int sz; /* get size */ fseek(fp,0L,SEEK_END); sz = ftell (fp); if(sz == -1) { switch(errno) { case EBADF: WARNc_S("Not a seekable stream"); break; case EINVAL: WARNc_S("Wrong argument"); break; default: WARNc1_S("%s", strerror(errno)); break; } *size = 0; return NULL; } /* read file possibly partitial */ if(!*size || *size > (size_t)ftell(fp)) *size = sz; rewind(fp); DBG_MEM1_S("%u\n",((unsigned int)((size_t)size))); if(!*size) return mem; /* allocate memory */ oyAllocHelper_m_( mem, char, *size+1, oyAllocateFunc_, return 0); /* check and read */ if ((fp != 0) && mem && *size) { int s = fread(mem, sizeof(char), *size, fp); DBG_MEM /* check again */ if ((size_t)s != *size) { *size = 0; oyFree_m_ (mem) mem = 0; } else { mem = oyReAllocFromStdMalloc_( mem, size, allocate_func ); } } } }
/** Function: oyNamedColor_GetName * @memberof oyNamedColor_s * @brief get color channels * * @since Oyranos: version 0.1.8 * @date 22 december 2007 (API 0.1.8) */ const char * oyNamedColor_GetName( oyNamedColor_s * color, oyNAME_e type, uint32_t flags ) { const char * text = 0; oyNamedColor_s_ * s = (oyNamedColor_s_*) color; if(!s) return 0; if(!s->oy_) return 0; text = oyObject_GetName( s->oy_, type ); if(!text && flags) { const char * tmp = 0; char * txt = 0; double l[3]; int i; icSignature sig = oyProfile_GetSignature( s->profile_, oySIGNATURE_COLOR_SPACE ); oyAllocHelper_m_( txt, char, 1024, 0, return 0 ); oyNamedColor_GetColorStd( color, oyEDITING_LAB, l, oyDOUBLE, 0, 0 ); switch(type) { case oyNAME_DESCRIPTION: tmp = oyObject_GetName( s->oy_, oyNAME_NAME ); if(!tmp) tmp = oyObject_GetName( s->oy_, oyNAME_NICK ); if(tmp) oySprintf_(txt, "%s: CIE*Lab: ", tmp ); else oySprintf_(txt, "CIE*Lab: "); for(i = 0; i < 3; ++i) oySprintf_( &txt[ oyStrlen_(txt) ], "%.02f ", l[i] ); tmp = oyICCColorSpaceGetName( sig ); if(tmp) oySprintf_( &txt[ oyStrlen_(txt) ], "; %s:", tmp ); if( s->channels_ ) for(i = 0; i < oyICCColorSpaceGetChannelCount( sig ); ++i) oySprintf_( &txt[ oyStrlen_(txt) ], "%.02f ", s->channels_[i] ); break; default: break; } oyObject_SetName ( s->oy_, txt, type ); oyFree_m_( txt ); text = oyObject_GetName( s->oy_, type ); } if(!text && type > oyNAME_NICK) text = oyObject_GetName( s->oy_, type - 2 ); if(!text && type > oyNAME_NAME) text = oyObject_GetName( s->oy_, type - 1 ); if(!text && type < oyNAME_NICK ) text = oyObject_GetName( s->oy_, type + 2 ); if(!text && type < oyNAME_DESCRIPTION ) text = oyObject_GetName( s->oy_, type + 1 ); if(!text) text = _("----"); return text; }
/** @internal * Function oyXML2XFORMsCmdLineSelect1Handler * @brief build a UI for a xf:select1 XFORMS sequence * * This function is a simple demonstration. * * @param[in] cur libxml2 node * @param[in] collected_elements parsed and requested elements * @param[in] user_data toolkit context * @return error * * @version Oyranos: 0.1.10 * @since 2009/08/29 (Oyranos: 0.1.10) * @date 2009/09/04 */ int oyXML2XFORMsCmdLineSelect1Handler( xmlNodePtr cur, oyOptions_s * collected_elements, oyPointer user_data ) { int is_default, choices_n = 0; const char * default_value = 0, * tmp, * label, * value, * help, * xpath = 0; char * default_key = 0, *key = 0; oyFormsArgs_s * forms_args = user_data; int print = forms_args ? forms_args->print : 1; xmlNodePtr select1, choices = 0, items; if(oy_debug && default_value && print) printf( "found default: \"%s\"\n", default_value ); if(cur) { if(oyXMLNodeNameIs(cur, "xf:select1")) { select1 = cur->children; default_value = oyXFORMsModelGetXPathValue( cur, "ref", &xpath ); } else select1 = 0; while(select1) { if(oyXMLNodeNameIs( select1, "xf:label") && print) printf( " %s:\n", oyXML2NodeValue(select1) ); else if(oyXMLNodeNameIs( select1, "xf:help") && print & 0x02) { printf( " [%s]\n", oyXML2NodeValue(select1) ); } else { if(oyXMLNodeNameIs(select1, "xf:choices")) choices = select1->children; else choices = 0; } while(choices) { label = tmp = value = help = 0; is_default = 0; if(oyXMLNodeNameIs( choices, "xf:item")) items = choices->children; else items = 0; while(items) { if(oyXMLNodeNameIs( items, "xf:label") && print) label = oyXML2NodeValue( items ); if(oyXMLNodeNameIs( items, "xf:value") && print) value = oyXML2NodeValue( items ); if(oyXMLNodeNameIs( items, "xf:help") && print) help = oyXML2NodeValue( items ); items = items->next; } if(value || label) { /* detect default */ if(value && default_value && oyStrcmp_(default_value,value) == 0) { is_default = 1; } if(!value) value = label; if(!label) label = value; /* append the choice * store the label and value in user_data() for evaluating results*/ if(print & 0x04) { tmp = 0; if(print & 0x02) tmp = label; help = tmp?help? (strstr(help,tmp) ? &help[strlen(tmp)] : help):"":""; printf( " --%s=\"%s\"%s%s%s%s%s%s\n", xpath+1, oyNoEmptyString_m_(value), is_default ? " *":"", tmp ? " [" : "", tmp?tmp:"", (help && strlen(help))?": ":"", help, tmp?"]":"" ); } if( !(print & 0x02) && !(print & 0x04) && is_default ) printf( " --%s=\"%s\"\n", xpath+1, oyNoEmptyString_m_(value) ); ++choices_n; } choices = choices->next; } select1 = select1->next; } } /* collect results */ if(xpath && forms_args) oyOptions_SetFromText( (oyOptions_s**)&forms_args->xforms_data_model_, xpath+1, default_value, OY_CREATE_NEW ); if(default_key) oyFree_m_( default_key ); if(key) oyFree_m_( key ); /*printf("collected:\n%s", oyOptions_GetText( collected_elements, oyNAME_NICK));*/ return 0; }
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, ¤t ); 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; }