File: conv2hsv.cpp

package info (click to toggle)
glhack 1.2-2
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 26,680 kB
  • ctags: 21,101
  • sloc: ansic: 208,574; cpp: 13,139; yacc: 2,005; makefile: 1,155; lex: 377; sh: 122; awk: 89; sed: 11
file content (67 lines) | stat: -rw-r--r-- 1,727 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//----------------------------------------------------------------------------
//  RGB --> HSV Converter
//----------------------------------------------------------------------------
//
//  (C) 2001-2002 Andrew Apted
//
//  This program is free software; you can redistribute it and/or
//  modify it under the terms of the GNU General Public License
//  as published by the Free Software Foundation; either version 2
//  of the License, or (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//------------------------------------------------------------------------

using namespace std;

#include "z_config.h"

#include "z_string.h"
#include "z_rgb.h"
#include "z_hsv.h"


static void ShowInfo()
{
  fprintf(stdout,
      "\n**** Conv2HSV 1.0 ****\n\n"
      "Copyright (C) 2001-2002 Andrew Apted.\n"
      "Under the GNU General Public License (GPL).\n\n"
      "USAGE: conv2hsv < input.rgb > output.hsv\n\n"
  );

  fflush(stdout);
}

int main(int argc, const char **argv, const char **envp)
{
  if (argc > 1 &&
      (Z_String::CaseCmp(argv[1], "/?") == 0 ||
       Z_String::CaseCmp(argv[1], "-h") == 0 ||
       Z_String::CaseCmp(argv[1], "-help") == 0 ||
       Z_String::CaseCmp(argv[1], "--help") == 0))
  {
    ShowInfo();
    exit(0);
  }

  for (;;)
  {
    int r, g, b;

    if (scanf(" %d %d %d ", &r, &g, &b) != 3)
      break;

    PackCol rgbcol(r, g, b);
    
    HsvCol hsvcol(rgbcol);

    printf("%3d %3d %3d\n", hsvcol.h, hsvcol.s, hsvcol.v);
  }
 
  return 0;
}