Guest User

Untitled

a guest
Apr 29th, 2014
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <fstream>
  4.  
  5. using namespace std;
  6.  
  7. ifstream infile;
  8. ofstream outfile;
  9. const int resolution = 10;
  10.  
  11. void readValues(int [][10], int [][10], int [][10] , int &, int &);
  12. int MAX(int , int , int );
  13. void RGBtoCMYK(int , int , int , double&, double&, double&, double&);
  14.  
  15. //void writeValues(double[][10], double[][10],double[][10],double[][10] , ofstream&);
  16.  
  17. int red[resolution][resolution], green[resolution][resolution] , blue [resolution][resolution], maxrow, maxcol;
  18. double c,m,y,k;
  19. int main()
  20. {
  21.  
  22. ifstream infile("C:/image.txt"); //Reading from file
  23. ofstream outfile("C:/CMYKR.txt");
  24.  
  25. cout.setf(ios::fixed,ios::floatfield);
  26. cout.precision(1);
  27.  
  28. if (!infile.is_open()) { // Condition if the file is not open
  29. cout << "Error. Unable to open file.";
  30. system ("PAUSE");
  31. exit(1);
  32. }
  33.  
  34. readValues(red,green,blue,maxrow,maxcol); // this function reads the data and puts it in the three arrays
  35. cout<<endl<<"CMYK VALUES"<<endl;
  36. for (int i=0;i<maxrow ; i++)
  37. {
  38. for(int j=0;j<maxcol ;j++)
  39. {
  40. void RGBtoCMYK(red[i][j],green[i][j],blue[i][j], c , m, y, k);
  41.  
  42. cout << "," <<c<< "," <<m<< "," <<y<< "," <<k<<", ";
  43. }
  44.  
  45. }
  46.  
  47.  
  48. // writeValues(c,m,y ,k,outfile);
  49. }
  50. void readValues(int red[][10], int green[][10], int blue[][10] , int &maxrow, int &maxcol)
  51. {
  52.  
  53. int x = 0, y = 0;
  54. infile >> maxrow >> maxcol;
  55.  
  56. for(x = 0;x<maxrow;x++)
  57. {
  58. for(y=0;y<maxcol;y++)
  59. {
  60. infile >> red[x][y];
  61. }
  62. }
  63.  
  64. for(x = 0;x<maxrow;x++)
  65. {
  66. for(y=0;y<maxcol;y++)
  67. {
  68. infile >>blue[x][y];
  69. }
  70. }
  71.  
  72. for(x = 0;x<maxrow;x++)
  73. {
  74. for(y=0;y<maxcol;y++)
  75. {
  76. infile >>green[x][y];
  77. }
  78.  
  79.  
  80. }
  81.  
  82. }
  83. int largest(int x, int y, int z)
  84. {
  85. if (x > y && x > z)
  86. return x;
  87. else if (y > z)
  88. return y;
  89. else
  90. return z;
  91.  
  92. }
  93. void RGBtoCMYK(int r, int g, int b, double &c, double &m, double &y, double &k) // function RGBtoCMYK(r, g, b, c, m, y, k) that receives RGB values as input parameters, and returns CMYK values as reference parameters
  94.  
  95. {
  96.  
  97. double w;
  98.  
  99.  
  100.  
  101. if(r == 0 && g == 0 && b == 0) { // If the RGB values are all 0 then the CMY values are all 0 and the K value is 1
  102.  
  103. c = 0;
  104. m = 0;
  105. y = 0;
  106. k = 1;
  107.  
  108. }
  109.  
  110. else {
  111.  
  112. w = largest(r / 255.0, g / 255.0, b / 255.0);
  113. c = (w - (r / 255.0)) / w;
  114. m = (w - (g / 255.0)) / w;
  115. y = (w - (b / 255.0)) / w;
  116. k = 1.0 - w;
  117.  
  118. }
  119.  
  120. }
Advertisement
Add Comment
Please, Sign In to add comment