-
Notifications
You must be signed in to change notification settings - Fork 0
/
ImageManipulator.cpp
1061 lines (762 loc) · 25.8 KB
/
ImageManipulator.cpp
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/******************************
** ImageManipulator.cpp **
** Created by Charles Davis **
** CPSC 246-01 **
******************************/
/******************************************************************************
** ImageManipulator.cpp is the implementation file for the ImageManipulator **
** class. It has 11 filters that manipulate the colors of the given image **
** It has a function called filterImage(string image, int imageFilter) that **
** takes the input file, changes the color value based on the inputed image **
** filter integer and spits out the finished image to the given string **
** file name. In the header file there is a list of constant ints that a **
** a user can send through the image filter function. They will be ran in **
** this order: **
** **
** 1. ZERO_RED 5. INVERT_GREEN 9. SWAP_GREEN_BLUE **
** 2. ZERO_GREEN 6. INVERT_BLUE 10. SWAP_BLUE_RED **
** 3. ZERO_BLUE 7. AVERAGE_RGB 11. FIESTA_FILTER **
** 4. INVERT_RED 8. SWAP_RED_GREEN **
** **
** So if a user wanted to zero the red and then swap the blue and red **
** the function call would be: **
** myImage.filterImage("myPic.ppm,myImage.ZERO_RED + myImage.SWAP_RED_BLUE) **
** **
** and even if the values were reverse they would still be executed in the **
** same order. **
** The fiest filter is a special filter created by the developer that does **
** some crazy stuff to the image by adding to the color values and swapping **
** colors in rows and columns creating a really crazy looking final image **
*****************************************************************************/
#include "ImageManipulator.h"
#include <string>
#include <sstream>
#include <iostream>
#include <fstream>
using namespace std;
/******************************** Constructor ********************************/
ImageManipulator::ImageManipulator(string file)
{
// The constructor opens the given file, validates that the file exists
// checks the magic number, reads and ignores the comments, gets the
// height, width and max color value and assigns them to the instance
// variables of the object then creates a new Pixel array with size
// height and width then initializes the array values all to zero
string tempLine; // tempLine for reading comment line
inFileName = file; // set the filename for the object
inFile.open(inFileName); // open the file
if(inFile.is_open()) // if the file is open
{
getline(inFile, magicNumber); //read in magic number
if(magicNumber == "P3") // if it is a valid number
{
getline(inFile, tempLine); //get the comment line
if(tempLine.at(0) == '#') // if comment is valid comment
{
inFile >> width; // read in width and height
inFile >> height;
if(width > 0 && height > 0) // if the width and height
{ // aren't negative
inFile >> maxVal; // read in max color value
if(maxVal != 255) // for our purposes the maxVal
{ // should be 255. If it isn't exit
cerr << "Invalid Max Color";
exit(1);
}
}
else // negative size found. exit
{
cerr << "Invalid size";
exit(1);
}
}
else // no comment found
{
cerr << "Invalid Header";
exit(1);
}
}
else // bad magic number
{
cerr << "Invalid Header";
exit(1);
}
} // file isn't open
else
{
cerr << "Error opening file";
exit(1);
}
RGBArray = new Pixel[width * height]; // alloc memory for array
for(int i = 0; i < (width * height); i++) // init array
{
RGBArray[i].redVal = 0;
RGBArray[i].greenVal = 0;
RGBArray[i].blueVal = 0;
}
}
/********************************* Destructor ********************************/
ImageManipulator::~ImageManipulator()
{
//Delete dynamic memory stuff
delete [] RGBArray;
}
/***************************** Copy Constructor ******************************/
ImageManipulator::ImageManipulator(const ImageManipulator &im)
{
// copies the values of the instantiated object im to the new object
// this.
//copy all relavant values to new object.
inFileName = im.inFileName;
magicNumber = im.magicNumber;
height = im.height;
width = im.width;
maxVal = im.maxVal;
// create new Pixel array with size width * height
RGBArray = new Pixel[width*height];
//instantiate the new array with a copy of the other objects values
for(int i = 0; i < (width*height); i++)
{
RGBArray[i].redVal = im.RGBArray[i].redVal;
RGBArray[i].greenVal = im.RGBArray[i].greenVal;
RGBArray[i].blueVal = im.RGBArray[i].blueVal;
}
}
/*************************** Operator = Overload *****************************/
ImageManipulator& ImageManipulator::operator = (const ImageManipulator& im)
{
// assings the values of the instantiate object passed to the function
// and returns this object.
if(this != &im) // check to see if the user passed the same exact
{ // object if not do the assignments
inFileName = im.inFileName;
magicNumber = im.magicNumber;
height = im.height;
width = im.width;
maxVal = im.maxVal;
delete [] RGBArray; // delete the current array to make room
// for the new one
RGBArray = new Pixel[width * height]; //create a new array
// instantiate the new array with other object's values
for(int i = 0; i < (width * height); i++)
{
RGBArray[i] = im.RGBArray[i];
}
}
return *this; // return the object to the caller
}
/******************************** Filter Image *******************************/
void ImageManipulator::filterImage(string image, int imageFilter)
{
// takes the given string for the output image name and filters the
// input image that the object was constructed with. By checking the
// bits of the imageFilter integer it runs each filter on the image
// in a specific order.
string tempLine; // tempLine for getting rid of header
int aryIndx, bitMask; //ary index and bitmask for checking filter val
int tempRed = 0, tempGreen = 0, tempBlue = 0;
currentRow = 0; // set current row to zero to start at the top of
// the image.
outFileName = image; // set the name of the outFile
outFile.open(outFileName); // open the outFile for sending values
if(outFile.is_open()) // if outFile is open send it new header
{
outFile << magicNumber << "\n";
outFile << "#Generated by ImageManipulator 2014. ";
outFile << "Created by Charles Davis\n";
outFile << width << " " << height << "\n";
outFile << maxVal << "\n";
}
else
{
cerr << "Error opening out file";
exit(1);
}
inFile.open(inFileName); // open inFile
if(inFile.is_open()) // if there wasn't an error
{
getline(inFile, tempLine); //get magic number out of way
getline(inFile, tempLine); //get comments out of the way
getline(inFile, tempLine); // get height and width out of the way
getline(inFile, tempLine); // get maxVal out of the way
}
else // there was an error. exit
{
cerr << "Error opening file";
exit(1);
}
cout << "Processing " << getInFileName();
cout << " to " << outFileName << endl;
while(currentRow < height) //for every rown in the image
{
// for each column in the row
for(int currentCol = 0; currentCol < width; currentCol++)
{
// treating a 1d array as a 2d calculate the index
aryIndx = currentRow * width + currentCol;
inFile >> tempRed; // get red value
inFile >> tempGreen; // get green value
inFile >> tempBlue; // get blue value
RGBArray[aryIndx].redVal = tempRed; // set red
RGBArray[aryIndx].greenVal = tempGreen; // set green
RGBArray[aryIndx].blueVal = tempBlue; // set blue
}
// for each possible filter
for(int i = 0; i < NUM_FILTERS; i++)
{
//calculate the bitmask by shifting the bit i places
bitMask = (1 << i);
// bitwise & will check the imageFilter int for the bitMask
if(imageFilter & bitMask)
{
// if it exists do a switch
switch(bitMask)
{
case ZERO_RED:
zeroRed(); break;
case ZERO_GREEN:
zeroGreen(); break;
case ZERO_BLUE:
zeroBlue(); break;
case INVERT_RED:
invertRed(); break;
case INVERT_GREEN:
invertGreen(); break;
case INVERT_BLUE :
invertBlue(); break;
case AVERAGE_RGB :
averageRGB(); break;
case SWAP_RED_GREEN:
swapRG(); break;
case SWAP_GREEN_BLUE :
swapGB(); break;
case SWAP_BLUE_RED:
swapBR(); break;
case FIESTA_FILTER:
fiestaFilter(); break;
default: break;
}
}
}
// for each column in the current row print out the RGB values
for(int currentCol = 0; currentCol < width; currentCol++)
{
// calculate the 1d version of 2d index
aryIndx = currentRow * width + currentCol;
//print out value and a space between them
outFile << RGBArray[aryIndx].redVal << " ";
outFile << RGBArray[aryIndx].greenVal << " ";
outFile << RGBArray[aryIndx].blueVal << " ";
// for every 5 triplets print out a newline to the file
if((currentCol+1) % 5 == 0)
{
outFile << "\n";
}
}
currentRow++;
}
inFile.close(); // close in and out files
outFile.close();
}
/********************************** zeroRed **********************************/
void ImageManipulator::zeroRed()
{
// zeros out the red element of the pixel array
int currentCol = 0, aryIndx;
// for every element in the current row
while(currentCol < width)
{
aryIndx = currentRow * width + currentCol;
// zero out red value
RGBArray[aryIndx].redVal = 0;
currentCol++;
}
}
/********************************* zeroGreen *********************************/
void ImageManipulator::zeroGreen()
{
// zeros out the green element of the pixel array
int currentCol = 0, aryIndx;
// for every element in the current row
while(currentCol < width)
{
aryIndx = currentRow * width + currentCol;
// zero out the green value
RGBArray[aryIndx].greenVal = 0;
currentCol++;
}
}
/********************************** zeroBlue *********************************/
void ImageManipulator::zeroBlue()
{
// zeros out the blue element of the pixel array
int currentCol = 0, aryIndx;
// for every element in the current row
while(currentCol < width)
{
aryIndx = currentRow * width + currentCol;
//zero out the blue value
RGBArray[aryIndx].blueVal = 0;
currentCol++;
}
}
/********************************* invertRed *********************************/
void ImageManipulator::invertRed()
{
// inverts the red value of the current row in the array
int currentCol = 0, aryIndx;
// for every element in the current row
while(currentCol < width)
{
aryIndx = currentRow * width + currentCol;
// invert red value. maxVal - currentRedVal
RGBArray[aryIndx].redVal = maxVal - RGBArray[aryIndx].redVal;
currentCol++;
}
}
/******************************** invertGreen ********************************/
void ImageManipulator::invertGreen()
{
// inverts the green value of the current row in the array
int currentCol = 0, aryIndx;
// for every element in the current row
while(currentCol < width)
{
aryIndx = currentCol * width + currentCol;
// invert green value. maxVal - currentGreenVal
RGBArray[aryIndx].greenVal = maxVal - RGBArray[aryIndx].greenVal;
currentCol++;
}
}
/********************************* invertBlue ********************************/
void ImageManipulator::invertBlue()
{
// inverts the blue value of the current row in the array
int currentCol = 0, aryIndx;
// for every element in the current row
while(currentCol < width)
{
aryIndx = currentRow * width + currentCol;
// invert blue value. maxVal - currentBlueVal
RGBArray[aryIndx].blueVal = maxVal - RGBArray[aryIndx].blueVal;
currentCol++;
}
}
/******************************** averageRGB *********************************/
void ImageManipulator::averageRGB()
{
// averages the three color values and assigns them to the current
// elements in the array. This creates a grey scale picture
int currentCol = 0, averageColor, aryIndx;
// for every element in the current row
while(currentCol < width)
{
aryIndx = currentRow * width + currentCol;
// add all three colors and get the average
averageColor = (RGBArray[aryIndx].redVal +
RGBArray[aryIndx].greenVal +
RGBArray[aryIndx].blueVal) / 3;
// assign the average to each position in the pixel array
RGBArray[aryIndx].redVal = averageColor;
RGBArray[aryIndx].greenVal = averageColor;
RGBArray[aryIndx].blueVal = averageColor;
currentCol++;
}
}
/********************************** swapRG ***********************************/
void ImageManipulator::swapRG()
{
// swaps the red and green values of the pixels in the array
int currentCol = 0, swapTemp, aryIndx;
// for every element in the current row
while(currentCol < width)
{
aryIndx = currentRow * width + currentCol;
// swap the red and green values
swapTemp = RGBArray[aryIndx].redVal;
RGBArray[aryIndx].redVal = RGBArray[aryIndx].greenVal;
RGBArray[aryIndx].greenVal = swapTemp;
currentCol++;
}
}
/*********************************** swapGB **********************************/
void ImageManipulator::swapGB()
{
// swaps the green and blue values of the pixels in the array
int currentCol = 0, swapTemp, aryIndx;
// for every element the current row
while(currentCol < width)
{
aryIndx = currentRow * width + currentCol;
// swap the green and blue values
swapTemp = RGBArray[aryIndx].greenVal;
RGBArray[aryIndx].greenVal = RGBArray[aryIndx].blueVal;
RGBArray[aryIndx].blueVal = swapTemp;
currentCol++;
}
}
/********************************** swapBR ***********************************/
void ImageManipulator::swapBR()
{
// swaps the blue and red values of the pixels in the array
int currentCol = 0, swapTemp, aryIndx;
// for every element in the current row
while(currentCol < width)
{
aryIndx = currentRow * width + currentCol;
// swap the blue and red values
swapTemp = RGBArray[aryIndx].blueVal;
RGBArray[aryIndx].blueVal = RGBArray[aryIndx].redVal;
RGBArray[aryIndx].redVal = swapTemp;
currentCol++;
}
}
/******************************** fiestaFilter *******************************/
void ImageManipulator::fiestaFilter()
{
// this is the custom crazy filter created by me. It turns the image
// into a crazy looking grid with 7 rows and 7 columns of different
// value manipulations.
int tempRed, tempGreen, tempBlue;
int currentCol = 0, cutOne, seventhCut, aryIndx;
// cut the width of image into seven columns
cutOne = width / 7;
//cut the height of the image into seven rows
seventhCut = height / 7;
// for each element in the current row
while(currentCol < width)
{
// if the current row is the first, third, fifth or seventh row
if(currentRow < seventhCut ||
(currentRow >= (seventhCut * 2) && currentRow < (seventhCut * 3)) ||
(currentRow >= (seventhCut * 4) && currentRow < (seventhCut * 5)) ||
(currentRow >= (seventhCut * 6)) && currentRow < height)
{
// swap the blue and red pixels
swapBR();
}
//Red and Green
// for the first cut
for(int colCount = 0; colCount < cutOne; colCount++)
{
// calculate the current row and column in a 1d array
aryIndx = currentRow * width + colCount;
// Red
// add 5 to the red value
tempRed = RGBArray[aryIndx].redVal + 5;
// if the add exceeds the max value circle back to begining
if(tempRed > maxVal)
{
// set it to 0
RGBArray[aryIndx].redVal = 0;
// add the difference
RGBArray[aryIndx].redVal +=
(tempRed - maxVal);
}
else
{ // otherwise add 5
RGBArray[aryIndx].redVal += 5;
}
//Green
// add 10 to green value
tempGreen = RGBArray[aryIndx].greenVal + 10;
// if the add exceeds the max value circle back to begining
if(tempGreen > maxVal)
{
// set it to 0
RGBArray[aryIndx].greenVal = 0;
// add the difference
RGBArray[aryIndx].greenVal +=
(tempGreen - maxVal);
}
else
{ // other wise add 5
RGBArray[aryIndx].greenVal += 10;
}
}
//green and blue
// for the second cut
for(int colCount = cutOne; colCount < (cutOne*2); colCount++)
{
// calculate the current row and column in 1d array
aryIndx = currentRow * width + colCount;
//green
// add 15 to green value
tempGreen = RGBArray[aryIndx].greenVal + 15;
//if the add exceeds the max value circle back to begining
if(tempGreen > maxVal)
{
// set it to 0
RGBArray[aryIndx].greenVal = 0;
// add the difference
RGBArray[aryIndx].greenVal +=
(tempGreen - maxVal);
}
else
{ // otherwise add 15
RGBArray[aryIndx].greenVal += 15;
}
//blue
// add 20 to the blue value
tempBlue = RGBArray[aryIndx].blueVal + 20;
// if the add exceeds the max value circle back to the begining
if(tempBlue > maxVal)
{
// set it to 0
RGBArray[aryIndx].blueVal = 0;
// add the difference
RGBArray[aryIndx].blueVal +=
(tempBlue - maxVal);
}
else
{ // otheriwse add 20
RGBArray[aryIndx].blueVal += 20;
}
}
//blue and red for the third cut
for(int colCount = (cutOne*2); colCount < (cutOne*3); colCount++)
{
// calculate the row and column in the 1d array.
aryIndx = currentRow * width + colCount;
//blue
// add 25 to the blue value
tempBlue = RGBArray[aryIndx].blueVal + 25;
// if add exceed the max value circle back to 0
if(tempBlue > maxVal)
{
// set it to 0
RGBArray[aryIndx].blueVal = 0;
// add the difference
RGBArray[aryIndx].blueVal +=
(tempBlue - maxVal);
}
else
{ // otherwise add 25
RGBArray[aryIndx].blueVal += 25;
}
//red
// add 30 to red value
tempRed = RGBArray[aryIndx].redVal + 30;
// if add exceeds the max value circle back to begining
if(tempRed > maxVal)
{
// set it to 0
RGBArray[aryIndx].redVal = 0;
// add the difference
RGBArray[aryIndx].redVal +=
(tempRed - maxVal);
}
else
{ // otherwise add 30
RGBArray[aryIndx].redVal += 30;
}
}
// for the 4th cut red and green
for(int colCount = (cutOne*3); colCount < (cutOne*4); colCount++)
{
// calculate the row and column in the 1d array.
aryIndx = currentRow * width + colCount;
//red
// add 15 to red value
tempRed = RGBArray[aryIndx].redVal + 15;
// if add exceeds max value circle back to begining
if(tempRed > maxVal)
{
// set it to 0
RGBArray[aryIndx].redVal = 0;
// add the difference
RGBArray[aryIndx].redVal +=
(tempRed - maxVal);
}
else
{ // otherwise add 15
RGBArray[aryIndx].redVal += 15;
}
//green
// add 30 to green value
tempGreen= RGBArray[aryIndx].greenVal + 30;
// if add exceeds the max value circle back to the begining
if(tempGreen > maxVal)
{
// set it to 0
RGBArray[aryIndx].greenVal = 0;
// add the difference
RGBArray[aryIndx].greenVal +=
(tempGreen - maxVal);
}
else
{ // otherwise add 30
RGBArray[aryIndx].greenVal += 30;
}
//blue
// add 45 to the blue
tempBlue = RGBArray[aryIndx].blueVal + 45;
// if add exceeds the max value circle back the begining
if(tempBlue > maxVal)
{
// set it to 0
RGBArray[aryIndx].blueVal = 0;
// add the difference
RGBArray[aryIndx].blueVal +=
(tempBlue - maxVal);
}
else
{ // otherwise just add 45
RGBArray[aryIndx].blueVal += 45;
}
}
//blue and red for the 5th cut
for(int colCount = (cutOne*4); colCount < (cutOne*5); colCount++)
{
// calculate the row in column in 1d like it is a 2d array
aryIndx = currentRow * width + colCount;
//blue
// add 25 to blue value
tempBlue = RGBArray[aryIndx].blueVal + 25;
// if add exceeds the max value circle back to the begining
if(tempBlue > maxVal)
{
// set it to 0
RGBArray[aryIndx].blueVal = 0;
// add the difference
RGBArray[aryIndx].blueVal +=
(tempBlue - maxVal);
}
else
{ // otherwise add 25
RGBArray[aryIndx].blueVal += 25;
}
//red
// add 30 to the red value
tempRed = RGBArray[aryIndx].redVal + 30;
// if add exceeds the max value circle back to the begining
if(tempRed > maxVal)
{
// set it to 0
RGBArray[aryIndx].redVal = 0;
// add the difference
RGBArray[aryIndx].redVal +=
(tempRed - maxVal);
}
else
{ // otherwise add 30
RGBArray[aryIndx].redVal += 30;
}
}
//green and blue forthe 6th cut
for(int colCount = (cutOne*5); colCount < (cutOne*6); colCount++)
{
// calculate the row and column in a 1d array as a 2d
aryIndx = currentRow * width + colCount;
//green
// add 15 to the green value
tempGreen = RGBArray[aryIndx].greenVal + 15;
// if add exceeds the max value circle back to the begining
if(tempGreen > maxVal)
{
// set it to 0
RGBArray[aryIndx].greenVal = 0;
// add the difference
RGBArray[aryIndx].greenVal +=
(tempGreen - maxVal);
}
else
{ // otherwise add 15
RGBArray[aryIndx].greenVal += 15;
}
//blue
// add 20 to the blue value
tempBlue = RGBArray[aryIndx].blueVal + 20;
// if add exceeds max value circle back to the begining
if(tempBlue > maxVal)
{
// set it to 0
RGBArray[aryIndx].blueVal = 0;
// add the difference
RGBArray[aryIndx].blueVal +=
(tempBlue - maxVal);
}
else
{ // otherwise add 20
RGBArray[aryIndx].blueVal += 20;
}
}
// for the last cut red and green
for(int colCount = (cutOne*6); colCount < width; colCount++)
{
// calculate the row in coloumn in 1d as if it were a 2d
aryIndx = currentRow * width + colCount;
// Red
// add 5 to the red value
tempRed = RGBArray[aryIndx].redVal + 5;
// if add exceeds the max value circle back to the begining
if(tempRed > maxVal)
{
// set it to 0
RGBArray[aryIndx].redVal = 0;
// add the difference
RGBArray[aryIndx].redVal +=
(tempRed - maxVal);
}
else
{ // otherwise add 5
RGBArray[aryIndx].redVal += 5;
}
//Green
// add 10 to the green value
tempGreen = RGBArray[aryIndx].greenVal + 10;
// if add exceeds max value circle back to the begining
if(tempGreen > maxVal)
{
// set it to 0
RGBArray[aryIndx].greenVal = 0;
// add the difference
RGBArray[aryIndx].greenVal +=
(tempGreen - maxVal);
}
else
{ // otherwise add 10
RGBArray[aryIndx].greenVal += 10;
}
}
currentCol++; // next column element in row
}
// for the whole row
for(int colCount = 0; colCount < width; colCount++)
{
// calculate the row and column in 1d array as 2d
aryIndx = currentRow * width + colCount;
// add 75 to all three
tempRed = RGBArray[aryIndx].redVal + 75;
tempGreen = RGBArray[aryIndx].greenVal + 75;
tempBlue = RGBArray[aryIndx].blueVal + 75;
// cap all the values at max value
if(tempRed >= maxVal)
{
RGBArray[aryIndx].redVal = maxVal;
}
if(tempGreen >= maxVal)