Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdlib>
- #include <iostream>
- #include <fstream>
- using namespace std;
- ifstream infile;
- ofstream outfile;
- const int resolution = 10;
- void readValues(int [][10], int [][10], int [][10] , int &, int &);
- int MAX(int , int , int );
- void RGBtoCMYK(int , int , int , double&, double&, double&, double&);
- //void writeValues(double[][10], double[][10],double[][10],double[][10] , ofstream&);
- int red[resolution][resolution], green[resolution][resolution] , blue [resolution][resolution], maxrow, maxcol;
- double c,m,y,k;
- int main()
- {
- ifstream infile("C:/image.txt"); //Reading from file
- ofstream outfile("C:/CMYKR.txt");
- cout.setf(ios::fixed,ios::floatfield);
- cout.precision(1);
- if (!infile.is_open()) { // Condition if the file is not open
- cout << "Error. Unable to open file.";
- system ("PAUSE");
- exit(1);
- }
- readValues(red,green,blue,maxrow,maxcol); // this function reads the data and puts it in the three arrays
- cout<<endl<<"CMYK VALUES"<<endl;
- for (int i=0;i<maxrow ; i++)
- {
- for(int j=0;j<maxcol ;j++)
- {
- void RGBtoCMYK(red[i][j],green[i][j],blue[i][j], c , m, y, k);
- cout << "," <<c<< "," <<m<< "," <<y<< "," <<k<<", ";
- }
- }
- // writeValues(c,m,y ,k,outfile);
- }
- void readValues(int red[][10], int green[][10], int blue[][10] , int &maxrow, int &maxcol)
- {
- int x = 0, y = 0;
- infile >> maxrow >> maxcol;
- for(x = 0;x<maxrow;x++)
- {
- for(y=0;y<maxcol;y++)
- {
- infile >> red[x][y];
- }
- }
- for(x = 0;x<maxrow;x++)
- {
- for(y=0;y<maxcol;y++)
- {
- infile >>blue[x][y];
- }
- }
- for(x = 0;x<maxrow;x++)
- {
- for(y=0;y<maxcol;y++)
- {
- infile >>green[x][y];
- }
- }
- }
- int largest(int x, int y, int z)
- {
- if (x > y && x > z)
- return x;
- else if (y > z)
- return y;
- else
- return z;
- }
- 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
- {
- double w;
- 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
- c = 0;
- m = 0;
- y = 0;
- k = 1;
- }
- else {
- w = largest(r / 255.0, g / 255.0, b / 255.0);
- c = (w - (r / 255.0)) / w;
- m = (w - (g / 255.0)) / w;
- y = (w - (b / 255.0)) / w;
- k = 1.0 - w;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment