I got the code for MJPEG decoding from here and I am trying to split the code for IDCT into smaller functions.
The IDCT function in the original code is as follows:
The function IDCT() declares the array Y[] which transfers data across all for-loops. In your refactored code every function declares its own Y[] array. The same error you did with the Yc[] array. Make the arrays global and see if the code runs.
Edit 2017_08-28
Give Yc[] an extra dimension:
void IDCTforY(int32_t *input, uint8_t *output)
{
int32_t Y[64];
int32_t k, l;
int32_t Yc[8][8];
for (l = 0; l < 8; l++)
{
for (k = 0; k < 8; k++)
Yc[l][k] = Y(k, l);
idct_1d(Yc[l]);
}
//Running the loop for de-scaling separately....
for (l = 0; l < 8; l++)
{
for (k = 0; k < 8; k++)
{
int32_t r = 128 + DESCALE(Yc[l][k], S_BITS + 3);
r = r > 0 ? (r < 255 ? r : 255) : 0;
X(k, l) = r;
}
}
}
Edit 2017-08-29
I cannot explain the optical effect, but you broke the data flow. The original code was like this:
for (l = 0; l < 8; l++)
{
int32_t Yc[8];
Fill(Yc);
idct_1d(Yc);
Descale_and_WriteOut(Yc);
}
You made of it:
int32_t Yc[8];
for (l = 0; l < 8; l++)
{
Fill(Yc);
idct_1d(Yc);
}
for (l = 0; l < 8; l++)
{
Descale_and_WriteOut(Yc);
}
You see, that only the result of the last iteration of the input-and-process-loop is passed to the output-loop. I gave every l-iteration own memory in Yc[][].