-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathneo.cpp
130 lines (110 loc) · 4.12 KB
/
neo.cpp
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
/* Copyright (C) 2023 Magnus Grander - All Rights Reserved
* You may use, distribute and modify this code under the
* terms of the BSD license.
*
* You should have received a copy of the BSD license with
* this file.
*/
#include "neo.h"
void SaveScreenshot()
{
const Uint32 format = SDL_PIXELFORMAT_ARGB8888;
SDL_Surface *surface = SDL_CreateRGBSurfaceWithFormat(0, 320, 200, 32, format);
SDL_RenderReadPixels(renderer, NULL, format, surface->pixels, surface->pitch);
SDL_SaveBMP(surface, "screenshot.bmp");
SDL_FreeSurface(surface);
}
int main(int argc, char* argv[] )
{
int iFileHandle;
bool bLoadOk;
int iLoadSize;
unsigned char bNeoPic[32768];
int R[16];
int G[16];
int B[16];
int iN;
int iPtr, iInk;
int iR, iG, iB;
int iX, iY, iZ;
unsigned int uW0, uW1, uW2, uW3;
unsigned int uBit;
bool quit = false;
int i;
if (argc != 2) {
fprintf (stderr, "wrong number of arguments!\n");
fprintf (stderr, "Usage: neo filename.neo\n");
exit (1);
}
SDL_Init(SDL_INIT_VIDEO);
SDL_CreateWindowAndRenderer(320, 200, 0, &window, &renderer);
FILE * filp = fopen(argv[1], "rb");
iLoadSize = fread(bNeoPic, sizeof(char), 32768, filp);
if (iLoadSize == 32128)
{
bLoadOk = true;
// Skip two words (Flag byte=0, assume resolution=0)
// Extract the palette from the next 16 words, and
// convert into a temporary array of TColor:
for (iN=0; iN<16; ++iN)
{
iR = floor((bNeoPic[iN*2 + 4] & 0x07) * 255.0 / 7.0);
iG = floor((bNeoPic[iN*2 + 5] & 0x70) * 255.0 / 7.0 / 16.0);
iB = floor((bNeoPic[iN*2 + 5] & 0x07) * 255.0 / 7.0);
//colNeoPalette[iN] = TColor(RGB(iR, iG, iB));
R[iN] = iR;
G[iN] = iG;
B[iN] = iB;
}
// Address pointer, past 128b header:
iPtr = 128;
// 200 rows of image:
for (iY=0; iY<200; ++iY)
{
// 20 column blocks:
for (iX=0; iX<20; ++iX)
{
// Fetch the 4 words that make up the
// next 16 pixels across 4 bitplanes:
uW0 = bNeoPic[iPtr+0] * 256 + bNeoPic[iPtr+1];
uW1 = bNeoPic[iPtr+2] * 256 + bNeoPic[iPtr+3];
uW2 = bNeoPic[iPtr+4] * 256 + bNeoPic[iPtr+5];
uW3 = bNeoPic[iPtr+6] * 256 + bNeoPic[iPtr+7];
// The first pixel is found in the highest bit:
uBit = 0x8000;
// 16 pixels to process:
for (iZ=0; iZ<16; ++iZ)
{
// Work out the colour index:
iInk = 0;
if (uW0 & uBit) iInk += 1;
if (uW1 & uBit) iInk += 2;
if (uW2 & uBit) iInk += 4;
if (uW3 & uBit) iInk += 8;
// Plot a pixel of that Tcolor:
SDL_SetRenderDrawColor(renderer, R[iInk], G[iInk], B[iInk], 255);
SDL_RenderDrawPoint(renderer, iX*16 + iZ, iY );
SDL_RenderPresent(renderer);
//imgPic->Canvas->Pixels[iX*16 + iZ][iY] = colNeoPalette[iInk];
uBit >>= 1;
}
iPtr += 8;
}
}
}
while (!quit)
{
SDL_WaitEvent(&event);
switch (event.type)
{
case SDL_QUIT:
quit = true;
break;
}
}
SaveScreenshot();
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
return EXIT_SUCCESS;
}