int openiccIsDirFull_ (const char* name) { struct stat status; int r = 0; if(!name) return 0; memset(&status,0,sizeof(struct stat)); if(name && name[0]) r = stat(name, &status); if(r != 0 && *openicc_debug > 1) switch (errno) { case EACCES: WARNc_S("Permission denied: %s", name); break; case EIO: WARNc_S("EIO : %s", name); break; case ENAMETOOLONG: WARNc_S("ENAMETOOLONG : %s", name); break; case ENOENT: WARNc_S("A component of the name/file_name does not exist, or the file_name is an empty string: \"%s\"", name); break; case ENOTDIR: WARNc_S("ENOTDIR : %s", name); break; #ifdef HAVE_POSIX case ELOOP: WARNc_S("Too many symbolic links encountered while traversing the name: %s", name); break; case EOVERFLOW: WARNc_S("EOVERFLOW : %s", name); break; #endif default: WARNc_S("%s : %s", strerror(errno), name); break; } r = !r && ((status.st_mode & S_IFMT) & S_IFDIR); return r; }
/** Function oyCMMapi4_Create * @memberof oyCMMapi4_s * @brief Custom CMMapi4 constructor * * @param init custom initialisation * @param msg_set message function setter * @param registration the modules @ref registration string, * @param version module version * - 0: major - should be stable for the live time of a filter * - 1: minor - mark new features * - 2: patch version - correct errors * @param module_api tell compatibility with Oyranos API * - 0: last major Oyranos version during development time, e.g. 0 * - 1: last minor Oyranos version during development time, e.g. 9 * - 2: last Oyranos patch version during development time, e.g. 5 * @param context_type tell the context type, if any * the data type of the context returned by oyCMMapi4_s::oyCMMFilterNode_ContextToMem_f, mandatory in case of a set oyCMMapi4_s::oyCMMFilterNode_ContextToMem * e.g. ::oyCOLOR_ICC_DEVICE_LINK / "oyDL" * @param contextToMem * only mandatory for context producing filters, e.g. "//color/icc" * @param getText optionally set a * oyCMMFilterNode_ContextToMem, * used to override a Oyranos side hash creation * @param ui a UI description * provide a oyCMMapi4_s::ui->getText( select, type ) call. The "select" * argument shall cover at least "name" and "help" * @param object a optional object * * @version Oyranos: 0.9.5 * @since 2013/06/09 (Oyranos: 0.9.5) * @date 2013/06/09 */ OYAPI oyCMMapi4_s* OYEXPORT oyCMMapi4_Create ( oyCMMInit_f init, oyCMMMessageFuncSet_f msg_set, const char * registration, int32_t version[3], int32_t module_api[3], const char * context_type, oyCMMFilterNode_ContextToMem_f contextToMem, oyCMMFilterNode_GetText_f getText, oyCMMui_s * ui, oyObject_s object ) { oyCMMapi4_s_ * api4 = (oyCMMapi4_s_*) oyCMMapi4_New( object ); if(!api4) { WARNc_S(_("MEM Error.")); return NULL; } oyCMMapi_Set( (oyCMMapi_s*) api4, init, msg_set, registration, version, module_api ); if(context_type) memcpy( api4->context_type, context_type, 8 ); api4->oyCMMFilterNode_ContextToMem = contextToMem; api4->oyCMMFilterNode_GetText = getText; api4->ui = (oyCMMui_s_*) oyCMMui_Copy( ui, object ); if(api4->ui) { api4->ui->parent = (oyCMMapiFilter_s*) oyCMMapi4_Copy( (oyCMMapi4_s*) api4, NULL ); } return (oyCMMapi4_s*) api4; }
int openiccMakeDir_ (const char* path) { const char * full_name = path; char * path_parent = 0, * path_name = 0; int rc = !full_name; #ifdef HAVE_POSIX mode_t mode = S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH; /* 0755 */ #endif if(full_name) path_name = openiccExtractPathFromFileName_(full_name); if(path_name) { if(!openiccIsDirFull_(path_name)) { path_parent = openiccPathGetParent_(path_name); if(!openiccIsDirFull_(path_parent)) rc = openiccMakeDir_(path_parent); if(path_parent) free( path_parent ); if(!rc) rc = mkdir (path_name #ifdef HAVE_POSIX , mode #endif ); if(rc && *openicc_debug > 1) switch (errno) { case EACCES: WARNc_S("Permission denied: %s", path); break; case EIO: WARNc_S("EIO : %s", path); break; case ENAMETOOLONG: WARNc_S("ENAMETOOLONG : %s", path); break; case ENOENT: WARNc_S("A component of the path/file_name does not exist, or the file_name is an empty string: \"%s\"", path); break; case ENOTDIR: WARNc_S("ENOTDIR : %s", path); break; #ifdef HAVE_POSIX case ELOOP: WARNc_S("Too many symbolic links encountered while traversing the path: %s", path); break; case EOVERFLOW: WARNc_S("EOVERFLOW : %s", path); break; #endif default: WARNc_S("%s : %s", strerror(errno), path); break; } } free( path_name );; } return rc; }
char * openiccReadFile( const char * file_name, int * size_ptr ) { FILE * fp = NULL; int size = 0, s = 0; char * text = NULL; if(file_name) { fp = fopen(file_name,"rb"); if(fp) { fseek( fp, 0L, SEEK_END ); size = ftell( fp ); if(size == -1) { switch(errno) { case EBADF: WARNc_S("Not a seekable stream %d", errno); break; case EINVAL: WARNc_S("Wrong argument %d", errno); break; default: WARNc_S("%s", strerror(errno)); break; } if(size_ptr) *size_ptr = size; fclose( fp ); return NULL; } rewind(fp); text = malloc(size+1); if(text == NULL) { WARNc_S( "Error: Could allocate memory: %lu", (long unsigned int)size); fclose( fp ); return NULL; } s = fread(text, sizeof(char), size, fp); text[size] = '\000'; if(s != size) WARNc_S( "Error: fread %lu but should read %lu", (long unsigned int) s, (long unsigned int)size); fclose( fp ); } else { WARNc_S( "Error: Could not open file - \"%s\"", file_name); } } if(size_ptr) *size_ptr = size; return text; }
int openiccIsFileFull_ (const char* fullFileName, const char * read_mode) { struct stat status; int r = 0; const char* name = fullFileName; memset(&status,0,sizeof(struct stat)); if(name && name[0]) r = stat(name, &status); if(r != 0 && *openicc_debug > 1) switch (errno) { case EACCES: WARNc_S("Permission denied: %s", name); break; case EIO: WARNc_S("EIO : %s", name); break; case ENAMETOOLONG: WARNc_S("ENAMETOOLONG : %s", name); break; case ENOENT: WARNc_S("A component of the name/file_name does not exist, or the file_name is an empty string: \"%s\"", name); break; case ENOTDIR: WARNc_S("ENOTDIR : %s", name); break; case ELOOP: WARNc_S("Too many symbolic links encountered while traversing the name: %s", name); break; case EOVERFLOW: WARNc_S("EOVERFLOW : %s", name); break; default: WARNc_S("%s : %s", strerror(errno), name); break; } r = !r && ( ((status.st_mode & S_IFMT) & S_IFREG) || ((status.st_mode & S_IFMT) & S_IFLNK) ); if (r) { FILE* fp = fopen (name, read_mode); if (!fp) { openiccMessage_p( openiccMSG_DBG, 0, "not existent: %s", name ); r = 0; } else { fclose (fp); } } return r; }
/** Function oyFilterNode_SetData * @memberof oyFilterNode_s * @brief Set process data to a filter socket * * @param[in,out] node filter node * @param[in] data data * @param[in] socket_pos position of socket * @param[in] object a object to not only set a reference * @return error * * @version Oyranos: 0.1.10 * @since 2009/03/05 (Oyranos: 0.1.10) * @date 2009/03/05 */ int oyFilterNode_SetData ( oyFilterNode_s * node, oyStruct_s * data, int socket_pos, oyObject_s * object ) { oyFilterNode_s * s = node; oyFilterSocket_s_ * socket = 0; if(!s) return 0; oyCheckType__m( oyOBJECT_FILTER_NODE_S, return 0 ); socket = (oyFilterSocket_s_*)oyFilterNode_GetSocket( node, socket_pos ); if(socket) { if(socket->data && socket->data->release) socket->data->release( &socket->data ); if(data && data->copy) { socket->data = data->copy( data, object ); if(oy_debug_objects >= 0) oyObjectDebugMessage_( socket->data->oy_, __func__, oyStructTypeToText(socket->data->type_) ); } else socket->data = data; oyFilterSocket_Release( (oyFilterSocket_s **) &socket ); } else { WARNc_S("Node has no socket. Can not assign data."); return -1; } return 0; }
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; }
int openiccWriteFile ( const char * filename, void * mem, int size ) { FILE *fp = 0; const char * full_name = filename; int r = !filename; int written_n = 0; char * path = 0; if(!r) { path = openiccExtractPathFromFileName_( full_name ); r = openiccMakeDir_( path ); } if(!r) { fp = fopen(full_name, "wb"); if ((fp != 0) && mem && size) { #if 0 do { r = fputc ( block[pt++] , fp); } while (--size); #else written_n = fwrite( mem, 1, size, fp ); if(written_n != size) r = errno; #endif } else if(mem && size) r = errno; else WARNc_S("no data to write into: \"%s\"", filename ); if(r && *openicc_debug > 1) { switch (errno) { case EACCES: WARNc_S("Permission denied: %s", filename); break; case EIO: WARNc_S("EIO : %s", filename); break; case ENAMETOOLONG: WARNc_S("ENAMETOOLONG : %s", filename); break; case ENOENT: WARNc_S("A component of the path/file_name does not exist, or the file_name is an empty string: \"%s\"", filename); break; case ENOTDIR: WARNc_S("ENOTDIR : %s", filename); break; #ifdef HAVE_POSIX case ELOOP: WARNc_S("Too many symbolic links encountered while traversing the path: %s", filename); break; case EOVERFLOW: WARNc_S("EOVERFLOW : %s", filename); break; #endif default: WARNc_S("%s : %s", strerror(errno), filename);break; } } if (fp) fclose (fp); } if(path) free( path ); return written_n; }
/** Function oyConfigs_Modify * @memberof oyConfigs_s * @brief Ask a module for device informations or other direct calls * * * @param[in,out] configs The passed configs first member is used * to obtain a registration string and * select a appropriate module. * Regarding the module the * configs need to be homogenous. * All configs are passed at once to the * module. Mixing configs from different * modules is not defined. * @param[in] options options to pass to the module; With zero * the usage instructions are requested. * @return 0 - good, >= 1 - error, issue <= -1 * * @version Oyranos: 0.1.10 * @since 2009/08/21 (Oyranos: 0.1.10) * @date 2009/08/25 */ OYAPI int OYEXPORT oyConfigs_Modify ( oyConfigs_s * configs, oyOptions_s * options ) { int error = !oyConfigs_Count( configs ); oyConfig_s_ * config = 0; oyConfigs_s * s = configs; int i; uint32_t count = 0, * rank_list = 0; char ** texts = 0, * registration_domain = 0; oyCMMapi8_s_ * cmm_api8 = 0; if(error > 0) { WARNc_S( "\n No devices provided. Give up" ); return 0; } oyCheckType__m( oyOBJECT_CONFIGS_S, return 1 ) oyExportStart_(EXPORT_CHECK_NO); if(error <= 0) { /** 1. pick the first device to select a registration */ config = (oyConfig_s_*)oyConfigs_Get( configs, 0 ); /** 1.2 get all device class module names from the firsts oyConfig_s * registration */ error = oyConfigDomainList ( config->registration, &texts, &count, &rank_list, 0 ); oyConfig_Release( (oyConfig_s**)&config ); } /** 2. call each modules oyCMMapi8_s::oyConfigs_Modify */ for( i = 0; i < count; ++i ) { registration_domain = texts[i]; if(error <= 0) { cmm_api8 = (oyCMMapi8_s_*) oyCMMsGetFilterApi_( 0, registration_domain, oyOBJECT_CMM_API8_S ); error = !cmm_api8; } if(error <= 0) error = !cmm_api8->oyConfigs_Modify; if(error <= 0) error = cmm_api8->oyConfigs_Modify( configs, options ); } oyStringListRelease_( &texts, count, oyDeAllocateFunc_ ); if(rank_list) oyDeAllocateFunc_( rank_list ); oyExportEnd_(); return error; }
/** Function oyConfigs_FromDeviceClass * @memberof oyConfigs_s * @brief Ask a module for device informations or other direct calls * * @param[in] device_type the device type ::oyFILTER_REG_TYPE, * defaults to OY_TYPE_STD (optional) * @param[in] device_class the device class, e.g. "monitor", * ::oyFILTER_REG_APPLICATION * @param[in] options options to pass to the module, for zero * the usage instructions are requested, * a option "device_name" can be used * as filter * @param[out] devices the devices * @param[in] object the optional object * @return 0 - good, >= 1 - error * * @verbatim // pass empty options to the module to get a usage message oyOptions_s * options = 0; int error = oyConfigs_FromDeviceClass( OY_TYPE_STD, "monitor", options, 0, 0 ); @endverbatim * * @version Oyranos: 0.1.10 * @since 2009/01/28 (Oyranos: 0.1.10) * @date 2009/01/30 */ OYAPI int OYEXPORT oyConfigs_FromDeviceClass ( const char * device_type, const char * device_class, oyOptions_s * options, oyConfigs_s ** devices, oyObject_s object ) { int error = !device_class || !device_class[0]; oyConfig_s * device = 0; oyConfigs_s * configs = 0; int i, j, j_n; uint32_t count = 0, * rank_list = 0; char ** texts = 0, * device_class_registration = 0; const char * tmp = 0, * device_name = 0; if(error > 0) { WARNc_S( "\n No device_class argument provided. Give up" ); return 0; } /** 1. obtain detailed and expensive device informations */ if(options) { options = oyOptions_Copy( options, 0 ); device_name = oyOptions_FindString( options, "device_name", 0 ); } /** 1.2.1 build a device class registration string */ if(error <= 0) { device_class_registration = oyDeviceRegistrationCreate_( device_type, device_class, device_name, device_class_registration ); error = !device_class_registration; } /** 1.2.2 get all device class module names */ if(error <= 0) error = oyConfigDomainList ( device_class_registration, &texts, &count, &rank_list, 0 ); if(devices && !*devices) *devices = oyConfigs_New( object ); /** 1.3 ask each module */ for( i = 0; i < count; ++i ) { const char * registration_domain = texts[i]; /** 1.3.1 call into module */ error = oyConfigs_FromDomain( registration_domain, options, &configs, object); if(devices && *devices) j_n = oyConfigs_Count( configs ); else j_n = 0; for( j = 0; j < j_n; ++j ) { device = oyConfigs_Get( configs, j ); if(device_name) { /** 1.3.1.1 Compare the device_name with the device_name option * and collect the matching devices. */ tmp = oyConfig_FindString( device, "device_name", 0 ); if(tmp && oyStrcmp_( tmp, device_name ) == 0) oyConfigs_MoveIn( *devices, &device, -1 ); } else /** 1.3.1.2 ... or collect all device configurations */ oyConfigs_MoveIn( *devices, &device, -1 ); oyConfig_Release( &device ); } oyConfigs_Release( &configs ); } if(devices) j_n = oyConfigs_Count( *devices ); else j_n = 0; for( j = 0; j < j_n; ++j ) { device = oyConfigs_Get( *devices, j ); /** The basic call on how to obtain the configuration is added here as * the objects name. "properties" and "list" are known. */ if(oyOptions_FindString( options, "command", "properties" ) || oyOptions_FindString( options, "oyNAME_DESCRIPTION", 0 )) oyObject_SetName( device->oy_, "properties", oyNAME_NAME ); else if(oyOptions_FindString( options, "list", 0 )) oyObject_SetName( device->oy_, "list", oyNAME_NAME ); oyConfig_Release( &device ); } oyOptions_Release( &options ); return error; }
/** @internal * Function oyFilterGraph_New_ * @memberof oyFilterGraph_s_ * @brief allocate a new oyFilterGraph_s_ object * * @version Oyranos: * @since 2010/04/26 (Oyranos: 0.1.10) * @date 2010/04/26 */ oyFilterGraph_s_ * oyFilterGraph_New_ ( oyObject_s object ) { /* ---- start of common object constructor ----- */ oyOBJECT_e type = oyOBJECT_FILTER_GRAPH_S; int error = 0; oyObject_s s_obj = oyObject_NewFrom( object ); oyFilterGraph_s_ * s = 0; if(s_obj) s = (oyFilterGraph_s_*)s_obj->allocateFunc_(sizeof(oyFilterGraph_s_)); else { WARNc_S(_("MEM Error.")); return NULL; } if(!s) { if(s_obj) oyObject_Release( &s_obj ); WARNc_S(_("MEM Error.")); return NULL; } error = !memset( s, 0, sizeof(oyFilterGraph_s_) ); if(error) WARNc_S( "memset failed" ); memcpy( s, &type, sizeof(oyOBJECT_e) ); s->copy = (oyStruct_Copy_f) oyFilterGraph_Copy; s->release = (oyStruct_Release_f) oyFilterGraph_Release; s->oy_ = s_obj; /* ---- start of custom FilterGraph constructor ----- */ error += !oyObject_SetParent( s_obj, oyOBJECT_FILTER_GRAPH_S, (oyPointer)s ); /* ---- end of custom FilterGraph constructor ------- */ /* ---- end of common object constructor ------- */ if(error) WARNc_S( "oyObject_SetParent failed" ); /* ---- start of custom FilterGraph constructor ----- */ error += oyFilterGraph_Init__Members( s ); /* ---- end of custom FilterGraph constructor ------- */ if(!oy_filtergraph_init_) { oy_filtergraph_init_ = 1; oyStruct_RegisterStaticMessageFunc( type, oyFilterGraph_StaticMessageFunc_ ); } if(error) WARNc1_S("%d", error); if(oy_debug_objects >= 0) oyObject_GetId( s->oy_ ); return s; }
/** @internal * Function oyOption_New_ * @memberof oyOption_s_ * @brief allocate a new oyOption_s_ object * * @version Oyranos: * @since 2010/04/26 (Oyranos: 0.1.10) * @date 2010/04/26 */ oyOption_s_ * oyOption_New_ ( oyObject_s object ) { /* ---- start of common object constructor ----- */ oyOBJECT_e type = oyOBJECT_OPTION_S; int error = 0; oyObject_s s_obj = oyObject_NewFrom( object ); oyOption_s_ * s = 0; if(s_obj) s = (oyOption_s_*)s_obj->allocateFunc_(sizeof(oyOption_s_)); if(!s || !s_obj) { WARNc_S(_("MEM Error.")); return NULL; } error = !memset( s, 0, sizeof(oyOption_s_) ); if(error) WARNc_S( "memset failed" ); memcpy( s, &type, sizeof(oyOBJECT_e) ); s->copy = (oyStruct_Copy_f) oyOption_Copy; s->release = (oyStruct_Release_f) oyOption_Release; s->oy_ = s_obj; /* ---- start of custom Option constructor ----- */ error += !oyObject_SetParent( s_obj, oyOBJECT_OPTION_S, (oyPointer)s ); /* ---- end of custom Option constructor ------- */ /* ---- end of common object constructor ------- */ if(error) WARNc_S( "oyObject_SetParent failed" ); /* ---- start of custom Option constructor ----- */ error += oyOption_Init__Members( s ); /* ---- end of custom Option constructor ------- */ if(!oy_option_init_) { oy_option_init_ = 1; oyStruct_RegisterStaticMessageFunc( type, oyOption_StaticMessageFunc_ ); } if(error) WARNc1_S("%d", error); if(oy_debug) oyObject_GetId( s->oy_ ); return s; }
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 ); } } } }
/** @brief copy pure colors * * Handle color only. * With a empty \b from variable set -1 as default in \b to. * * @since Oyranos: version 0.1.8 * @date september 2007 (API 0.1.8) */ void oyCopyColor ( const double * from, double * to, int n, oyProfile_s * ref, int channels_n ) { int i, j; icColorSpaceSignature sig = 0; int c = 0; int error = 0; if(!n || !to) return; if(ref) sig = oyProfile_GetSignature ( ref, oySIGNATURE_COLOR_SPACE ); else sig = icSigXYZData; c = oyICCColorSpaceGetChannelCount( sig ); if(from) { error = !memcpy( to, from, sizeof(double) * (n * c) ); if(error) WARNc_S("Problem with memcpy."); } else { if(!channels_n && c) channels_n = c; else if(channels_n && !c) c = channels_n; if(channels_n) switch(sig) { case icSigLabData: case icSigLuvData: case icSigHsvData: case icSigHlsData: case icSigYCbCrData: for( i = 0; i < n; ++i ) { to[i*channels_n+0] = -1; to[i*channels_n+1] = 0; to[i*channels_n+2] = 0; for( j = c; j < channels_n; ++j ) if(j==c) to[i*channels_n+j] = 1; /* set alpha */ else to[i*channels_n+j] = 0; } break; case icSigXYZData: case icSigRgbData: default: for( i = 0; i < n; ++i ) { for( j = 0; j < channels_n; ++j ) if(j < c) to[i*channels_n+j] = -1; else if(j==c) to[i*channels_n+j] = 1; /* set alpha */ else to[i*channels_n+j] = 0; } break; } } }