-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEncode_Init.c
401 lines (328 loc) · 7.35 KB
/
Encode_Init.c
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
/*
** SPDX-License-Identifier: GPL-3.0-or-later
** Copyright (c) 2023-2024 Rene W. Olsen <[email protected]>
*/
// --
#include "RVNCd.h"
// --
static void mySetGeneric( struct Config *cfg, struct PixelMessage *msg )
{
int x;
int y;
/**/ if ( msg->pm_BitsPerPixel == 0 )
{
Log_PrintF( cfg, LOGTYPE_Error, "Unsupported Bits width (%ld)", msg->pm_BitsPerPixel );
goto bailout;
}
else if ( msg->pm_BitsPerPixel <= 8 )
{
cfg->GfxRead_Encode_RenderTile = TileRender_Generic_8;
}
else if ( msg->pm_BitsPerPixel <= 16 )
{
if ( msg->pm_BigEndian )
{
cfg->GfxRead_Encode_RenderTile = TileRender_Generic_16BE;
}
else
{
cfg->GfxRead_Encode_RenderTile = TileRender_Generic_16LE;
}
}
else if ( msg->pm_BitsPerPixel <= 24 )
{
Log_PrintF( cfg, LOGTYPE_Error, "Unsupported Bits width (%ld)", msg->pm_BitsPerPixel );
goto bailout;
}
else if ( msg->pm_BitsPerPixel <= 32 )
{
if ( msg->pm_BigEndian )
{
cfg->GfxRead_Encode_RenderTile = TileRender_Generic_32BE;
}
else
{
cfg->GfxRead_Encode_RenderTile = TileRender_Generic_32LE;
}
}
else
{
Log_PrintF( cfg, LOGTYPE_Error, "Unsupported Bits width (%ld)", msg->pm_BitsPerPixel );
goto bailout;
}
// --
cfg->GfxRead_Encode_FuncName = "Generic";
cfg->GfxRead_Encode_Format = PIXF_A8R8G8B8;
cfg->GfxRead_Encode_FormatSize = 4;
// --
x = 8;
y = 1;
while( y < msg->pm_RedMax )
{
y = y << 1;
x--;
}
cfg->GfxRead_Enocde_RedShift = x;
// --
x = 8;
y = 1;
while( y < msg->pm_GreenMax )
{
y = y << 1;
x--;
}
cfg->GfxRead_Enocde_GreenShift = x;
// --
x = 8;
y = 1;
while( y < msg->pm_BlueMax )
{
y = y << 1;
x--;
}
cfg->GfxRead_Enocde_BlueShift = x;
// --
bailout:
return;
}
// --
static void mySetEncoding_RGB888( struct Config *cfg, struct PixelMessage *msg UNUSED )
{
// IExec->DebugPrintF( "mySetEncoding_RGB888\n" );
// printf( "mySetEncoding_RGB888\n" );
cfg->GfxRead_Encode_FuncName = "Copy";
cfg->GfxRead_Encode_Format = PIXF_A8R8G8B8;
cfg->GfxRead_Encode_FormatSize = 4;
cfg->GfxRead_Encode_RenderTile = TileRender_Copy;
}
static void mySetEncoding_RGB888PC( struct Config *cfg, struct PixelMessage *msg UNUSED )
{
// IExec->DebugPrintF( "mySetEncoding_RGB888PC\n" );
// printf( "mySetEncoding_RGB888PC\n" );
cfg->GfxRead_Encode_FuncName = "Copy";
cfg->GfxRead_Encode_Format = PIXF_B8G8R8A8;
cfg->GfxRead_Encode_FormatSize = 4;
cfg->GfxRead_Encode_RenderTile = TileRender_Copy;
}
static void mySetEncoding_RGB565PC( struct Config *cfg, struct PixelMessage *msg UNUSED )
{
// IExec->DebugPrintF( "mySetEncoding_RGB565PC\n" );
// printf( "mySetEncoding_RGB565PC\n" );
cfg->GfxRead_Encode_FuncName = "Copy";
cfg->GfxRead_Encode_Format = PIXF_R5G6B5PC;
cfg->GfxRead_Encode_FormatSize = 2;
cfg->GfxRead_Encode_RenderTile = TileRender_Copy;
}
// --
struct myFormatClient
{
struct PixelMessage *Pixel;
void (*Function)( struct Config *cfg, struct PixelMessage *msg );
};
struct myFormatAmiga
{
int Format;
struct myFormatClient *Struct;
};
// --
static struct PixelMessage myRGB888 =
{
/* pm_Type */ 0,
/* pm_Pad */ 0,
/* pm_Pad2 */ 0,
/* pm_Pad3 */ 0,
/* pm_BitsPerPixel */ 32,
/* pm_Depth */ 24,
/* pm_BigEndian */ 1,
/* pm_TrueColor */ 1,
/* pm_RedMax */ 255,
/* pm_GreenMax */ 255,
/* pm_BlueMax */ 255,
/* pm_RedShift */ 16,
/* pm_GreenShift */ 8,
/* pm_BlueShift */ 0,
/* pm_Pad4 */ 0,
/* pm_Pad5 */ 0,
/* pm_Pad6 */ 0
};
static struct PixelMessage myRGB888PC =
{
/* pm_Type */ 0,
/* pm_Pad */ 0,
/* pm_Pad2 */ 0,
/* pm_Pad3 */ 0,
/* pm_BitsPerPixel */ 32,
/* pm_Depth */ 24,
/* pm_BigEndian */ 0,
/* pm_TrueColor */ 1,
/* pm_RedMax */ 255,
/* pm_GreenMax */ 255,
/* pm_BlueMax */ 255,
/* pm_RedShift */ 16,
/* pm_GreenShift */ 8,
/* pm_BlueShift */ 0,
/* pm_Pad4 */ 0,
/* pm_Pad5 */ 0,
/* pm_Pad6 */ 0
};
static struct PixelMessage myRGB565PC =
{
/* pm_Type */ 0,
/* pm_Pad */ 0,
/* pm_Pad2 */ 0,
/* pm_Pad3 */ 0,
/* pm_BitsPerPixel */ 16,
/* pm_Depth */ 16,
/* pm_BigEndian */ 0,
/* pm_TrueColor */ 1,
/* pm_RedMax */ 31,
/* pm_GreenMax */ 63,
/* pm_BlueMax */ 31,
/* pm_RedShift */ 11,
/* pm_GreenShift */ 5,
/* pm_BlueShift */ 0,
/* pm_Pad4 */ 0,
/* pm_Pad5 */ 0,
/* pm_Pad6 */ 0
};
// -- Screen is 32Bit ARGB -> xx
// -- Any Optimization ? or fallback to Generic
static struct myFormatClient my_A8R8G8B8[] =
{
{ & myRGB888, mySetEncoding_RGB888 },
{ & myRGB888PC, mySetEncoding_RGB888PC },
{ NULL, mySetGeneric }
};
// -- Screen is 16Bit PC -> xx
// -- Any Optimization ? or fallback to Generic
static struct myFormatClient my_R5G6B5PC[] =
{
{ & myRGB565PC, mySetEncoding_RGB565PC },
{ NULL, mySetGeneric }
};
// -- Amiga ScreenModes
// -- Screen modes with some Optimization
static struct myFormatAmiga my_Modes[] =
{
{ PIXF_A8R8G8B8, my_A8R8G8B8 },
{ PIXF_R5G6B5PC, my_R5G6B5PC },
{ 0, NULL }
};
// --
void mySetEncoding_Message( struct Config *cfg, struct PixelMessage *msg, int User )
{
struct myFormatClient *format;
struct CommandPxlFmt *pfmsg;
int pos;
//printf( "\n\n-- Set Encoding\n\n\n" );
// --
if ( User )
{
cfg->GfxRead_Enocde_ActivePixelSet = TRUE;
}
// printf( "Setting GfxRead_Enocde_ActivePixel 22\n" );
memcpy( & cfg->GfxRead_Enocde_ActivePixel, msg, sizeof( struct PixelMessage ));
cfg->GfxRead_Enocde_ActivePixelID++;
// -- Update GUI
pfmsg = myCalloc( sizeof( struct CommandPxlFmt ) );
if ( pfmsg )
{
pfmsg->cpf_Command = CMD_PxlFmt;
pfmsg->cpf_Format = *msg;
pfmsg->cpf_Client = TRUE;
// --
IExec->PutMsg( CmdMsgPort, & pfmsg->cpf_Message );
}
// --
pos = 0;
while( my_Modes[pos].Format )
{
if ( my_Modes[pos].Format == cfg->GfxRead_Screen_Format )
{
break;
}
else
{
pos++;
}
}
if ( ! my_Modes[pos].Format )
{
// No optimized functions, using fallback
mySetGeneric( cfg, msg );
}
else
{
format = my_Modes[pos].Struct;
pos = 0;
while( format[pos].Pixel )
{
if ( ! memcmp( format[pos].Pixel, msg, sizeof( struct PixelMessage )))
{
break;
}
else
{
pos++;
}
}
format[pos].Function( cfg, msg );
}
// --
IExec->ObtainSemaphore( & cfg->GfxRead_Screen_Sema );
if ( cfg->GfxRead_Screen_ChunkyBuffer )
{
if ( cfg->GfxRead_Encode_OldFormat != cfg->GfxRead_Encode_Format )
{
// Clear Screen
memset( cfg->GfxRead_Screen_ChunkyBuffer, 0, cfg->GfxRead_Screen_ChunkySize );
// Only Send update when GfxRead have read it again
memset( cfg->GfxRead_Screen_TileArrayBuffer, 0, cfg->GfxRead_Screen_Tiles );
}
else
{
// Force a resend updates
memset( cfg->GfxRead_Screen_TileArrayBuffer, 0x80, cfg->GfxRead_Screen_Tiles );
}
}
cfg->GfxRead_Encode_OldFormat = cfg->GfxRead_Encode_Format;
IExec->ReleaseSemaphore( & cfg->GfxRead_Screen_Sema );
// --
}
// --
void mySetEncoding_Format( struct Config *cfg, int Format )
{
// This Stops Reading from Screen
cfg->GfxRead_Encode_Format = 0;
cfg->GfxRead_Encode_FormatSize = 0;
cfg->GfxRead_Encode_RenderTile = NULL;
if ( cfg->GfxRead_Enocde_ActivePixelSet )
{
mySetEncoding_Message( cfg, & cfg->GfxRead_Enocde_ActivePixel, FALSE );
}
else
{
switch( Format )
{
case PIXF_A8R8G8B8:
{
mySetEncoding_Message( cfg, & myRGB888, FALSE );
break;
}
case PIXF_R5G6B5PC:
{
mySetEncoding_Message( cfg, & myRGB565PC, FALSE );
break;
}
default:
{
if ( Format )
{
Log_PrintF( cfg, LOGTYPE_Error, "Unsupported Amiga Pixel Format : %ld", Format );
}
break;
}
}
}
}
// --