I'm making my own lossy image compression codec in c++ w/ SDL, and the decoder isn't reading the header correctly (or more likely the encoder isn't writing it right)
If I replace w = inimage->w with w = 512, the reader still doesn't give the correct numberCode:#include <SDL.h>
#include <SDL_image.h>
#include <iostream>
#include <fstream>
#include <windows.h>
using namespace std;
int ICEC();
int DICEC();
void Slock(SDL_Surface *dest);
void Sulock(SDL_Surface *dest);
int main(int argc, char *argv[])
{
if(SDL_Init(SDL_INIT_VIDEO) == -1)
return -1;
atexit(SDL_Quit);
ICEC();
DICEC();
}
int ICEC()
{
SDL_Surface * inimage = IMG_Load("Image\\test.bmp");
// vars
Slock(inimage);
int w = inimage->w;
int h = inimage->h;
Uint8 bpp = inimage->format->BytesPerPixel;
bool subsample = true;
ofstream out;
//write width, height, and bytes per pixel as a header
out.open("Image\\test.ice", ios::binary);
out.write(reinterpret_cast<char*>(&w), sizeof(int));
out.write(reinterpret_cast<char*>(&h), sizeof(int));
out.write(reinterpret_cast<char*>(&bpp), sizeof(Uint8));
Sulock(inimage);
out.close();
return 0;
}
void Slock(SDL_Surface *dest)
{
if ( SDL_MUSTLOCK(dest) )
{
if ( SDL_LockSurface(dest) < 0 )
{
return;
}
}
}
void Sulock(SDL_Surface *dest)
{
if ( SDL_MUSTLOCK(dest) )
{
SDL_UnlockSurface(dest);
}
}
Also, the call to Slock is causing an access violation.
I can't figure out the source of all these problems :(
Thanks,
MC