Вы находитесь на странице: 1из 2

if(argv[i][0] == 'a'){

addf(imgWidth, imgHeight, atoi(argv[i+1]), atoi(argv[i+2]),


atoi(argv[i+3]), image, image);
}

If the argv equal to a, the function addf will be called with the three next command line
arguments. This is simply done by increasing the index from the point where a is found
by 1,2, 3. Because argv points to a string, I use atoi() function to get the actual integer
value in order to pass them to the function. In addition, the addf() function take image[]
array as its input and outputting the result into the original array. This works perfectly
well because what it does is just updating the image.
When argv equal to m, the function meanf will be called. The next argument from the
index of m will be used as the filter width. Unlike addf() function, filter() outputs the
result into addedImage array. Then, the copy function will copy data from addedImage
back to the original image array.
if(argv[i][0] == 'm'){
meanf(imgWidth, imgHeight, atoi(argv[i+1]), image,
addedImage);
copyf(MAXWIDTH, MAXHEIGHT, COLORS, addedImage, image);
}

Once the loop stops, the ppmout is used to output ppm file of the image data. One of the
program criteria is no limitation in command line arguments that user can enter. Since
the for loop is defined, the program can read the operation in any order and multiple
times as long as the user enter proper format.

Testing
Before implementing command arguments part, I first tested the addf() function by
entering values directly into it. This allows me to see if it is working properly or not. I
called addf() function in the main function and output the new image as below
addf(imgWidth, imgHeight, 100, 100, 100, image, image);
ppmout(imgWidth, imgHeight, MAXC, image);

Output PPM files

The output image indicated that the addf() function worked properly. From observation,
the color tone was a little bit brighter than the original image. This is reasonable because
the input command tells the program to add a value of 100 to each pixel.
Deklaroval jsem funkci addLayer () as
To trv est argumenty. Prvn dva jsou ka a vka obrazu. Tyto hodnoty urit rozmry
dvojrozmrnm poli stejn jako limit pro smyky.Tet argument je barva, kter me bt
0, 1 nebo 2. Ve funkci addf (), ti addLayer (), funkce bude volna s ervenou, zelenou a
modrou barvu, resp.tvrt je hodnota, kter se vztahuje k prav. Tento konkrtn tvrzen
nebudou pedny do funkce main () zskat vstupy z argument pkazovho dku.
Posledn dva argumenty jsou zdrojem pole a clov pole. Oba maj stejn rozmry.
V prohlen tla funkce addLayer () obsahuje vnoen do smyky.Vnj smyka jde od
0 do ky obrazu a vnitn smyka jde od 0 do maximln vky. To znamen, e funkce
bude testovat prostednictvm kadho prvku ve stejn barevn vrstvy a pidat pravu
existujc hodnotu.Pkaz piazen je psn jak
Existuj speciln ppady, e funkce potebuje zvldnout samostatn. To je, kdy je
modifikovan hodnota je mimo rozsah barev. Tento kol lze provst pomoc if. I
definovan podmnky, e v ppad, e addArray [] [b] [barva] je vt ne MAX, pak je
roven max.Podobn stav je definovn pro zporn hodnoty, kter stanovil addArray [] [b]
[barva] rovno 0, je-li men ne 0.
Druh funkce, kter jsem vytvoil pro tento program je funkce koprovn (). Tato st lze
zapsat pmo do hlavn funkce. Nicmn jsem se rozhodl vyhlsit funkci samostatn,
take je snaz zmnit pozdji. Funkce koprovn je podobn funkci addArray ().
Obsahuje vnoen smyku, kter prochz kad prvek v trojrozmrnm poli. Pokad,
kdy se hodnota od [] pole budou elov vzny na [] pole se stejnou indexy.
V tomto cvien, bude hlavn funkce () mus bt psemn jinak. Nyn m dva parametry.
Ne je nov prohlen
Uvnit hlavn, jsem poprv voln funkce ppmread () pro zskn obrazovch dat. To bude
ukldat ku obrzku, vku obrazu, poet barev a obraz pole.
Po zadn pkazovho dku, bude ada argument potat a ukldat. Vzhledem k tomu,
argc promnn obsahuje celkov poet vstupnch argument, to je pouvno jako
koncov index pro smyky. Z analzy sti, argv [0] je ukazatel, kter odkazuje na prvn
etzec a arvg [1] bod na druhm etzci a tak dle. Tam jsou dv hlavn operace; addf je
reprezentovn znakem "A" a meanf znakem "m". Toto nastaven umouje program
porovnvat mezi arvg a charakter pouit stejn opertor porovnn. V prvnm ppad
jsem napsal kd as

Вам также может понравиться