GrafX2 2.9.3227
The ultimate 256-color painting program
Amstrad CPC/CPC+ picture formats

Support for Amstrad CPC/CPC+ picture formats. More...

+ Collaboration diagram for Amstrad CPC/CPC+ picture formats:

Data Structures

struct  sgx_data
 Structure for current information about loading SGX file. More...
 

Typedefs

typedef int(* Read_SGX_Callback) (struct sgx_data *, word, word, word, word, word, byte)
 Callback function for Read_SGX() More...
 

Functions

void Test_SGX (T_IO_Context *context, FILE *file)
 Test for SGX file (SymbOS) More...
 
static void Set_SGX_Palette (T_IO_Context *context)
 
static int Read_SGX (struct sgx_data *data, Read_SGX_Callback cb)
 Read a SGX file structure. More...
 
int SGX_Get_dimensions (struct sgx_data *data, word posx, word posy, word width, word height, word byte_width, byte ncolors)
 Only skip bytes. More...
 
int SGX_Load_Picture (struct sgx_data *data, word posx, word posy, word width, word height, word byte_width, byte ncolors)
 Set the pixels. More...
 
void Load_SGX (T_IO_Context *context)
 
static int Save_SGX_Sub (T_IO_Context *context, FILE *file, word n_colors)
 Write SGX file format as specified here : http://www.cpcwiki.eu/index.php/Format:SGX_(SymbOS_graphic_files) More...
 
void Save_SGX (T_IO_Context *context)
 
void Test_SCR (T_IO_Context *context, FILE *file)
 Test for SCR file (Amstrad CPC) More...
 
static int Depack_CPC_LZW (byte *dst, FILE *file)
 Unpack LZ streams from CPCconvImg v0.x (Demoniak/iMPACT!) More...
 
void Load_SCR (T_IO_Context *context)
 Load Advanced OCP Art Studio files (Amstrad CPC) More...
 
void Save_SCR (T_IO_Context *context)
 Save Amstrad SCR file. More...
 
void Test_GOS (T_IO_Context *context, FILE *file)
 Test for GO1/GO2/KIT - Amstrad Plus Graphos. More...
 
void Load_GOS (T_IO_Context *context)
 Load GO1/GO2/KIT - Amstrad CPC Plus Graphos. More...
 
void Save_GOS (T_IO_Context *context)
 
void Test_CM5 (T_IO_Context *context, FILE *file)
 Test for CM5 - Amstrad CPC "Mode 5" picture. More...
 
void Load_CM5 (T_IO_Context *context)
 Load Amstrad CPC "Mode 5" picture. More...
 
void Save_CM5 (T_IO_Context *context)
 Save a CPC Mode 5 picture. More...
 
void Test_PPH (T_IO_Context *context, FILE *file)
 Amstrad CPC 'PPH' for Perfect Pix. More...
 
static uint8_t pph_blend (uint8_t a, uint8_t b)
 
void Load_PPH (T_IO_Context *context)
 
void Save_PPH (T_IO_Context *context)
 Not yet implemented. More...
 

Detailed Description

Support for Amstrad CPC/CPC+ picture formats.

The Amstrad CPC has 3 video modes :

Supported formats :

Typedef Documentation

◆ Read_SGX_Callback

typedef int(* Read_SGX_Callback) (struct sgx_data *, word, word, word, word, word, byte)

Callback function for Read_SGX()

Function Documentation

◆ Test_SGX()

void Test_SGX ( T_IO_Context context,
FILE *  file 
)

◆ Set_SGX_Palette()

static void Set_SGX_Palette ( T_IO_Context context)
static

◆ Read_SGX()

static int Read_SGX ( struct sgx_data data,
Read_SGX_Callback  cb 
)
static

Read a SGX file structure.

Returns
0 for error

References sgx_data::file, GFX2_DEBUG, GFX2_Log(), GFX2_WARNING, sgx_data::height, MAX, sgx_data::ncolors, Read_byte(), Read_word_le(), and sgx_data::width.

Referenced by Load_SGX().

◆ SGX_Get_dimensions()

int SGX_Get_dimensions ( struct sgx_data data,
word  posx,
word  posy,
word  width,
word  height,
word  byte_width,
byte  ncolors 
)

Only skip bytes.

References sgx_data::file, sgx_data::height, sgx_data::ncolors, and sgx_data::width.

Referenced by Load_SGX().

◆ SGX_Load_Picture()

int SGX_Load_Picture ( struct sgx_data data,
word  posx,
word  posy,
word  width,
word  height,
word  byte_width,
byte  ncolors 
)

Set the pixels.

Returns
0 in case of error

References sgx_data::context, sgx_data::file, sgx_data::height, sgx_data::ncolors, Read_byte(), Set_pixel(), and sgx_data::width.

Referenced by Load_SGX().

◆ Load_SGX()

◆ Save_SGX_Sub()

static int Save_SGX_Sub ( T_IO_Context context,
FILE *  file,
word  n_colors 
)
static

Write SGX file format as specified here : http://www.cpcwiki.eu/index.php/Format:SGX_(SymbOS_graphic_files)

We are using only simple chunks for 4 colors pictures. Chunk dimentions are limited to the ones of simple chunks (252x255), we could go up to 508x65535 with extended chunks.

Returns
0 for error

References sgx_data::context, sgx_data::file, Get_pixel(), GFX2_DEBUG, GFX2_Log(), sgx_data::height, T_IO_Context::Height, MIN, sgx_data::width, T_IO_Context::Width, Write_byte(), and Write_word_le().

Referenced by Save_SGX().

◆ Save_SGX()

◆ Test_SCR()

void Test_SCR ( T_IO_Context context,
FILE *  file 
)

Test for SCR file (Amstrad CPC)

SCR file format is originally from "Advanced OCP Art Studio" : http://www.cpcwiki.eu/index.php/Format:Advanced_OCP_Art_Studio_File_Formats

.WIN "window" format is also supported.

SCR files are normally just a dump of the 16K of video memory. So they are essentially 16 kilobytes of pixel data without any header. To make things more fun, there is an optional compression. This all makes detection a bit fuzzy. However there are various things we can still check:

  • Presence of a valid PAL file. If the PAL file is not there the pixel data may still be valid. The PAL file size depends on the screen mode (number of colors).
  • An AMSDOS header is a good indication but in some cases it may not be there.
  • Some tools embed the palette and mode (and usually some kind of loader code) in the SCR file, we can also detect these.
Todo:
the palette data can be hidden in the 48 "empty" bytes every 2048 bytes of a standard resolution SCR file. So we should detect the hidden Z80 code and load them. Load address of file is C000. Z80 code :
C7D0: 3a d0 d7 cd 1c bd 21 d1 d7 46 48 cd 38 bc af 21 | :.....!..FH.8..!
C7E0: d1 d7 46 48 f5 e5 cd 32 bc e1 f1 23 3c fe 10 20 | ..FH...2...#<..
C7F0: f1 c3 18 bb 00 00 00 00 00 00 00 00 00 00 00 00 | ................
mode and palette :
D7D0: 00 1a 00 0c 03 0b 01 0d 17 10 02 0f 09 19 06 00 | ................
https://gitlab.com/GrafX2/grafX2/merge_requests/121#note_119964168

References sgx_data::context, CPC_check_AMSDOS(), sgx_data::file, File_error, File_length_file(), sgx_data::file_size, GFX2_DEBUG, GFX2_Log(), GFX2_LogHexDump(), mode, NULL, Open_file_read_with_alternate_ext(), Read_byte(), and Read_bytes().

◆ Depack_CPC_LZW()

static int Depack_CPC_LZW ( byte dst,
FILE *  file 
)
static

Unpack LZ streams from CPCconvImg v0.x (Demoniak/iMPACT!)

Parameters
dstdestination buffer
fileinput
Returns
unpacked length or -1 for error

References sgx_data::file, and Read_byte().

Referenced by Load_SCR().

◆ Load_SCR()

void Load_SCR ( T_IO_Context context)

◆ Save_SCR()

void Save_SCR ( T_IO_Context context)

Save Amstrad SCR file.

guess mode from aspect ratio :

  • normal pixels are mode 1
  • wide pixels are mode 0
  • tall pixels are mode 2

Mode and palette are stored in a .PAL file for compatibility with OCP Art studio.

The picture color index should be 0-15, The CPC Hardware palette is expected to be set (indexes 64 to 95)

If the picture is using overscan (more than 16384 bytes) we produce a iMPdraw v2 format autoloading file. see http://orgams.wikidot.com/le-format-impdraw-v2

If the picture is not using overscan (standard resolutions, < 16384 screen buffer) a BASIC loader is saved.

Todo:

Add possibility to set R9 value

Add OCP packing support

References sgx_data::context, CPC_compare_colors(), CPC_is_CPC_old_color(), cpc_scr_simple_loader, CPC_set_HW_palette(), CPC_write_AMSDOS_header(), sgx_data::file, File_error, T_IO_Context::File_name, GFX2_DEBUG, GFX2_Log(), GFX2_WARNING, T_IO_Context::Height, impdraw_loader, NULL, Open_file_write(), Open_file_write_with_alternate_ext(), T_IO_Context::Palette, PIXEL_TALL, PIXEL_TALL2, PIXEL_TALL3, PIXEL_WIDE, PIXEL_WIDE2, T_IO_Context::Ratio, raw2crtc(), T_IO_Context::Width, Write_byte(), and Write_bytes().

◆ Test_GOS()

void Test_GOS ( T_IO_Context context,
FILE *  file 
)

Test for GO1/GO2/KIT - Amstrad Plus Graphos.

This format is made of 3 files .KIT hold the palette in "Kit4096" format. There are 16 colors each stored as 12 bit RGB in RB0G order. .GO1 and GO2 hold each half of the picture (top and bottom) The file always cover the whole display of the Plus (192*272 mode 0 pixels) Only mode 0 is possible.

References sgx_data::context, CPC_check_AMSDOS(), sgx_data::file, File_error, File_length_file(), sgx_data::file_size, NULL, and Open_file_read_with_alternate_ext().

◆ Load_GOS()

◆ Save_GOS()

◆ Test_CM5()

void Test_CM5 ( T_IO_Context context,
FILE *  file 
)

Test for CM5 - Amstrad CPC "Mode 5" picture.

This is a format designed by SyX. There is one .GFX file in the usual amstrad format and a .CM5 file with the palette, which varies over time.

CM5 file is 2049 bytes, GFX is 18432 bytes.

Todo:
check CM5 contains only valid values [0x40-0x5f]

References sgx_data::context, CPC_check_AMSDOS(), sgx_data::file, File_error, File_length_file(), sgx_data::file_size, NULL, and Open_file_read_with_alternate_ext().

◆ Load_CM5()

◆ Save_CM5()

void Save_CM5 ( T_IO_Context context)

Save a CPC Mode 5 picture.

Resolution is fixed to 288x256. The pictures uses 5 layers. 4 for defining the "inks" the 5th to select one of the 4 inks.

  • Layer 1 : 1 color Only
  • Layer 2 and 3 : 1 color/line
  • Layer 4 : 1 color / 48x1 block
  • Layer 5 : CPC mode 2 288x256 picture.

The .CM5 file contains the inks from layers 1-4, the .GFX file contains the pixel data in linear fashion

Todo:

Check picture has 5 layers

Check the constraints on the layers

See also
https://www.cpc-power.com/index.php?page=detail&num=12905

References sgx_data::context, sgx_data::file, File_error, Get_pixel(), Open_file_write(), Open_file_write_with_alternate_ext(), Set_saving_layer(), and Write_byte().

◆ Test_PPH()

void Test_PPH ( T_IO_Context context,
FILE *  file 
)

Amstrad CPC 'PPH' for Perfect Pix.

This is a format designed by Rhino. There are 3 modes:

  • Mode 'R': 1:1 pixels, 16 colors from the CPC 27 color palette. (this is implemented on CPC as two pictures with wide pixels, the "odd" one being shifted half a pixel to the right), and flipping)
  • Mode 'B0': wide pixels, up to 126 out of 378 colors. (this is implemented as two pictures with wide pixels, sharing the same 16 color palette, and flipping)
  • Mode 'B1': 1:1 pixels, 1 fixed color, up to 34 palettes of 9 colors (actually 4 colors + flipping)
  • The standard CPC formats can also be encapsulated into a PPH file.
See also
http://www.pouet.net/prod.php?which=67770#c766959

References sgx_data::context, sgx_data::file, File_error, File_length_file(), sgx_data::file_size, NULL, Open_file_read_with_alternate_ext(), and Read_bytes().

◆ pph_blend()

static uint8_t pph_blend ( uint8_t  a,
uint8_t  b 
)
static

Referenced by Load_PPH().

◆ Load_PPH()

◆ Save_PPH()

void Save_PPH ( T_IO_Context context)

Not yet implemented.

References sgx_data::context.