Problem byte in program.

I will try to explain how my program works and what the issue is.
I am loading tile data from a file which uses intertwined bitplanes in 4bpp.
The code sorta works. But whenever the program encounters the value of 0x1a it stops working. However if I change this problem byte to something else the program works but now the tiles are 1pixel off.

I thought the bitmap function I was using was the problem so I tried png instead.
encounters the same issue.

Sorry the code was to long to post...
source here
https://www.mediafire.com/file/bzq1n2nk5dytecu/main.cpp/file

Does my computer have a corrupted file or something?

Here is a code snippet whit checks which bit is set.

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
for (int p = 0; p < 8; p++) // Bottom Left Tile
        {
            if (p == 7) { c = 512; }
            if (p == 6) { c = 576; }
            if (p == 5) { c = 640; }
            if (p == 4) { c = 704; }
            if (p == 3) { c = 768; }
            if (p == 2) { c = 832; }
            if (p == 1) { c = 896; }
            if (p == 0) { c = 960; }

            for (int j = 0, N = 7; j < 8; j++, N--)
            {
                std::bitset<4> bs;
                bs.set(0, (Bitplane0_Bottom_Left_ROW[p] >> N) & 1);
                bs.set(1, (Bitplane1_Bottom_Left_ROW[p] >> N) & 1);
                bs.set(2, (Bitplane2_Bottom_Left_ROW[p] >> N) & 1);
                bs.set(3, (Bitplane3_Bottom_Left_ROW[p] >> N) & 1);
                unsigned long Index = bs.to_ulong();




                image[c++] = colours[Index][0]; // Red
                image[c++] = colours[Index][1]; // Green
                image[c++] = colours[Index][2]; // Blue 
                image[c++] = colours[Index][3]; // Alpha
            }

        }





I came across this.
https://www.ascii-code.com/character/%E2%90%9A


In DOS, Windows, CP/M, and derivatives of Digital Equipment Corporation operating systems, it is used to indicate the end of file, both when typing on the terminal, and sometimes in text files stored on disk.



OK I SOLVED THE ISSUE!
That 0x1a substitute character treated it like an end of file/halt

I had to open a stream in binary mode. like this
is.open ("C:\\Final.png", ios::binary );



Last edited on
Re L3-10 - It's easier to use a look-up table.
Topic archived. No new replies allowed.