Answer the question
In order to leave comments, you need to log in
Why is extra information written to palette images (bmp)?
If I understand correctly - when the color depth is 1.4 or 8, then after the file and image headers, a palette of 2 ^ BitCount (color depth) colors follows. And after this palette, the indexes of the colors of the palette follow.
Here is the read function
int Image::loadpaletteimg(FILE *f)
{
int Palette_size = pow(2,BMInfoHeader.BitCount);//размер палитры - 2 в степени глубины цвета
Palette=new RGBQUAD[Palette_size];
for (int i = 0; i < Palette_size; i++) fread(&(Palette[i]),sizeof(RGBQUAD),1,f);//считываем палитру
Rgbquad=new RGBQUAD*[BMInfoHeader.Height];//cтолбцы
for (int i = 0; i < BMInfoHeader.Height; i++)//построчно записываем
{
Rgbquad[i]=new RGBQUAD[BMInfoHeader.Width];//строки
fread(Rgbquad[i], sizeof(RGBQUAD), BMInfoHeader.Width, f);
}
if(Rgbquad) cout<<"\nИзображение успешно загружено!"<<endl;
return 1;
}
void Image::writepaletteimg(FILE *f)
{
int Palette_size = pow(2,BMInfoHeader.BitCount);
for (int i = 0; i < Palette_size; i++)
{
fwrite(&(Palette[i]),sizeof(RGBQUAD),1,f);
//cout<<i<<endl;
}
cout<<"Палитра записана!"<<endl;
int size = BMInfoHeader.Height*BMInfoHeader.Width;
for (int i = 0; i < BMInfoHeader.Height; i++)
{
fwrite(Rgbquad[i], sizeof(RGBQUAD), BMInfoHeader.Width, f);
}
fclose(f);
return;
}
Answer the question
In order to leave comments, you need to log in
From
Rgbquad=new RGBQUAD*[BMInfoHeader.Height];//cтолбцы
and did not understand below. https://ru.wikipedia.org/wiki/BMP#BITMAPFILEHEADER
I'm scrolling through Wikipedia and I see that there is such a field "Color table size in cells." the latest versions of the bmp format. Those. it may be worth determining the size of the table from the header, and not raising it to the power of two.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question