int oyAddMonitorEffects ( oyProfile_s * monitor_profile, oyOptions_s ** module_options ) { int error = 0; oyOptions_s * f_options = *module_options; int f_options_n, i, display_white_point = 0; oyOption_s * o = oyOptions_Find( f_options, "display_white_point", oyNAME_PATTERN ); if(o) { const char * value = oyOption_GetValueString(o,0); if(value) { int c = atoi( value ); if(c >= 0) display_white_point = c; } oyOption_Release( &o ); } if( oy_debug ) oyMessageFunc_p( oyMSG_DBG, (oyStruct_s*)f_options, OY_DBG_FORMAT_"display_white_point: %d", OY_DBG_ARGS_, display_white_point); /* erase old display profile */ f_options_n = oyOptions_Count( f_options ); for(i = 0; i < f_options_n; ++i) { oyOption_s * o = oyOptions_Get(f_options, i); if(o && oyFilterRegistrationMatch( oyOption_GetRegistration(o), OY_STD "/icc_color/display.icc_profile.abstract.white_point.automatic", 0 )) { if(oy_debug) oyMessageFunc_p( oyMSG_DBG, (oyStruct_s*)f_options, OY_DBG_FORMAT_"release: %s", OY_DBG_ARGS_, oyOption_GetRegistration(o)); oyOption_Release( &o ); oyOptions_ReleaseAt( f_options, i ); break; } oyOption_Release( &o ); } if(display_white_point) /* not "none" */ { error = oyProfileAddWhitePointEffect( monitor_profile, module_options ); if( error || oy_debug ) oyMessageFunc_p( oyMSG_WARN, (oyStruct_s*)f_options, OY_DBG_FORMAT_"display_white_point: %d %s", OY_DBG_ARGS_, display_white_point, oyProfile_GetText( monitor_profile, oyNAME_DESCRIPTION )); } 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
oyConversion_s * oyConversion_FromImageForDisplay_ ( oyImage_s * image_in, oyImage_s * image_out, oyFilterNode_s ** cc_node, uint32_t flags, oyDATATYPE_e data_type, oyOptions_s * cc_options, oyObject_s obj ) { oyFilterNode_s * in = 0, * out = 0, * icc = 0; int error = 0; oyConversion_s * conversion = 0; oyOptions_s * options = 0; oyOption_s * option = 0; const char * sv = 0; double scale = 0; if(!image_in || !image_out) return NULL; /* start with an empty conversion object */ conversion = oyConversion_New( obj ); /* create a filter node */ in = oyFilterNode_NewWith( "//" OY_TYPE_STD "/root", 0, obj ); /* set the above filter node as the input */ oyConversion_Set( conversion, in, 0 ); /* set the image buffer */ oyFilterNode_SetData( in, (oyStruct_s*)image_in, 0, 0 ); /* add a scale node */ out = oyFilterNode_NewWith( "//" OY_TYPE_STD "/scale", 0, obj ); options = oyFilterNode_GetOptions( out, OY_SELECT_FILTER ); /* scale factor from DB */ option = oyOption_FromRegistration( OY_INTERNAL "/scale/scale", 0 ); error = oyOption_SetFromText( option, 0, 0 ); error = oyOption_SetValueFromDB( option ); scale = 1.0; if(!error) { sv = oyOption_GetValueString( option, 0 ); if(sv) scale = strtod( sv, 0 ); } oyOption_Release( &option ); error = oyOptions_SetFromDouble( &options, OY_INTERNAL "/scale/scale", scale, 0, OY_CREATE_NEW ); oyOptions_Release( &options ); /* append the node */ error = oyFilterNode_Connect( in, "//" OY_TYPE_STD "/data", out, "//" OY_TYPE_STD "/data", 0 ); if(error > 0) fprintf( stderr, "could not add filter: %s\n", "//" OY_TYPE_STD "/scale" ); in = out; /* add a expose node */ out = oyFilterNode_NewWith( "//" OY_TYPE_STD "/expose", 0, obj ); options = oyFilterNode_GetOptions( out, OY_SELECT_FILTER ); /* expose factor */ error = oyOptions_SetFromDouble( &options, "//" OY_TYPE_STD "/expose/expose", 1.0, 0, OY_CREATE_NEW ); oyOptions_Release( &options ); /* append the node */ error = oyFilterNode_Connect( in, "//" OY_TYPE_STD "/data", out, "//" OY_TYPE_STD "/data", 0 ); if(error > 0) fprintf( stderr, "could not add filter: %s\n", "//" OY_TYPE_STD "/expose" ); in = out; /* add a channel node */ out = oyFilterNode_NewWith( "//" OY_TYPE_STD "/channel", 0, obj ); options = oyFilterNode_GetOptions( out, OY_SELECT_FILTER ); /* channel option*/ error = oyOptions_SetFromText( &options, "//" OY_TYPE_STD "/channel/channel", "", OY_CREATE_NEW ); oyOptions_Release( &options ); /* append the node */ error = oyFilterNode_Connect( in, "//" OY_TYPE_STD "/data", out, "//" OY_TYPE_STD "/data", 0 ); if(error > 0) fprintf( stderr, "could not add filter: %s\n", "//" OY_TYPE_STD "/channel" ); in = out; /* create a new filter node */ { icc = out = oyFilterNode_FromOptions( OY_CMM_STD, "//" OY_TYPE_STD "/icc_color", cc_options, NULL ); /* append the new to the previous one */ error = oyFilterNode_Connect( in, "//" OY_TYPE_STD "/data", out, "//" OY_TYPE_STD "/data", 0 ); if(error > 0) fprintf( stderr, "could not add filter: %s\n", OY_CMM_STD ); /* Set the image to the first/only socket of the filter node. * oyFilterNode_Connect() has now no chance to copy it it the other nodes. * We rely on resolving the image later. */ error = oyFilterNode_SetData( out, (oyStruct_s*)image_out, 0, 0 ); if(error != 0) fprintf( stderr, "could not add data\n" ); } /* swap in and out */ if(out) in = out; /* create a node for preparing the image for displaying */ { out = oyFilterNode_NewWith( "//" OY_TYPE_STD "/display", 0, obj ); options = oyFilterNode_GetOptions( out, OY_SELECT_FILTER ); /* data type for display */ error = oyOptions_SetFromInt( &options, "//" OY_TYPE_STD "/display/datatype", data_type, 0, OY_CREATE_NEW ); /* alpha might be support once by FLTK? */ error = oyOptions_SetFromInt( &options, "//" OY_TYPE_STD "/display/preserve_alpha", 1, 0, OY_CREATE_NEW ); oyOptions_Release( &options ); /* append the node */ error = oyFilterNode_Connect( in, "//" OY_TYPE_STD "/data", out, "//" OY_TYPE_STD "/data", 0 ); if(error > 0) fprintf( stderr, "could not add filter: %s\n", "//" OY_TYPE_STD "/display" ); oyFilterNode_SetData( out, (oyStruct_s*)image_out, 0, 0 ); in = out; } /* add a closing node */ out = oyFilterNode_NewWith( "//" OY_TYPE_STD "/output", 0, obj ); error = oyFilterNode_Connect( in, "//" OY_TYPE_STD "/data", out, "//" OY_TYPE_STD "/data", 0 ); if(error > 0) fprintf( stderr, "could not add filter: %s\n", "//" OY_TYPE_STD "/output" ); /* set the output node of the conversion */ oyConversion_Set( conversion, 0, out ); /* apply policies */ /*error = oyOptions_SetFromText( &options, "//" OY_TYPE_STD "//verbose", "true", OY_CREATE_NEW );*/ oyConversion_Correct( conversion, "//" OY_TYPE_STD "/icc_color", flags, options ); oyOptions_Release( &options ); if(cc_node) *cc_node = icc; return conversion; }