/** Function oyDeviceGetProfile * @brief order a device profile * * This function is designed to satisfy most users as it tries to deliver * a profile all the time. * Following code can almost allways expect some profile to go with. * It tries hard to get a current profile or set the system up and retry or * get at least one basic profile. * * For a basic and thus weaker call to the device use * oyDeviceAskProfile2() instead. * * @param device the device * @param options * - options passed to the backend * - "///icc_profile_flags" with a int * containing ::OY_ICC_VERSION_2 or * ::OY_ICC_VERSION_4 * @param profile the device's ICC profile * @return error * * @version Oyranos: 0.9.7 * @date 2018/02/23 * @since 2009/02/08 (Oyranos: 0.1.10) */ OYAPI int OYEXPORT oyDeviceGetProfile ( oyConfig_s * device, oyOptions_s * options, oyProfile_s ** profile ) { int error = !device, l_error = 0; oyConfig_s * s = device; oyProfile_s * p; oyOption_s * o = NULL; oyCheckType__m( oyOBJECT_CONFIG_S, return 1 ) l_error = oyDeviceAskProfile2( device, options, profile ); OY_ERR /** This function does a device setup in case no profile is delivered * by the according module. */ if(error != 0 && !*profile) { oyMessageFunc_p( oyMSG_DBG,(oyStruct_s*)device, OY_DBG_FORMAT_ "calling oyDeviceSetup2()\n", OY_DBG_ARGS_ ); error = oyDeviceSetup2( device, options ); } /* The backend shows with the existence of the "icc_profile" response that it * can handle device profiles through the driver. */ if(error <= 0) o = oyConfig_Find( device, "icc_profile" ); p = (oyProfile_s*) oyOption_GetStruct( o, oyOBJECT_PROFILE_S ); if(oyProfile_GetSignature( p, oySIGNATURE_MAGIC ) == icMagicNumber) *profile = p; else if(!error) error = -1; p = 0; if(error <= 0) { l_error = oyDeviceAskProfile2( device, options, profile ); OY_ERR }
/** @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; } } }
/** 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; }
/** @brief implement oyCMMFilter_GetNext_f() * * @version Oyranos: 0.9.6 * @date 2016/04/04 * @since 2013/06/10 (Oyranos: 0.9.5) */ int oyraFilter_ImageExposeRun ( oyFilterPlug_s * requestor_plug, oyPixelAccess_s * ticket ) { int result = 0, error = 0; oyFilterSocket_s * socket = 0; oyFilterNode_s * input_node = 0, * node = 0; oyFilterPlug_s * plug = 0; oyImage_s * image = 0; int dirty = 0; socket = oyFilterPlug_GetSocket( requestor_plug ); node = oyFilterSocket_GetNode( socket ); image = (oyImage_s*)oyFilterSocket_GetData( socket ); if(!image) { result = 1; goto clean_expose1; } if(oy_debug) oyra_msg( oyMSG_WARN, (oyStruct_s*)ticket, OY_DBG_FORMAT_ "image [%d](%d)\n",OY_DBG_ARGS_,oyStruct_GetId((oyStruct_s*)image),oyImage_GetWidth(image) ); { oyRectangle_s * ticket_roi = oyPixelAccess_GetArrayROI( ticket ); double expose = 1.0; oyOptions_s * node_opts = oyFilterNode_GetOptions( node, 0 ); if(!node_opts) dirty = 1; if(dirty) { result = dirty; goto clean_expose2; } plug = oyFilterNode_GetPlug( node, 0 ); /* select node */ input_node = oyFilterNode_GetPlugNode( node, 0 ); /* find filters own expose factor */ error = oyOptions_FindDouble( node_opts, "//" OY_TYPE_STD "/expose/expose", 0, &expose ); if(error) WARNc2_S("%s %d", _("found issues"),error); if(oy_debug > 2) oyra_msg( oyMSG_WARN, (oyStruct_s*)ticket, OY_DBG_FORMAT_ "%s expose: %f",OY_DBG_ARGS_, oyPixelAccess_Show(ticket), expose); if(expose != 1.0) { oyImage_s * output_image = oyPixelAccess_GetOutputImage( ticket ); oyArray2d_s * array_out = oyPixelAccess_GetArray( ticket ); oyProfile_s * p = oyImage_GetProfile( output_image ); icColorSpaceSignature sig = oyProfile_GetSignature( p, oySIGNATURE_COLOR_SPACE ); int layout_dst = oyImage_GetPixelLayout( output_image, oyLAYOUT ); int channels_dst = oyToChannels_m( layout_dst ); int byte_swap = oyToByteswap_m( layout_dst ); int ticket_array_pix_width; /* avoid division by zero */ if(!channels_dst) channels_dst = 1; ticket_array_pix_width = oyArray2d_GetWidth( array_out ) / channels_dst; { int w,h,x,y, i, start_x,start_y; unsigned int max = 1; oyRectangle_s * ticket_roi = oyPixelAccess_GetArrayROI( ticket ); oyRectangle_s_ roi_= {oyOBJECT_RECTANGLE_S,0,0,0, 0,0,0,0}; oyRectangle_s * roi = (oyRectangle_s*)&roi_; uint8_t ** array_out_data; /* get pixel layout infos for copying */ oyDATATYPE_e data_type_out = oyToDataType_m( layout_dst ); int bps_out = oyDataTypeGetSize( data_type_out ); /* get the source pixels */ result = oyFilterNode_Run( input_node, plug, ticket ); /* get the channel buffers */ array_out_data = oyArray2d_GetData( array_out ); w = oyArray2d_GetWidth( array_out ) / channels_dst; h = oyArray2d_GetHeight( array_out ); oyRectangle_SetByRectangle( roi, ticket_roi ); oyRectangle_Scale( roi, ticket_array_pix_width ); start_x = OY_ROUND(roi_.x); start_y = OY_ROUND(roi_.y); switch(data_type_out) { case oyUINT8: max = 255; break; case oyUINT16: max = 65535; break; case oyUINT32: max = UINT32_MAX; break; default: break; } /* expose the samples */ #if defined(USE_OPENMP) #pragma omp parallel for private(x,y,i) #endif for(y = start_y; y < h; ++y) { for(x = start_x; x < w; ++x) { if( (sig == icSigRgbData || sig == icSigXYZData || sig == icSigLabData || sig == icSigYCbCrData) && channels_dst >= 3) { double rgb[3], v; for(i = 0; i < 3; ++i) { switch(data_type_out) { case oyUINT8: rgb[i] = array_out_data[y][x*channels_dst*bps_out + i*bps_out]; break; case oyUINT16: { uint16_t v = *((uint16_t*)&array_out_data[y][x*channels_dst*bps_out + i*bps_out]); if(byte_swap) v = oyByteSwapUInt16(v); rgb[i] = v; } break; case oyUINT32: { uint32_t v = *((uint32_t*)&array_out_data[y][x*channels_dst*bps_out + i*bps_out]); if(byte_swap) v = oyByteSwapUInt32(v); rgb[i] = v; } break; case oyHALF: v = *((uint16_t*)&array_out_data[y][x*channels_dst*bps_out + i*bps_out]); rgb[i] = v; break; case oyFLOAT: v = *((float*)&array_out_data[y][x*channels_dst*bps_out + i*bps_out]); rgb[i] = v; break; case oyDOUBLE: v = *((double*)&array_out_data[y][x*channels_dst*bps_out + i*bps_out]); rgb[i] = v; break; } } oySensibleClip ( rgb, sig, max, expose ); for(i = 0; i < 3; ++i) { v = rgb[i]; switch(data_type_out) { case oyUINT8: array_out_data[y][x*channels_dst*bps_out + i*bps_out] = v; break; case oyUINT16: { uint16_t u16 = v; *((uint16_t*)&array_out_data[y][x*channels_dst*bps_out + i*bps_out]) = byte_swap ? oyByteSwapUInt16(u16) : u16; } break; case oyUINT32: { uint32_t u32 = v; *((uint32_t*)&array_out_data[y][x*channels_dst*bps_out + i*bps_out]) = byte_swap ? oyByteSwapUInt16(u32) : u32; } break; case oyHALF: *((uint16_t*)&array_out_data[y][x*channels_dst*bps_out + i*bps_out]) = v; break; case oyFLOAT: *((float*)&array_out_data[y][x*channels_dst*bps_out + i*bps_out]) = v; break; case oyDOUBLE: *((double*)&array_out_data[y][x*channels_dst*bps_out + i*bps_out]) = v; break; } } } else for(i = 0; i < channels_dst; ++i) { int v; switch(data_type_out) { case oyUINT8: v = array_out_data[y][x*channels_dst*bps_out + i*bps_out] * expose; if(v > 255) v = 255; array_out_data[y][x*channels_dst*bps_out + i*bps_out] = v; break; case oyUINT16: v = *((uint16_t*)&array_out_data[y][x*channels_dst*bps_out + i*bps_out]); if(byte_swap) v = oyByteSwapUInt16(v); v *= expose; if(v > 65535) v = 65535; *((uint16_t*)&array_out_data[y][x*channels_dst*bps_out + i*bps_out]) = byte_swap ? oyByteSwapUInt16(v) : v; break; case oyUINT32: *((uint32_t*)&array_out_data[y][x*channels_dst*bps_out + i*bps_out]) *= expose; break; case oyHALF: *((uint16_t*)&array_out_data[y][x*channels_dst*bps_out + i*bps_out]) *= expose; break; case oyFLOAT: *((float*)&array_out_data[y][x*channels_dst*bps_out + i*bps_out]) *= expose; break; case oyDOUBLE: *((double*)&array_out_data[y][x*channels_dst*bps_out + i*bps_out]) *= expose; break; } } } } } oyArray2d_Release( &array_out ); oyImage_Release( &output_image ); oyProfile_Release( &p ); } else /* expose == 1.0 */ { result = oyFilterNode_Run( input_node, plug, ticket ); } clean_expose2: oyOptions_Release( &node_opts ); oyFilterPlug_Release( &plug ); oyRectangle_Release( &ticket_roi ); oyFilterNode_Release( &input_node ); } clean_expose1: oyImage_Release( &image ); oyFilterSocket_Release( &socket ); oyFilterNode_Release( &node ); return result; }