My task is to implement JPEG encoder/decoder in Qt. I have to process jpeg markers (for example 0xFFC4 which is start of huffman table) and data between markers. I open my jpeg file using QFile class. While debugging the result is shown in picture bellow. As you can see the value in marker[0] is -1/255 and marker[1] is -40/216, and the if statement is never true I don’t know why? The code is following:
try{
char markers[2];
char TableData[64];
QFile *file= new QFile( "NovaSlika.jpeg");
if(file->open(QFile::ReadOnly )){
while(file->read((char*)markers,sizeof(markers))){
if(markers[0]=='255' && markers[1]=='216'){//FF i C4
char TableLength[2];
char tableMetaData;
file->read((char*)TableLength,sizeof(TableLength));//Read table length
file->read((char*)tableMetaData,sizeof(tableMetaData));//Read metadata
file->read((char*)TableData,sizeof(TableData));//Read data
break;
}
}
}
Picture of debugging process is here
Be careful in your while condition: read() returns
You should probably do:
And this line isn’t right either:
Get rid of those single quotes. (-Wall on gcc would have warned you on this). It should be: