点击查看详细介绍

UF_DISP_ask_closest_color() 函数的参数解释说明、函数详细用法,以及实例代码演示

misnn 7年前 985 0

购买与咨询 NX 二次开发视频教程,请联系微信号:13890821008  QQ号:85585969  


函数结构:
UF_DISP_ask_closest_color
(
int clr_model,
double clr_values [ 3 ],
int clr_cmp_mtd,
int * clr_num
)

函数说明:
确定颜色的颜色表对象(CTO)“最接近”给定的颜色值,根据指定的颜色的比较 方法。返回最接近的颜色的索引。UF_DISP_CCM_EUCLIDEAN_DISTANCE - 此方法返回色这是最欧几里得距离的给定的彩色在RGB色彩立方体。注意,背景颜色不视为候选人。必须有当这个函数被调用加载的一部分。

函数参数:
第1个参数为输入:
输入int 整数型的参数,参数的变量格式为clr_model,在clr_values值的颜色模型;以下常量在uf_disp.h定义:UF_DISP_rgb_model UF_DISP_hsv_model UF_DISP_hls_model

第2个参数为输入:
输入double 双精度类型的参数,参数的变量格式为clr_values [ 3 ],RGB:clr_values[0]:代表颜色,其中每个值的含义和范围取决于颜色模型指定了三个双打0.0&下;=红&下;= 1.0 clr_values[1]:0.0&下;=绿色&下;=1.0 clr_values[2]:0.0&下;=蓝&下;= 1.0 HSV:clr_values[0]:0.0&下;=色调&下;=360.0 clr_values[1]:0.0&下;=饱和&下;= 1.0 clr_values[2]:0.0<=价值<=1.0 HLS:clr_values[0]:0.0<=色调<=360.0 clr_values[2]:0.0<=光<=1.0 clr_values[1]:0.0<=饱和度和LT=1.0

第3个参数为输入:
输入int 整数型的参数,参数的变量格式为clr_cmp_mtd,颜色比较法目前只UF_DISP_CCM欧氏距离定义。

第4个参数为输出:
输出int * 整数型的参数,参数的变量格式为clr_num,最接近的颜色的数目。范围:1 ..(在CTO#彩色记录) - 1注:背景颜色不视为候选人。

UF_DISP_ask_closest_color函数实例代码演示:
下面的示例减小了每种颜色的饱和度10%的色表。背景颜色变为蓝色。
[quote]
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <uf.h>
#include <uf_disp.h>
#define UF_CALL(X) (report( __FILE__, __LINE__, #X, (X)))
static int report( char *file, int line, char *call, int irc)
{
if (irc)
{
char messg[133];
printf("%s, line %d: %s\n", file, line, call);
(UF_get_fail_message(irc, messg)) ?
printf(" returned a %d\n", irc) :
printf(" returned error %d: %s\n", irc, messg);
}
return(irc);
}
static void do_ugopen_api(void)
{
int count, clr_num, name_len;
char *clr_name;
char *new_name;
double clr_values[3];
UF_CALL(UF_DISP_ask_color_count( &count ));
for (clr_num = 1; clr_num < count; clr_num++ )
{
/* Request "hsv" color values */
UF_CALL(UF_DISP_ask_color( clr_num,
UF_DISP_hsv_model,
&clr_name,
clr_values ));
/* Reduce the saturation by 10% */
clr_values[1] *= 0.9;
/* Append "_dil" (i.e. diluted) to the color name */
name_len = strlen( clr_name );
new_name = malloc( name_len+5 );
strcpy( new_name, clr_name );
if (name_len < (UF_DISP_MAX_NAME_SIZE-4))
{
strcat( new_name, "_dil" );
}
UF_CALL(UF_DISP_set_color( clr_num,
UF_DISP_hsv_model,
new_name,
clr_values ));
free( new_name );
UF_free( clr_name );
}
/* Set background color to blue using "rgb" model. */
/* Color name is ignored for background. */
clr_values[0] = 0.0; /* red */
clr_values[1] = 0.0; /* green */
clr_values[2] = 1.0; /* blue */
UF_CALL(UF_DISP_set_color( UF_DISP_BACKGROUND_COLOR,
UF_DISP_rgb_model,
NULL,
clr_values ));
UF_CALL(UF_DISP_load_color_table());
/* Determine the closest color to blue. Note that */
/* the background color is not considered. */
clr_values[0] = 240.0;
clr_values[1] = 0.0;
clr_values[2] = 0.0;
UF_CALL(UF_DISP_ask_closest_color(
UF_DISP_hsv_model,
clr_values,
UF_DISP_CCM_EUCLIDEAN_DISTANCE,
&clr_num ));
printf( "The closest color to blue is #: %d", clr_num );
}
/*ARGSUSED*/
void ufusr(char *param, int *retcode, int paramLen)
{
if (!UF_CALL(UF_initialize()))
{
do_ugopen_api();
UF_CALL(UF_terminate());
}
}
int ufusr_ask_unload(void)
{
return (UF_UNLOAD_IMMEDIATELY);
}



[/quote]

0

最新回复 (0)
请登录后发表新帖