- A call like this can copy the image
from the image file into the buffer:
getImage(buffer, filename, imgHeight, imgWidth) ;
(Which of the parameters above are input, output, and
input/output? Answer the same question for all your functions
-- you'll have disasterous and hard-to-figure-out problems if
you don't decide properly which parameters should be value
params and which should be reference params.)
- What should the call above do? It could create an input file
stream called "inFile" bound to the filename, read the first
line of the file to get the values of imgHeight and imgWidth,
then after making sure that input is set to start at the
beginning of the second line, get the image by making a
function call like this:
getImageLine(buffer, inFile, lineNum, imgWidth);
one time for each value of lineNum from 0 to imgHeight-1. The
job of getImageLine would be to copy the next line of the
image file into the proper row of the buffer.
After getImage loops through its calls to getImageLine, it
should close the image file.
- What should this call do?
getImageLine(buffer, inFile, lineNum, imgWidth);
It needs to transfer each character individually with a call like this:
inFile.get(buffer[lineNum][colNum]);
This statement gets the next character from inFile and puts it
into a particular location in the buffer. It puts it into the
position whose row index is "lineNum" and whose column index
is "colNum."
getImageLine should contain a loop that executes this "get"
statement once for each value of colNum from 0 to imgWidth-1.
The value of lineNum should remain fixed within each call to
getImageLine. (getImage takes care of getting all the lines
into the buffer by calling getImageLine many times, each time
with a new value of lineNum.)
After transferring all the characters on the current line
getImageLine would have to read the newline character at the
end of the line. That way the next time the program does some
reading, the reading starts at the beginning of the next line.
Since the "get" is a built-in function that operates on the
input file stream that we have named "inFile" here, we don't
have to worry about how to make the "get" do what it does.
Therefore there are no more details regarding getting the image
that need to be considered. (Yay!)
- A call like this can perform the tiling:
doTileJob(buffer, numTileRows, numTileCols, imgHeight, imgWidth)
- What should function "doTileJob" do? It could do the tiling
one row at a time by making a function call like this:
makeRow(buffer,numTileCols,imgHeight,imgWidth)
numTileRows times.
(doTileJob has to make some blank lines before and after the
loop in order to get the spacing to look right -- look closely
at the sample run -- there are two blank lines in the output
before the tiling starts and two more after it ends. )
- What should function "makeRow" do? It could make one row of
the tiling by making this function call:
makeRowLine(lineNum, buffer, numTileCols, imgWidth)
once for each value of lineNum from 0 to imgHeight-1. Each
call would make one line of the tiling on the screen.
- What should the function call:
makeRowLine(lineNum, buffer, numTileCols, imgWidth)
do? This function has to copy the same line out of the buffer
repeatedly until it has made enough for the number of tiles
that are supposed to go across in the tiling. It could make
one line of the tiling by making this function call:
writeBufRow(lineNum, buffer, imgWidth)
numTileCols times. Each call would copy one line of the buffer
to the output one time.
At the very end, makeRowLine would have to output a newline
character so that the next time the program does some writing,
it starts at the beginning of a new line.
- What should the function call:
writeBufRow(lineNum, buffer, imgWidth)
do? The job of this function is just to execute this statement in a loop:
cout << buffer[lineNum][charNum]
The statement outputs a character in the buffer. It outputs
the character in the row indexed by "lineNum" and the column
indexed by "charNum." To write out a specific line in the
buffer we need to hold lineNum fixed and vary charNum from 0 to
imgWidth-1 in the loop.