Пример #1
0
Файл: color.c Проект: AZed/cdo
int getrgb (char *line, int rgb[], int color_model)
{
  int n, count;
	
  count = slash_count (line);
	
  if (count == 3) {	/* c/m/y/k */
    double cmyk[4];
    n = sscanf (line, "%lf/%lf/%lf/%lf", &cmyk[0], &cmyk[1], &cmyk[2], &cmyk[3]);
    if (n != 4 || check_cmyk (cmyk)) return (TRUE);
    cmyk_to_rgb (rgb, cmyk);
    return (FALSE);
  }
	
  if (count == 2) {	/* r/g/b or h/s/v */
    if (color_model == RGB) {	/* r/g/b */
      n = sscanf (line, "%d/%d/%d", &rgb[0], &rgb[1], &rgb[2]);
      if (n != 3 || check_rgb (rgb)) return (TRUE);
    }
    else {					/* h/s/v */
      double h, s, v;
      n = sscanf (line, "%lf/%lf/%lf", &h, &s, &v);
      if (n != 3 || check_hsv (h, s, v)) return (TRUE);
      hsv_to_rgb (rgb, h, s, v);
    }
    return (FALSE);
  }
	
  if (count == 0) {				/* gray */
    n = sscanf (line, "%d", &rgb[0]);
    rgb[1] = rgb[2] = rgb[0];
    if (n != 1 || check_rgb (rgb)) return (TRUE);
    return (FALSE);
  }

  /* Get here if there is a problem */
			
  return (TRUE);
}
Пример #2
0
static int check_option(int argc, char * argv[], struct option_info * info)
{
	int ret = 0;
	int c;

	if (argc <= 1) {
		usage();
		return -1;
	}

	memset(info, 0, sizeof(*info));

	ret = 0;
	while (!ret)
    {
		c = getopt (argc, argv, "i:o:r:hv");
		if (c == -1) {
			ret = 0;
			break;
		}
		
		switch (c)
        {
		case 'i':
			strncpy(info->input_file, optarg, sizeof(info->input_file)-1);
			info->action |= stricmp("fb", info->input_file) ? (eFile << 1) : (eFb << 1);
			break;
		case 'o':
			strncpy(info->output_file, optarg, sizeof(info->output_file)-1);
			info->action |= stricmp("fb", info->output_file) ? eFile : eFb;
			break;
		case 'r':
			info->output_rgb = check_rgb(optarg);
			if (eRGB_MIN == info->output_rgb) {
				ret = -1;
			}
			break;
		case 'v':
			version();
			ret = -1;
			break;
		case 'h':
        case '?':
			usage();
			ret = -1;
			break;
        default:
			printf ("?? getopt returned character code 0x%x ??\n", c);
			usage();
			ret = -1;
			break;
        }
    }

	if (info->output_rgb == eRGB_MIN) {
		info->output_rgb = eRGB_565;//默认输出为565格式
	}

	//如果只有两个参数,而且没有前缀,则认为argv[1]为输入图片,并且将图片打印到fb中
	if ((argc == 2) && (optind < argc)) {
		info->action = eAction_file_to_fb;
		strncpy(info->input_file, argv[1], sizeof(info->input_file)-1);
		return 0;
	}
	//还有多余参数,则认为非法,要退出
	if (optind < argc) {
		printf ("non-option ARGV-elements: ");
		while (optind < argc)
			printf ("%s ", argv[optind++]);
		printf ("\n");
		usage();
		return -1;
	}

	if (ret) {
		return ret;
	}

	ret = -1;
	do 
	{
		if (info->action == eAction_file_to_file
			|| info->action == eAction_file_to_fb
			|| info->action == eAction_fb_to_file)
		{
			//do nothing
		} else {
			printf("check_option : unknown action type!\n");
			break;
		}
		ret = 0;
	} while (0);

	return ret;
}