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; }
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; }
void ColorContext::setupColorLookupTable(bool advanced) { kDebug() << m_outputName; oyProfile_s *dummyProfile = 0; oyOptions_s *options = 0; if (!m_dstProfile) m_dstProfile = dummyProfile = oyProfile_FromStd(oyASSUMED_WEB, icc_profile_flags, 0); /* skip dummyProfile to dummyProfile conversion */ if (!m_srcProfile && dummyProfile) { if (dummyProfile) oyProfile_Release(&dummyProfile); return; } if (!m_srcProfile) { m_srcProfile = oyProfile_FromStd(oyASSUMED_WEB, icc_profile_flags, 0); if (!m_srcProfile) { kError() << "Output" << m_outputName << ":" << "no assumed dummyProfile source profile"; kWarning() << "Output" << m_outputName << "using dummy clut"; buildDummyClut(m_clut); return; } } int error = 0; int flags = 0; // Optionally set advanced options from Oyranos if (advanced) flags = oyOPTIONATTRIBUTE_ADVANCED; // Allocate memory for clut data m_clut.resize(CLUT_ELEMENT_COUNT); kDebug() << "Color conversion for" << m_outputName << "flags" << flags << (advanced ? "advanced" : ""); oyImage_s *imageIn = oyImage_Create( LUT_GRID_POINTS, LUT_GRID_POINTS * LUT_GRID_POINTS, m_clut.data(), OY_TYPE_123_16, m_srcProfile, 0); oyImage_s *imageOut = oyImage_Create( LUT_GRID_POINTS, LUT_GRID_POINTS * LUT_GRID_POINTS, m_clut.data(), OY_TYPE_123_16, m_dstProfile, 0); oyConversion_s *conversion = oyConversion_CreateBasicPixels(imageIn, imageOut, options, 0); if (!conversion) { kWarning() << "No conversion created for" << m_outputName; if (dummyProfile) oyProfile_Release(&dummyProfile); return; } oyOptions_Release(&options); error = oyOptions_SetFromText(&options, "//"OY_TYPE_STD"/config/display_mode", "1", OY_CREATE_NEW); if (error) { kWarning() << "Oy options error:" << error; if (dummyProfile) oyProfile_Release(&dummyProfile); return; } error = oyConversion_Correct(conversion, "//"OY_TYPE_STD"/icc", flags, options); if (error) { kWarning() << "Failed to correct conversion for" << m_outputName << "flags" << flags; if (dummyProfile) oyProfile_Release(&dummyProfile); return; } oyFilterGraph_s *conversionGraph = oyConversion_GetGraph(conversion); oyFilterNode_s *iccNode = oyFilterGraph_GetNode(conversionGraph, -1, "///icc", 0); // See what to search for in the cache QByteArray entryText; const char *t = oyFilterNode_GetText(iccNode, oyNAME_NAME); if (t) entryText = t; oyStructList_s *cache = Display::getInstance()->cache(); oyHash_s *entry = oyStructList_GetHash(cache, 0, entryText.constData()); oyArray2d_s *oyClut = (oyArray2d_s*) oyHash_GetPointer(entry, oyOBJECT_ARRAY2D_S); char ** array2d = (char**)oyArray2d_GetData( oyClut ); oyFilterNode_Release(&iccNode); oyFilterGraph_Release(&conversionGraph); if (oyClut) { // Found in cache kDebug() << "clut" << oyClut << "obtained from cache using entry" << entryText; memcpy(m_clut.data(), array2d[0], CLUT_DATA_SIZE); } else { kDebug() << "clut not found in cache using entry" << entryText << ", doing conversion"; // Create dummy / identity clut data for conversion input buildDummyClut(m_clut); // Do conversion error = oyConversion_RunPixels(conversion, 0); if (error) { kWarning() << "Output" << m_outputName << "Error" << error << "in conversion run pixels"; if (dummyProfile) oyProfile_Release(&dummyProfile); return; } // Save to cache oyClut = oyArray2d_Create( NULL, LUT_GRID_POINTS * 3, LUT_GRID_POINTS * LUT_GRID_POINTS, oyUINT16, NULL); array2d = (char**)oyArray2d_GetData( oyClut ); memcpy(array2d[0], m_clut.data(), CLUT_DATA_SIZE); oyHash_SetPointer(entry, (oyStruct_s*) oyClut); } oyOptions_Release(&options); oyImage_Release(&imageIn); oyImage_Release(&imageOut); oyConversion_Release(&conversion); if (!m_dstProfile) kDebug() << "Output" << m_outputName << "no profile"; }