Commit 182c9f8d authored by Robert Sprowson's avatar Robert Sprowson Committed by ROOL
Browse files

Fix loading palettes to all new & 256 colour old sprites

A check (marked DF-300) rejected any attempt to load a palette into a new (ie. RISC OS 3.50+) style sprite. This is bogus because bbc_modevar() is perfectly happy to process a sprite mode word and return Log2bpp, which is all that was required. Confirmed on RISC OS 3.50 with
  SYS"OS_ReadModeVariable",&202D0169,9 TO,,log2bpp
which gives 3 for a 256 colour 180dpi sprite.
Ref: https://www.riscosopen.org//forum/forums/4/topics/14966

Second, a logic error introduced in Paint-2_26 meant that loading from a file any 256 entry palette (old or new sprite) would result in the palette being reset to the kernel default. This is because there are 2 callers of menus_set_palette() with non-NULL palette pointers, but only 1 wants a default palette. Signal this case by passing -256 entries.

Version 2.31. Tagged as 'Paint-2_31'
parent bdc9c4ae
......@@ -9,12 +9,12 @@
GBLS Module_ApplicationDate
GBLS Module_HelpVersion
GBLS Module_ComponentName
Module_MajorVersion SETS "2.30"
Module_Version SETA 230
Module_MajorVersion SETS "2.31"
Module_Version SETA 231
Module_MinorVersion SETS ""
Module_Date SETS "28 Dec 2019"
Module_ApplicationDate SETS "28-Dec-19"
Module_Date SETS "29 Feb 2020"
Module_ApplicationDate SETS "29-Feb-20"
Module_ComponentName SETS "Paint"
Module_FullVersion SETS "2.30"
Module_HelpVersion SETS "2.30 (28 Dec 2019)"
Module_FullVersion SETS "2.31"
Module_HelpVersion SETS "2.31 (29 Feb 2020)"
END
/* (2.30)
/* (2.31)
*
* This file is automatically maintained by srccommit, do not edit manually.
*
*/
#define Module_MajorVersion_CMHG 2.30
#define Module_MajorVersion_CMHG 2.31
#define Module_MinorVersion_CMHG
#define Module_Date_CMHG 28 Dec 2019
#define Module_Date_CMHG 29 Feb 2020
#define Module_MajorVersion "2.30"
#define Module_Version 230
#define Module_MajorVersion "2.31"
#define Module_Version 231
#define Module_MinorVersion ""
#define Module_Date "28 Dec 2019"
#define Module_Date "29 Feb 2020"
#define Module_ApplicationDate "28-Dec-19"
#define Module_ApplicationDate "29-Feb-20"
#define Module_ComponentName "Paint"
#define Module_FullVersion "2.30"
#define Module_HelpVersion "2.30 (28 Dec 2019)"
#define Module_LibraryVersionInfo "2:30"
#define Module_FullVersion "2.31"
#define Module_HelpVersion "2.31 (29 Feb 2020)"
#define Module_LibraryVersionInfo "2:31"
......@@ -1471,13 +1471,12 @@ void menus_set_palette (main_sprite *sprite, int entries, int *palette)
int old_size, new_size, diff;
sprite_area **sarea = &sprite->file->spritearea;
sprite_header *header;
os_error *error;
ftracef1 ("%s palette\n", create? "Create": "Delete");
header = psprite_address (sprite);
old_size = MIN (header->image, header->mask) - sizeof (sprite_header);
new_size = create? 2*sizeof (int)*entries: 0;
new_size = create ?2 * sizeof (int) * abs(entries): 0;
diff = new_size - old_size;
ftracef3 ("Sprite \"%.12s\" had %d bytes of palette; wants %d bytes\n",
......@@ -1493,15 +1492,18 @@ void menus_set_palette (main_sprite *sprite, int entries, int *palette)
header = psprite_address (sprite); /*flex moved?*/
if (create && entries == 256)
{ if ((error = os_swix4 (OS_SpriteOp, 37 | 0x200 /*create/remove palette*/,
(int) *sarea, (int) header, 1 /*create*/ | (1U << 31))) != NULL)
if (create && entries == -256)
{ /* Special handling to create a full 256 entry */
os_error *error = os_swix4 (OS_SpriteOp, SpriteReason_CreateRemovePalette | 0x200,
(int) *sarea, (int) header, 1 /*create*/ | (1U << 31));
if (error != NULL)
{ werr (FALSE, error->errmess);
return;
}
}
else
{ start = (char *) header + MIN (header->image, header->mask);
{ /* Generic add/remove */
start = (char *) header + MIN (header->image, header->mask);
end = (char *) *sarea + (*sarea)->freeoff /*end of whole area*/;
memmove (start + diff, start, end - start);
......@@ -2048,7 +2050,7 @@ void menus_sprite_handler (void *handle, char *hit)
case s_Paint_Edit_Pal:
if (hit [2])
{ wimp_eventstr ev = {0}, *ev2;
{ wimp_eventstr ev = { wimp_ENULL }, *ev2;
int mx = 0, my = 0;
BOOL couldRemap = main_current_options.advanced.artist_friendly
&& main_current_options.advanced.remap_palette
......@@ -2349,7 +2351,7 @@ void menus_sprite_handler (void *handle, char *hit)
bbc_modevar (SpriteType_New32bpp << 27 | 1, bbc_Log2BPP) != -1)
{ /*It's a 256 colour sprite on a Risc PC or later,
so we'll add a full, 256 entry palette.*/
entries = 256;
entries = -256;
}
else
{ /*Otherwise stick with the historic behaviour*/
......
......@@ -1251,7 +1251,7 @@ void sprwindow_event_handler (wimp_eventstr *e, void *handle)
ftracef0 ("Read palette\n");
}
else if (check_palette_type (xferrecv_checkimport (&size), NULL))
{ size = xferrecv_doimport (palfile, 6*256 + 1,
{ size = xferrecv_doimport (palfile, sizeof(palfile),
&cant_extend_stack_buffer);
ftracef1 ("Imported %d byte palette\n", size);
}
......@@ -1287,12 +1287,6 @@ void sprwindow_event_handler (wimp_eventstr *e, void *handle)
}
if (entries == 0) break;
/*Fix DF-300: check not a new format sprite.*/
if ((unsigned) mode >= 256u)
{ werr (FALSE, msgs_lookup ("PntE1"));
break;
}
ftracef1 ("that means we need a sprite with %d colours\n", entries);
if (entries != 1 << (1 << bbc_modevar (mode, bbc_Log2BPP)))
{ werr (FALSE, msgs_lookup ("PntE1"));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment