My supervisor developed a simulator (Its a collection of codes) that reads data from a file and converts them to a signal (for example optical signal, etc.), and then the simulator saves this signal to a .sgn file.
He asked me to read a .jpg image in VS 2019 and convert it to a signal of type byte and then save the signal to .sgn file. However, when I save the signal and change its extension to .jpg (in order to make sure that the signal contains the image data) it cannot be open.
I compared the information of the original image and my signal and I see some extra garbage in the signal as shown in pictures.
- Original image
- Resulted image(Signal image)
My questions are (thank you so much in advance):
In order to solve this issue, should I read the image header file separately?
Am I reading the image file correctly? (the simulator is huge, so I can not put all the codes)
Do you have any other idea about where the problem is? like the buffer or something else.
std::ifstream inFile; inFile.open("1.jpg"); std::byte out; // type of output signal int length = sizeof(std::byte); char * memblock = new char[length]; for (int i = 0; i < process; i++) { //this line is related to the circular buffer inFile.read(memblock, length); std::byte * byte_values = (std::byte*)memblock; out = *byte_values; outputSignals[0]->bufferPut(out); // related to saving the output signal } delete[] memblock;