dhyanesh
asked on
Vector class problem
Hi
I have declared :
class Pixel
{
byte R;
byte G;
byte B;
public:
Pixel(){};
Pixel(const Pixel&);
void operator=(const Pixel&);
friend class Frame;
friend class Macroblock;
friend class BMPHeader;
};
class Frame
{
BMPHeader bmph;
vector <Macroblock> mblk;
vector <Pixel> pix;
int vertmac;
int hormac;
public:
Frame(){}; //----------------do nothing constructor
Frame(BMPHeader &,byte *);
void createMBlk(void);
void findMV(Frame &);
void display(void);
friend class Video;
};
Frame::Frame(BMPHeader& bmp,byte *buffer)
{
bmph = bmp;
pix.reserve(bmph.height*bm ph.width);
for (int j=(bmph.height-1);j>=0;j-- )
{
for(int i=0;i<bmph.width;i++)
{
int index;
switch(bmph.bitsperPixel)
{
case 24:pix[j*bmph.width+i].R = *buffer++;
pix[j*bmph.width+i].G = *buffer++;
pix[j*bmph.width+i].B = *buffer++;
break;
case 16:return;
index = GetWord(buffer); buffer += 2;
pix[j*bmph.width+i] = bmph.palette[index];
break;
case 8 :index = *buffer++;
pix[j*bmph.width+i].R = bmph.palette[index].R; //problem is here
pix[j*bmph.width+i].G = bmph.palette[index].G;
pix[j*bmph.width+i].B = bmph.palette[index].B;
break;
default:cout << "Color depth not supported";
return;
}
}
if (bmph.width%4 != 0)
for(int i=4;i>bmph.width%4;i--)
buffer++;
}
}
I get error: Access violation unhandled exception. Using VC++.
bmph.palette is also a vector of Pixel class
vector <Pixel> palette;
Please help. It is urgent.
Dhyanesh
I have declared :
class Pixel
{
byte R;
byte G;
byte B;
public:
Pixel(){};
Pixel(const Pixel&);
void operator=(const Pixel&);
friend class Frame;
friend class Macroblock;
friend class BMPHeader;
};
class Frame
{
BMPHeader bmph;
vector <Macroblock> mblk;
vector <Pixel> pix;
int vertmac;
int hormac;
public:
Frame(){}; //----------------do nothing constructor
Frame(BMPHeader &,byte *);
void createMBlk(void);
void findMV(Frame &);
void display(void);
friend class Video;
};
Frame::Frame(BMPHeader& bmp,byte *buffer)
{
bmph = bmp;
pix.reserve(bmph.height*bm
for (int j=(bmph.height-1);j>=0;j--
{
for(int i=0;i<bmph.width;i++)
{
int index;
switch(bmph.bitsperPixel)
{
case 24:pix[j*bmph.width+i].R = *buffer++;
pix[j*bmph.width+i].G = *buffer++;
pix[j*bmph.width+i].B = *buffer++;
break;
case 16:return;
index = GetWord(buffer); buffer += 2;
pix[j*bmph.width+i] = bmph.palette[index];
break;
case 8 :index = *buffer++;
pix[j*bmph.width+i].R = bmph.palette[index].R; //problem is here
pix[j*bmph.width+i].G = bmph.palette[index].G;
pix[j*bmph.width+i].B = bmph.palette[index].B;
break;
default:cout << "Color depth not supported";
return;
}
}
if (bmph.width%4 != 0)
for(int i=4;i>bmph.width%4;i--)
buffer++;
}
}
I get error: Access violation unhandled exception. Using VC++.
bmph.palette is also a vector of Pixel class
vector <Pixel> palette;
Please help. It is urgent.
Dhyanesh
ASKER
AlexFM
The program does not compile.
It says
C:\Program Files\Microsoft Visual Studio\MyProjects\finalprj \Ver1.cpp( 61) : error C2660: 'size' : function does not take 1 parameters
Also size() returns the size of the vector. I dont think it adds members.
Dhyanesh
The program does not compile.
It says
C:\Program Files\Microsoft Visual Studio\MyProjects\finalprj
Also size() returns the size of the vector. I dont think it adds members.
Dhyanesh
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you for your solution AlexFM.
Axter, I like your method as well but AlexFM was first with solution so I give him more points.
Dhyanesh
Axter, I like your method as well but AlexFM was first with solution so I give him more points.
Dhyanesh
Use size instead of reserve. reserve doesn't add members to vector.
pix.size(bmph.height*bmph.