80% Asperges, 20% Asparagus, 100% Career Destroying.

Pages: 12
Got a code that's producing memory address of stored 24bit pixel data. I'm pretty confident I can get the 3 byte colour code, pretty easily from each memory address.
If I change the array in struct, manually. It's giving me the other addresses, but if I loop or change the Array address in any other way elsewhere it's giving me random strings that seem to be totally irrelevant and I can't loop it in struct.
Any help will be appreciated and if I go on to get the correct code for retrieving 8 bits from the addresses and storing/outputting as 0-255 I'll be sure to post.
By the way I do want to work towards a Byte Array but for now I don't need help with that. I just need help with an address array output.
I know I can read as a pointer for draining the memory addresses from the array and get the R,G,B from that. But I really need a list of Addresses.
So any idea how and where to loop for memory address output?
If ya help me out you might get a place in Heaven, but only if you're scared of heights.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

struct BmpSignature
{
    unsigned char data[2]; //2 Signature check
    BmpSignature() { data[0] = data[1] = 0; }
//2 Bytes
};
struct BmpHeader
{
    unsigned int fileSize; //4 The size of the file in bytes
    unsigned short reserved1;
    unsigned short reserved2; //2 Both for apparent extension
    unsigned long int dataOffset; //4 Start of Pixel Data
    BmpHeader() : fileSize(0),  reserved1(0), reserved2(0), dataOffset(0) { }
//12 Bytes
};
struct BmpInfoHeader 
{
	unsigned long int bmpInfoSize; // 4 Size of info header
	unsigned long int bmpInfoWidth; //4 Image width in pixels 
	unsigned long int bmpInfoHeight; //4 Image height in pixels 
	unsigned short bmpInfoPlanes; //2 Must be 1 
	unsigned short bmpInfoBitCount; //2 Bits per pixel - 1, 4, 8, 16, 24, or 32 
	unsigned long int bmpInfoCompression; //4 Compression type (0 = uncompressed) 
	unsigned long int bmpInfoSizeImage; //4 Image Size - may be zero for uncompressed images 
	unsigned long int bmpInfoXPelsPerMeter; //4 Preferred resolution in pixels per meter 
	unsigned long int bmpInfoYPelsPerMeter; //4 Preferred resolution in pixels per meter 
	unsigned long int bmpInfoClrUsed; //4 Number Color Map entries that are actually used 
	unsigned long int bmpInfoClrImportant; //4 Number of Significant Colours
//40 Bytes
};
#pragma pack(push,1)
struct AddressArray 
{
	
	unsigned int ImageByteAddress []; //Memory location where the 24 bits have been stored
	                                 //But will not accept int at this point (in a struct) or a loop. A loop at print
	                                //Isn't outing the address but packed nonsense. I don't know, where to loop for
	                               //a list of addresses to be read 8 bits at a time.

};
#pragma pack(pop)


fstream fin("8ry328ry.bmp",ios::binary|ios::in); //open bitmap

void ReadHeader(ifstream &fin, BmpSignature &sig, BmpHeader &header) //name of function and access granting
{
    if(!fin) // if file is not open end program
        return;

    fin.seekg(0, ios::beg); //go to start of Hexidecimal data
    
    fin.read((char*) &sig, sizeof(sig)); //read from bitmap hexidecimal and store the equal amount of bit or bytes to corresponding 
    fin.read((char*) &header, sizeof(header));
}
void ReadInfoHeader(ifstream &fin, BmpInfoHeader &iheader)    
{
	    
    fin.seekg(14, ios::beg); //Go to the 14th Byte
    
    fin.read((char* ) &iheader, sizeof(iheader)); //read from bitmap hexidecimal and store equal amount of data to corresponding
}
void ReadPixelData(ifstream &fin, BmpHeader &header, BmpInfoHeader &iheader, AddressArray &BA)  
{
	fin.seekg(header.dataOffset, ios::beg); //locate pixel data using information from initial header
	fin.read((char *) &BA.ImageByteAddress, sizeof(iheader.bmpInfoWidth*iheader.bmpInfoHeight*iheader.bmpInfoBitCount)); //Store all pixel data as an array the size of pixels*bits, so here 3 bytes each.
        //I can use if statements for anything below 16 but right now I'm only working with 24bit	
}
void PrintHeader(BmpSignature sig, BmpHeader header)
{
    cout<<"==== BMP HEADER ===="<<endl;
    cout<<endl;
    cout<<"+ Signature  : " << sig.data[0]<<sig.data[1]<<endl;
    cout<<"+ File Size  : " << header.fileSize<<" byte(s)"<<endl;
    cout<<"+ Reserved1  : " << header.reserved1<<endl;
    cout<<"+ Reserved2  : " << header.reserved2<<endl;
    cout<<"+ Data Offset: " << header.dataOffset<<" byte(s)"<<endl;
}
void PrintBmpInfo(BmpInfoHeader iheader)
{   
    cout<<"==== BMP INFO HEADER ===="<<endl;
    cout<<endl;
    cout<<"+ Info Header Size: " <<iheader.bmpInfoSize<<" bytes"<<endl;
    cout<<"+ Width of Bmp: " <<iheader.bmpInfoWidth<<" pixels"<<endl;
    cout<<"+ Height of Bmp: "<<iheader.bmpInfoHeight<<" pixels"<<endl;
    cout<<"+ Number of Planes: "<<iheader.bmpInfoPlanes<<endl;
    cout<<"+ Number of Bits per pixel: "<<iheader.bmpInfoBitCount<<endl; 
    cout<<"+ Compression Type: "<<iheader.bmpInfoCompression<<endl;
    cout<<"+ Pixel Data: "<<iheader.bmpInfoSizeImage<<endl;
    cout<<"+ Prefered X Res: "<<iheader.bmpInfoXPelsPerMeter<<endl;
    cout<<"+ Prefered Y Res: "<<iheader.bmpInfoYPelsPerMeter<<endl;
    cout<<"+ Colour Map Entries in Use: "<<iheader.bmpInfoClrUsed<<endl;
    cout<<"+ Number of Significant Colours: "<<iheader.bmpInfoClrImportant<<endl;
}
void PrintbitInfo(BmpInfoHeader iheader)
{
	cout<<"+ Number of Pixels in Image: "<<iheader.bmpInfoWidth*iheader.bmpInfoHeight<<endl;
	cout<<"+ Number of Bits Storing Pixel Information: "<<iheader.bmpInfoWidth*iheader.bmpInfoHeight*iheader.bmpInfoBitCount<<endl;
	cout<<"+ Number of Pixel Bytes: "<<iheader.bmpInfoWidth*iheader.bmpInfoHeight*iheader.bmpInfoBitCount/8<<endl; 
	//The above prints, are printing all to screen, with a descriptor and a 'pointer' of what to print
}
void DataCheck(BmpInfoHeader iheader, BmpHeader header)
{
	if (iheader.bmpInfoWidth*iheader.bmpInfoHeight*iheader.bmpInfoBitCount/8 == iheader.bmpInfoSizeImage)
	bool DataCheck1 = true;
        else
        DataCheck1 = false;
	if(iheader.bmpInfoSizeImage + iheader.bmpInfoSize + 14 == header.fileSize)
	bool DataCheck2 = true;
        else
        DataCheck2 = false;
	if (DataCheck1&&DataCheck2 = true)
	cout<<"Data Compatable"<<endl;  else
	cout<<"Data Incompatable"<<endl;

//Quick DataCheck if Data Incompatable... Something has gone Wrong. 
}


void PrintAddressArray(AddressArray BA, BmpInfoHeader iheader)
{ 
cout<<"==== Address Array ===="<<endl;
cout<<endl;
cout<<BA.ImageByteAddress<<endl;
// This is the printing problem if I loop this it's not printing addresses, it's printing long integers that seem irrelevant.
}
void PrintSpacingLine()
{
	cout<<endl;
}
int main()
{
    
    ifstream fin("8ry328ry.bmp", ios::binary);
    
    BmpSignature sig;
    BmpHeader hdr;
    BmpInfoHeader ihdr;
    AddressArray BA;
    DataCheck(ihdr, hdr);
    ReadHeader(fin, sig, hdr);
    PrintHeader(sig, hdr);
    PrintSpacingLine();
    ReadInfoHeader(fin, ihdr);
    ReadPixelData(fin, hdr, ihdr, BA);
    PrintSpacingLine();
    PrintBmpInfo(ihdr);
    PrintSpacingLine();
	PrintbitInfo(ihdr);
	PrintSpacingLine();
	PrintAddressArray(BA, ihdr);
    return 0;  
    //This is for ordering the program.
}


If you run the code and fill the ImageByteAddress Array manually within the struct
So like...

1
2
3
ImageByteAddress[1]
ImageByteAddress[37]
ImageByteAddress[412]


You'll get the 4Byte address for each pixel (though it's only storing 3Bytes of data), but I can't seem to loop the output. As I said above hopefully someone can help before I go 'Benoit'.
I've got nerve damage on my brain [Insert Arnold Schwarzenegger quote] and don't get to work on this often, each time I do I want to smash my computer.

You have to put the .bmp in the same folder as the code and .exe obviously.
Last edited on
Memory addresses have nothing to do with your problem (that I can see). You just need to read in the pixel data.

Instead of using unsigned int, long, short, etc., you should use <cstdint> which defines sized data types like uint32_t, uint16_t, uint8_t.

You need to pack all of your structs. The struct that only contains the array is just extra junk. And that array needs to be assigned some storage at some point. It's best if the ReadPixelData simply allocated and returned the array.

You are opening your bitmap file both globally (outside any function in the middle of the program text) and also in main.

You call DataCheck before you read anything into the structs.

Multiplying width * height by bmpInfoBitCount is wrong. bmpInfoBitCount is 24 (bits). You want the number of bytes, not bits. And using the sizeof operator is wrong, too. (I don't know what you were thinking there. :-)

Another important point is that the rows are padded to an alignment of 4 bytes.

Here's a quick rewrite of your code. I've just hardcoded the 24-bit (3-byte) per pixel format.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;

#pragma pack(push,1)
struct BmpSignature {
    unsigned char data[2]; //2 Signature check
};

struct BmpHeader {
    uint32_t fileSize; //4 The size of the file in bytes
    uint16_t reserved1; //2 
    uint16_t reserved2; //2 
    uint32_t dataOffset; //4 Start of Pixel Data
};

struct BmpInfoHeader  {
    uint32_t bmpInfoSize; // 4 Size of info header
    uint32_t bmpInfoWidth; //4 Image width in pixels 
    uint32_t bmpInfoHeight; //4 Image height in pixels 
    uint16_t bmpInfoPlanes; //2 Must be 1 
    uint16_t bmpInfoBitCount; //2 Bits per pixel - 1, 4, 8, 16, 24, or 32 
    uint32_t bmpInfoCompression; //4 Compression type (0 = uncompressed) 
    uint32_t bmpInfoSizeImage; //4 Image Size - may be zero for uncompressed images 
    uint32_t bmpInfoXPelsPerMeter; //4 Preferred resolution in pixels per meter 
    uint32_t bmpInfoYPelsPerMeter; //4 Preferred resolution in pixels per meter 
    uint32_t bmpInfoClrUsed; //4 Number Color Map entries that are actually used 
    uint32_t bmpInfoClrImportant; //4 Number of Significant Colours
};
#pragma pack(pop)

void ReadHeader(ifstream &fin, BmpSignature &sig, BmpHeader &header) {
    fin.seekg(0, ios::beg);
    fin.read((char*)&sig, sizeof(sig));
    fin.read((char*)&header, sizeof(header));
}

void ReadInfoHeader(ifstream &fin, BmpInfoHeader &iheader) {
    fin.seekg(14, ios::beg);
    fin.read((char* ) &iheader, sizeof(iheader));
}

// Hardcoded for 3-byte (24-bit) data
uint8_t *ReadPixelData(ifstream &fin, BmpHeader &header, BmpInfoHeader &iheader) {
    uint8_t *pixels = nullptr;
    auto extra = (4 - (iheader.bmpInfoWidth * 3) % 4) % 4;//width is aligned to 4 bytes
    auto rowsize = iheader.bmpInfoWidth * 3 + extra;
    fin.seekg(header.dataOffset, ios::beg);
    pixels = new uint8_t[rowsize * iheader.bmpInfoWidth];
    fin.read((char*)pixels, rowsize * iheader.bmpInfoHeight);
    return pixels;
}

void PrintHeader(BmpSignature sig, BmpHeader header) {
    cout<<"==== BMP HEADER ===="<<endl;
    cout<<"+ Signature  : " << sig.data[0]<<sig.data[1]<<endl;
    cout<<"+ File Size  : " << header.fileSize<<" byte(s)"<<endl;
    cout<<"+ Reserved1  : " << header.reserved1<<endl;
    cout<<"+ Reserved2  : " << header.reserved2<<endl;
    cout<<"+ Data Offset: " << header.dataOffset<<" byte(s)\n\n";
}

void PrintBmpInfo(BmpInfoHeader iheader) {   
    cout<<"==== BMP INFO HEADER ===="<<endl;
    cout<<"+ Info Header Size: " <<iheader.bmpInfoSize<<" bytes"<<endl;
    cout<<"+ Width of Bmp: " <<iheader.bmpInfoWidth<<" pixels"<<endl;
    cout<<"+ Height of Bmp: "<<iheader.bmpInfoHeight<<" pixels"<<endl;
    cout<<"+ Number of Planes: "<<iheader.bmpInfoPlanes<<endl;
    cout<<"+ Number of Bits per pixel: "<<iheader.bmpInfoBitCount<<endl; 
    cout<<"+ Compression Type: "<<iheader.bmpInfoCompression<<endl;
    cout<<"+ Pixel Data: "<<iheader.bmpInfoSizeImage<<endl;
    cout<<"+ Prefered X Res: "<<iheader.bmpInfoXPelsPerMeter<<endl;
    cout<<"+ Prefered Y Res: "<<iheader.bmpInfoYPelsPerMeter<<endl;
    cout<<"+ Colour Map Entries in Use: "<<iheader.bmpInfoClrUsed<<endl;
    cout<<"+ Number of Significant Colours: "<<iheader.bmpInfoClrImportant<<"\n\n";
}

void PrintbitInfo(BmpInfoHeader iheader) {
    cout<<"==== BIT INFO ===="<<endl;
    cout<<"+ Number of Pixels in Image: "
        <<iheader.bmpInfoWidth*iheader.bmpInfoHeight<<endl;
    cout<<"+ Number of Bits Storing Pixel Information: "
        <<iheader.bmpInfoWidth*iheader.bmpInfoHeight*iheader.bmpInfoBitCount<<endl;
    cout<<"+ Number of Pixel Bytes: "
        <<iheader.bmpInfoWidth*iheader.bmpInfoHeight*iheader.bmpInfoBitCount/8<<"\n\n";
}

bool DataCheck(BmpInfoHeader iheader, BmpHeader header) {
    auto extra = (4 - (iheader.bmpInfoWidth * 3) % 4) % 4;//width is aligned to 4 bytes
    auto rowsize = iheader.bmpInfoWidth * (iheader.bmpInfoBitCount / 8) + extra;
    if ((rowsize * iheader.bmpInfoHeight == iheader.bmpInfoSizeImage)
       && (iheader.bmpInfoSizeImage + iheader.bmpInfoSize + 14 == header.fileSize))
        return true;
    cout<<"Data Incompatable\n";
    return false;
}

void PrintPixelArray(uint8_t *pixels, BmpInfoHeader iheader) { 
    auto extra = (4 - (iheader.bmpInfoWidth * 3) % 4) % 4;//width is aligned to 4 bytes
    auto rowsize = iheader.bmpInfoWidth * 3 + extra;
    cout<<"==== Pixel Array ====\n";
    cout << hex << setfill('0');    
    for (uint32_t row = 0; row < iheader.bmpInfoHeight; row++) {
        for (uint32_t col = 0; col < iheader.bmpInfoWidth; col++) {
            uint8_t *p = &pixels[row * rowsize + col * 3];
            for (int i = 0; i < 3; i++)
                cout << setw(2) << (unsigned)p[i];
            cout << ' ';
        }
        cout << '\n';
    }
}

int main() {
    BmpSignature sig;
    BmpHeader hdr;
    BmpInfoHeader ihdr;

    ifstream fin("8ry328ry.bmp", ios::binary);
    ReadHeader(fin, sig, hdr);
    ReadInfoHeader(fin, ihdr);

    if (!DataCheck(ihdr, hdr))
        return 0;

    PrintHeader(sig, hdr);
    PrintBmpInfo(ihdr);
    PrintbitInfo(ihdr);

    uint8_t *Pixels = ReadPixelData(fin, hdr, ihdr);
    PrintPixelArray(Pixels, ihdr);

    delete [] Pixels;
    return 0;  
}

Last edited on
That doesn't make any sense to me. The addresses have nothing to do with it, and you certainly don't need them for compression. What exactly do you mean by "address"?
I'm tapping out, man. Maybe it's a language problem.
See this:

http://www.cplusplus.com/doc/tutorial/pointers/

A pointer contains the address within the memory.


It's for creating pointers to memory rather than 3/4Bytes for each pixel.
It sounds like you are talking about a palette. See:

http://www.cplusplus.com/forum/general/22429/
But, I would argue that pointers are probably overkill. Just hop around from index to index in the byte array. adding a pointer on top of that is probably adding confusion (and possibly inefficiency). If the byte array itself is a pointer, so be it (a vector may be useful, or not, here .. there isnt much gained from it beyond memory management), but you don't need more pointers on top of that.
Literally, nothing, not one thing anyone has said has helped me at all.
I skimmed your code tpb and it seemed legit after I took it in the program (not just comp+ran) properly read my reaction was that of Michael Scotts 'No, NO! GOD NO!'.
You told me not to use sizeof then attempted to generate your own alternative which would just increase processing time. You's don't understand why memory is important? I'll tell ya now, if you's are trolling you'll probably end up in a simulation completely unable to code.

Here is a beta, it needs fixing maybe post fixes here or let other people fix on their own, depends if the help is needed. But it seems pointless to even ask, I'm sorry I was wrong about not insulting that code is terrible.



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

struct BmpSignature
{
    unsigned char data[2]; //2 Signature check
    BmpSignature() { data[0] = data[1] = 0; }
//2 Bytes
};
struct BmpHeader
{
    unsigned int fileSize; //4 The size of the file in bytes
    unsigned short reserved1;
    unsigned short reserved2; //2 Both for apparent extension
    unsigned long int dataOffset; //4 Start of Pixel Data
    BmpHeader() : fileSize(0),  reserved1(0), reserved2(0), dataOffset(0) { }
//12 Bytes
};
struct BmpInfoHeader 
{
	unsigned long int bmpInfoSize; // 4 Size of info header
	unsigned long int bmpInfoWidth; //4 Image width in pixels 
	unsigned long int bmpInfoHeight; //4 Image height in pixels 
	unsigned short bmpInfoPlanes; //2 Must be 1 
	unsigned short bmpInfoBitCount; //2 Bits per pixel - 1, 4, 8, 16, 24, or 32 
	unsigned long int bmpInfoCompression; //4 Compression type (0 = uncompressed) 
	unsigned long int bmpInfoSizeImage; //4 Image Size - may be zero for uncompressed images 
	unsigned long int bmpInfoXPelsPerMeter; //4 Preferred resolution in pixels per meter 
	unsigned long int bmpInfoYPelsPerMeter; //4 Preferred resolution in pixels per meter 
	unsigned long int bmpInfoClrUsed; //4 Number Color Map entries that are actually used 
	unsigned long int bmpInfoClrImportant; //4 Number of Significant Colours
//40 Bytes
};
#pragma pack(push,1)
struct AddressArray 
{
	
	uint32_t Temp []; 
	uint32_t Red [];
	uint32_t Green [];          //Colour 32 is temporary.                    
	uint32_t Blue [];
	uint32_t padding [];
	uint8_t Size;
	                              

};
#pragma pack(pop)

void ReadHeader(ifstream &fin, BmpSignature &sig, BmpHeader &header) 
{
    if(!fin) 
        return;

    fin.seekg(0, ios::beg); 
    
    fin.read((char*) &sig, sizeof(sig)); 
    fin.read((char*) &header, sizeof(header));
}
void ReadInfoHeader(ifstream &fin, BmpInfoHeader &iheader)    
{
	    
    fin.seekg(14, ios::beg); 
    
    fin.read((char* ) &iheader, sizeof(iheader)); 
}
void ReadPixelData(ifstream &fin, BmpHeader &header, BmpInfoHeader &iheader, AddressArray &BA)  
{
	

	for(uint32_t n=0; n<iheader.bmpInfoSizeImage; n++) {
	fin.seekg(header.dataOffset+n, ios::beg); 
	fin.read((char *) &BA.Red, sizeof(BA.Size));
	fin.seekg(header.dataOffset+n, ios::beg);	
	fin.read((char *) &BA.Green, sizeof(BA.Size)); 
	fin.seekg(header.dataOffset+n, ios::beg); 
	fin.read((char *) &BA.Blue, sizeof(BA.Size));  
	fin.seekg(header.dataOffset+n, ios::beg); 
	fin.read((char *) &BA.padding, sizeof(BA.Size));}
	

}
void PrintHeader(BmpSignature sig, BmpHeader header)
{
    cout<<"==== BMP HEADER ===="<<endl;
    cout<<endl;
    cout<<"+ Signature  : " << sig.data[0]<<sig.data[1]<<endl;
    cout<<"+ File Size  : " << header.fileSize<<" byte(s)"<<endl;
    cout<<"+ Reserved1  : " << header.reserved1<<endl;
    cout<<"+ Reserved2  : " << header.reserved2<<endl;
    cout<<"+ Data Offset: " << header.dataOffset<<" byte(s)"<<endl;
}
void PrintBmpInfo(BmpInfoHeader iheader)
{   
    cout<<"==== BMP INFO HEADER ===="<<endl;
    cout<<endl;
    cout<<"+ Info Header Size: " <<iheader.bmpInfoSize<<" bytes"<<endl;
	cout<<"+ Width of Bmp: " <<iheader.bmpInfoWidth<<" pixels"<<endl;
	cout<<"+ Height of Bmp: "<<iheader.bmpInfoHeight<<" pixels"<<endl;
    cout<<"+ Number of Planes: "<<iheader.bmpInfoPlanes<<endl;
	cout<<"+ Number of Bits per pixel: "<<iheader.bmpInfoBitCount<<endl; 
	cout<<"+ Compression Type: "<<iheader.bmpInfoCompression<<endl;
	cout<<"+ Pixel Data: "<<iheader.bmpInfoSizeImage<<endl;
	cout<<"+ Prefered X Res: "<<iheader.bmpInfoXPelsPerMeter<<endl;
	cout<<"+ Prefered Y Res: "<<iheader.bmpInfoYPelsPerMeter<<endl;
	cout<<"+ Colour Map Entries in Use: "<<iheader.bmpInfoClrUsed<<endl;
	cout<<"+ Number of Significant Colours: "<<iheader.bmpInfoClrImportant<<endl;
}
void PrintbitInfo(BmpInfoHeader iheader)
{
	cout<<"==== PIXEL INFO ===="<<endl;
	cout<<endl;
	cout<<"+ Number of Pixels in Image: "<<iheader.bmpInfoWidth*iheader.bmpInfoHeight<<endl;
	cout<<"+ Number of Bits Storing Pixel Information: "<<iheader.bmpInfoWidth*iheader.bmpInfoHeight*iheader.bmpInfoBitCount<<endl;
	cout<<"+ Number of Pixel Bytes: "<<iheader.bmpInfoWidth*iheader.bmpInfoHeight*iheader.bmpInfoBitCount/8<<endl; 

}
bool DataCheck(BmpInfoHeader iheader, BmpHeader header)
{
    if ((iheader.bmpInfoWidth*iheader.bmpInfoHeight*iheader.bmpInfoBitCount/8 == iheader.bmpInfoSizeImage)
       & (iheader.bmpInfoSizeImage + iheader.bmpInfoSize + 14 == header.fileSize))
        return true; 
		else
        return false;
}


void PrintAddressArray(AddressArray BA, BmpInfoHeader iheader)
{ 
cout<<"==== MEMORY INFO ===="<<endl;
cout<<endl;
unsigned long int ROWS = iheader.bmpInfoWidth;
unsigned long int COLS = iheader.bmpInfoHeight;
uint32_t i = ROWS;
uint32_t j = 0;
while (i > 0) {
while (j < COLS) {


std::cout << ( void * )&BA.Red[j]  << "   IS THE MEMORY ADDRESS"<<"   OF RED" << "    AT PIXEL"<< "   ROW:  "<< i << "   " << "   COLUMN:  " <<j<<'\t' 
                 <<"   Content: " << std::hex << std::uppercase << BA.Red[j]<< " "<<endl;;
std::cout << ( void * )&BA.Green[j]  << "   IS THE MEMORY ADDRESS"<<"   OF GREEN" << "  AT PIXEL"<< "   ROW:  " << i << "   " << "   COLUMN:  " <<j<<'\t'
                <<"   Content: "<< std::hex << std::uppercase << BA.Green[j]<< " "<<endl;
std::cout << ( void * )&BA.Blue[j]  << "   IS THE MEMORY ADDRESS"<<"   OF BLUE" << "   AT PIXEL"<< "   ROW:  " << i << "   " << "   COLUMN:  " <<j<<'\t' 
                <<"   Content: "<< std::hex << std::uppercase << BA.Blue[j]<< " "<<endl;;
				j = j+1; }
if (j=j+1)			
i=i-1;
if (i=i-1)
j=0;
}
}

void PrintSpacingLine()
{
	cout<<endl;
}
int main()
{
    
    ifstream fin("8ry328ry.bmp", ios::binary);
    
    BmpSignature sig;
    BmpHeader hdr;
    BmpInfoHeader ihdr;
    AddressArray BA;
    DataCheck;
    ReadHeader(fin, sig, hdr);
    ReadInfoHeader(fin, ihdr);
    ReadPixelData(fin, hdr, ihdr, BA);
    PrintSpacingLine();
    PrintHeader(sig, hdr);
    PrintSpacingLine();
    PrintSpacingLine();
    PrintBmpInfo(ihdr);
    PrintSpacingLine();
	PrintbitInfo(ihdr);
	PrintSpacingLine();
	PrintAddressArray(BA, ihdr);
    return 0;  

}


So here ya's go. I might post it finished I might not depends if ya need help and it seems ya's do.
I punched my little sister because of tpb's code.
This takes about 30 seconds to boot depending on processor, but then fast af.
Last edited on
You are a moron. That's the root of the problem. Sadly, that can't be fixed. Have a nice life.
If you think my code is random or wrong. I've made this to illustrate the problem. I've got workaround but they increase the processing time too much basically the n integer is reaching 11(12) and jumping to 255, then continues jumping every n iteration. To properly fix it I need to comprehend it and tbh I don't comprehend it at all. I don't know why it's jumping at 11.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#include <iostream>
#include <fstream>
using namespace std;

struct BmpSignature
{
    unsigned char data[2]; //2 Signature check

//2 Bytes
};
struct BmpHeader
{
    long int fileSize; //4 The size of the file in bytes
    unsigned short reserved1;
    unsigned short reserved2; //2 Both for apparent extension
    unsigned int dataOffset; //4 Start of Pixel Data
    BmpHeader() : fileSize(0),  reserved1(0), reserved2(0), dataOffset(0) { }
//12 Bytes
};
struct BmpInfoHeader 
{
	uint32_t bmpInfoSize; // 4 Size of info header
	uint32_t bmpInfoWidth; //4 Image width in pixels 
	uint32_t bmpInfoHeight; //4 Image height in pixels 
	unsigned short bmpInfoPlanes; //2 Must be 1 
	unsigned short bmpInfoBitCount; //2 Bits per pixel - 1, 4, 8, 16, 24, or 32 
	uint32_t bmpInfoCompression; //4 Compression type (0 = uncompressed) 
	uint32_t bmpInfoSizeImage; //4 Image Size - may be zero for uncompressed images 
	uint32_t bmpInfoXPelsPerMeter; //4 Preferred resolution in pixels per meter 
	uint32_t bmpInfoYPelsPerMeter; //4 Preferred resolution in pixels per meter 
	uint32_t bmpInfoClrUsed; //4 Number Color Map entries that are actually used 
	uint32_t bmpInfoClrImportant; //4 Number of Significant Colours
//40 Bytes
};

struct AddressArray 
{
	
	 


    
	uint8_t Red [];
	uint8_t Green [];          //Colour 32 is temporary.                    
	uint8_t Blue [];
	uint8_t Size;
	uint32_t n=0;
	uint32_t k=0;
	uint32_t r;
	                              

};


void ReadHeader(ifstream &fin, BmpSignature &sig, BmpHeader &header) 
{
    if(!fin) 
        return;

    fin.seekg(0, ios::beg); 
    
    fin.read((char*) &sig, sizeof(sig)); 
    fin.read((char*) &header, sizeof(header));
}
void ReadInfoHeader(ifstream &fin, BmpInfoHeader &iheader)    
{
	    
    fin.seekg(14, ios::beg); 
    
    fin.read((char* ) &iheader, sizeof(iheader)); 
}
void ReadPixelData(ifstream &fin, BmpHeader &header, BmpInfoHeader &iheader, AddressArray &BA)  
{
	


	BA.r = header.dataOffset;
	

	while (BA.n<iheader.bmpInfoSizeImage){
	fin.seekg(BA.r+BA.n, ios::beg); 
	fin>> std::dec >> BA.Blue[BA.k];
	cout<<BA.n<< "    "<<BA.r+BA.n<<"   "<<BA.k<< endl; 
	BA.n= BA.n+1;
	fin.seekg(BA.r+BA.n, ios::beg); 
	fin>> std::dec >> BA.Blue[BA.k];
	cout<<BA.n<< "    "<<BA.r+BA.n<< "  "<<BA.k<< endl; 
	BA.n= BA.n+1;//Gotta read the hex from memory (BA.TEMP) 1 Byte at a time & convert to Dec. instead of byte do as file read. from memory adress, so count characters.
	fin.seekg(BA.r+BA.n, ios::beg); 
	fin>> std::dec >> BA.Blue[BA.k];
	cout<<BA.n<< "    "<<BA.r+BA.n<<"   "<<BA.k<< endl; 
	BA.n= BA.n+1;
	BA.k= BA.k+1;}
	

}
void PrintHeader(BmpSignature sig, BmpHeader header)
{
    cout<<"==== BMP HEADER ===="<<endl;
    cout<<endl;
    cout<<"+ Signature  : " << sig.data[0]<<sig.data[1]<<endl;
    cout<<"+ File Size  : " << header.fileSize<<" byte(s)"<<endl;
    cout<<"+ Reserved1  : " << header.reserved1<<endl;
    cout<<"+ Reserved2  : " << header.reserved2<<endl;
    cout<<"+ Data Offset: " << header.dataOffset<<" byte(s)"<<endl;
}
void PrintBmpInfo(BmpInfoHeader iheader)
{   
    cout<<"==== BMP INFO HEADER ===="<<endl;
    cout<<endl;
    cout<<"+ Info Header Size: " <<iheader.bmpInfoSize<<" bytes"<<endl;
	cout<<"+ Width of Bmp: " <<iheader.bmpInfoWidth<<" pixels"<<endl;
	cout<<"+ Height of Bmp: "<<iheader.bmpInfoHeight<<" pixels"<<endl;
    cout<<"+ Number of Planes: "<<iheader.bmpInfoPlanes<<endl;
	cout<<"+ Number of Bits per pixel: "<<iheader.bmpInfoBitCount<<endl; 
	cout<<"+ Compression Type: "<<iheader.bmpInfoCompression<<endl;
	cout<<"+ Pixel Data: "<<iheader.bmpInfoSizeImage<<endl;
	cout<<"+ Prefered X Res: "<<iheader.bmpInfoXPelsPerMeter<<endl;
	cout<<"+ Prefered Y Res: "<<iheader.bmpInfoYPelsPerMeter<<endl;
	cout<<"+ Colour Map Entries in Use: "<<iheader.bmpInfoClrUsed<<endl;
	cout<<"+ Number of Significant Colours: "<<iheader.bmpInfoClrImportant<<endl;
}
void PrintbitInfo(BmpInfoHeader iheader)
{
	cout<<"==== PIXEL INFO ===="<<endl;
	cout<<endl;
	cout<<"+ Number of Pixels in Image: "<<iheader.bmpInfoWidth*iheader.bmpInfoHeight<<endl;
	cout<<"+ Number of Bits Storing Pixel Information: "<<iheader.bmpInfoWidth*iheader.bmpInfoHeight*iheader.bmpInfoBitCount<<endl;
	cout<<"+ Number of Pixel Bytes: "<<iheader.bmpInfoWidth*iheader.bmpInfoHeight*iheader.bmpInfoBitCount/8<<endl; 

}
bool DataCheck(BmpInfoHeader iheader, BmpHeader header)
{
    if ((iheader.bmpInfoWidth*iheader.bmpInfoHeight*iheader.bmpInfoBitCount/8 != iheader.bmpInfoSizeImage)
       | (iheader.bmpInfoSizeImage + iheader.bmpInfoSize + 14 != header.fileSize))
        return false; 
		else
        return true;
}


void PrintAddressArray(AddressArray BA, BmpInfoHeader iheader)
{ 
cout<<"==== MEMORY INFO ===="<<endl;
cout<<endl;


unsigned long int ROWS = 0; 
unsigned long int COLS = iheader.bmpInfoHeight;
while (ROWS < iheader.bmpInfoWidth+5) {
ROWS = ROWS + 4;}
uint32_t i = 0;
uint32_t j = COLS;
while (j >= 0) {
while (i <= ROWS) {


if (BA.Red[i]!=0) { //All MEMORY ADDRESSES MUST BE A MULTIPLE OF 4 padding bytes at the end of the rows(combined) to become multiple of 4.
std::cout << ( void * )&BA.Red[i]  << "   IS THE MEMORY ADDRESS"<<"   OF RED" << "    AT PIXEL"<< "   ROW:  "<< std::dec<<i << "   " << "   COLUMN:  " <<std::dec<<j<<'\t' 
                 <<"   Content: "<< std::hex << std::dec << ( void * )BA.Red[i]<< " "<<endl;}
if (BA.Green[i]!=0) {
std::cout << ( void * )&BA.Green[i]  << "   IS THE MEMORY ADDRESS"<<"   OF GREEN" << "  AT PIXEL"<< "   ROW:  " << std::dec<< i << "   " << "   COLUMN:  " << std::dec<<j<<'\t'
                <<"   Content: "<< std::hex << std::dec << ( void * )BA.Green[i]<< " "<<endl;}
if (BA.Blue[i]!=0) {
std::cout << ( void * )&BA.Blue[i]  << "   IS THE MEMORY ADDRESS"<<"   OF BLUE" << "   AT PIXEL"<< "   ROW:  " << std::dec<< i << "   " << "   COLUMN:  " << std::dec<<j<<'\t' 
                <<"   Content: " << std::hex << std::dec << ( void * )BA.Blue[i]<<" "<<endl;}
				i=i+1; }			
j=j-1;
i=0;
}
}
void PrintSpacingLine()
{
	cout<<endl;
}
int main()
{
    
    ifstream fin("8ry328ry.bmp", ios::binary);
    
    BmpSignature sig;
    BmpHeader hdr;
    BmpInfoHeader ihdr;
    AddressArray BA;
    DataCheck;
    ReadHeader(fin, sig, hdr);
    ReadInfoHeader(fin, ihdr);
    ReadPixelData(fin, hdr, ihdr, BA);
    if (DataCheck(ihdr, hdr) == false)
    cout<<"Data Incompatable"<<endl;
    if (DataCheck(ihdr, hdr) == false)
    return 0;
    else
    PrintSpacingLine();
    PrintHeader(sig, hdr);
    PrintSpacingLine();
    PrintSpacingLine();
    PrintBmpInfo(ihdr);
    PrintSpacingLine();
	PrintbitInfo(ihdr);
	PrintSpacingLine();
	PrintAddressArray(BA, ihdr);
    return 0;  

}
Last edited on
Do you realize that your definitions of AddressArray (all three of them) won't compile?
Flexible array members aren't supported in C++, and even if you're relying on some compiler extension, they must appear at the end of a non-empty structure anyways.

That stopped me short of helping you.
Last edited on
mbozzi wrote:
That stopped me short of helping you.

The guy is a pathetic braindead idiot.
As mbozzi has already told you, your code doesn't compile because it is not legal C++. Specifically, your lines 43 - 45 aren't legal.
KyleM24 wrote:
Think you's just work for the site don't know much code beside html, repost codes of others hide it from op and try convince people you's are intelligent and act like you've got mates. People are probably on to it though which is why you's still don't know how to code or even compile.

Be waiting 2 days for you to compile an answer, it's pointless.

First, thanks for the laugh! Second:

Your question lacks detail, and your posts so far have mostly been content-free. Instead of considering the criticism offered to you, you have consistently chosen to dismiss it entirely and now you've begun raving.

Your behaviour doesn't make any sense. You're not using your brain. Next time, if a post makes you upset, try to calm down before posting.

Fix your question or you won't get help.

@Kyle,
Please carefully read:
http://www.catb.org/esr/faqs/smart-questions.html
In particular,
http://www.catb.org/esr/faqs/smart-questions.html#answers
Last edited on
I'm on a forum for help with a code that compiles fine

As mbozzi has already explained to you, if your code compiles, it's because you're using a non-standard compiler extension. You're no longer writing standard C++, you're writing some obscure variant. At which point, the best advice I can give is that you read your compiler documentation, understand exactly how that extension works, and what impact it might be having on your problem.

Or, better yet, turn that extension off, and focus on writing - and learning - standard C++. It will set you in much better stead for continuing to program in the future.

And with that, I'm out. You seem more interested in having arguments than in actually understanding and learning C++, and I don't have any interest in arguing. Either take the advice and learn something, or don't. It's up to you.
Last edited on
Alas, there is no help for you.
mbozzi wrote:
Alas, there is no help for you.

Amen. Psychotic. Admits to beating sister. I've reported the other thread to the FBI (didn't know where else to report it).
closed account (E0p9LyTq)
He also admits to hacking the site, or wanting to do it.

So he can block others.

http://www.cplusplus.com/forum/lounge/238545/
Last edited on
I wonder who he'd want to block? :-)

And there's no reasoning with a psychotic. They live in their own little fantasy world. Here's one of my favorite psychotic interviews, although what's most interesting in this case is the dysphasia: https://youtu.be/kLGK-uB3h2M?t=660

My favorite response:
Doctor: How old are you now?
Patient: Same one. No one rhymes. Fly jumps around on a seat, but get it, you can't identify it. Man ahead of you. Forty-three.
closed account (E0p9LyTq)
I wonder who he'd want to block? :-)

Maybe his other personalities?
P.S Psy-op tech of need for approval ain't working here I'm not 6 y/o.

Lol, what does this mean?

Everyone is here is for completely voluntary reasons, tpb is not a troll (although he can be very blunt when stating an opinion). But tbh, this drama is one of my favorite parts of this site, I can't help but smile while reading it.

@tpb
PM me link to the sister post, I can't find it.
Last edited on
Pages: 12