New answers tagged

1

Without doing a deep dive, I do see a major problem in the logic. The code copies all the pixels from image to temp array. But then, it does all the calculations using the temp array as the source while concurrently putting the blurred pixels back into temp and not image. Finally, it copies the end result back to the image array. This would be the same as ...


0

while (fread(&buffer, BUFFER_SIZE, 1, inputf) == 1) // repeat until end of card { fread(&buffer, BUFFER_SIZE, 1, outputf); // (data, size, number, inptr) // read 512 bytes into a buffer Why are you trying to read from outputf into buffer??!! Clearly outputf is NULL pointer which results in segfault if (buffer[0] == 0xff && ...


0

This code looks for the start of a jpg, and closes the previous open file (if it exists) then starts a new file by adding the 512 Bytes of the current block. From the background section: "Realize, of course, that JPEGs can span contiguous blocks. Otherwise, no JPEG could be larger than 512 B." The case where there's not a new header, but already an ...


1

A jpeg signature is 4 bytes; program only tests 3. Program only writes one 512-byte block.


1

char *flname = "0.jpg"; The string here is immutable. Writing to it again is undefined behavior. You need to stack allocate space for a file name. 000.jpg is 7 characters and you need one extra byte to store the null terminator so 8 characters will do it. char flname[8]; You almost had it. In essence, I'm not sure what I could use to close the ...


0

Try to implement collatz function using recursion. Work it out for a single number and check if it's printing right number of steps. If you have implemented this, most of the important stuff is done. The next part would be to start a loop and store each number, along with number of steps it's taking (collatz algorithm), inside any data-structure (list, ...


1

RE:fread - it doesn't matter either way. The fread call is going to multiply the sieof() value x the number of them ( or parameter 2 x parameter 3 ) and read that many bytes. You just need to make sure that the sizeof(buffer) is 512 in this case. Either way, it will be 512 bytes read. The program doesn't know how big the file is. Go back to the spec. The ...


0

Actually there are several ways of achieving blur. Heck you only need a single conditional statement to check if a pixel is valid or not. In your implementation, it seems like you wrote an iterative solution(for loops) to do summation of pixels (check if they are valid using lot of conditional statements !). This can also be done using recursion to get final ...


0

You can loop over the inner 3 by 3 grid and add a condition that covers all cases. Here's my code for the same section of blur. for (int k = i - 1; k < i + 2; k++) { for (int l = j - 1; l < j + 2; l++) { if (l >= 0 && l < width && k >= 0 && k < height) { sumred += image[k][l]....


2

Let me guess. It doesn't seem to be doing anything, right? Without doing a deep dive analysis, one thing jumps out at me. The inner for loop runs from 0 to width. Think carefully about the practical effect of that. From 0 to width/2, it's going to swap the left half with the right half. Then from width/2 to width, it's going to swap everything back! If ...


Top 50 recent answers are included