I am using a jpeg encoder library (Jpegant) for compressing raw YCbCr images to Jpeg in C. The library works fine for a YCbCr image which has separate Y Cb and Cr components. Also in the library, the Y, Cb, and Cr streams are encoded separately and the generated bytes are written to the Jpeg file after the header.
Now I want to use the same library for encoding only the Y stream to a grayscale Jpeg image. The first step i did was to remove the Cb and Cr encoding. So only the Y stream is getting encoded and written to the file. The generated file is not a grayscale image, its just junk.
I tried doing the same by sending a stream of zeroes in both the Cb and Cr and this gives me what I want, so I assumed the issue is not in the encoding but in the headers. The header I am using is described here https://github.com/t27/vt-fox-1/tree/master/STM32L1_Code/encoder#basic-output-file
I have modified the number of streams(commented as 'nrofcomponents' in the above file) in the SOF and SOS sections. I have also removed the relevant Chrominance tables/data from the SOF,SOS and DHT sections. I set the Y subsampling to 0x11. The lengths for each of the sections are also modified. I used jpegsnoop too, and even that gives no errors.
The only problem is that most of the jpeg viewers are saying that my file is invalid and cant display it.
What else should I change in the header?
PS:I am creating a 16*8(w*h) pixel array and encoding 2 matrices of 8*8 at a time, I have set my RSI as Imagewidth/16.