Ocena użytkownikóww: ***** / 2
Nadesłany przez Tomasz Lubiński, 17 listopada 2007 01:00
Kod przedstawiony poniżej przedstawia główną część rozwiązania problemu.
Pobierz pełne rozwiązanie.Jeżeli nie odpowiada Ci sposób formatowania kodu przez autora skorzystaj z pretty printer'a i dostosuj go automatycznie do siebie.
cmy_rgb.cpp:
/*
Transformacja pomiedzy modelami CMY i RGB
www.algorytm.org
(c)2007 Tomasz Lubinski
*/
#include <stdio.h>
int* cmy2rgb(int c, int m, int y) {
int *result = new int[3];
result[0] = 255 - c;
result[1] = 255 - m;
result[2] = 255 - y;
return result;
}
int *rgb2cmy(int r, int g, int b){
int *result = new int[3];
result[0] = 255 - r;
result[1] = 255 - g;
result[2] = 255 - b;
return result;
}
void main(void) {
int x;
int c,m,y;
int r,g,b;
int *result;
printf("Zakresy skladowych 0-255\n");
printf("1. Dla transformacji CMY -> RGB\n");
printf("2. Dla transformacji RGB -> CMY\n");
scanf("%d", &x);
if (x == 1){
printf("C=");
scanf("%d", &c);
printf("M=");
scanf("%d", &m);
printf("Y=");
scanf("%d", &y);
result = cmy2rgb(c,m,y);
printf("R=%d, G=%d, B=%d", result[0], result[1], result[2]);
}
else {
printf("R=");
scanf("%d", &r);
printf("G=");
scanf("%d", &g);
printf("B=");
scanf("%d", &b);
result = rgb2cmy(r,g,b);
printf("C=%d, M=%d, Y=%d", result[0], result[1], result[2]);
}
}