Log In  
Follow
Cutievirus
[ :: Read More :: ]

Cart #pngframe-3 | 2024-04-08 | Embed ▽ | License: CC4-BY-NC-SA
22

Import PNG images and generate optimal palette

Can import png to fit picotron default palette, custom palette imported through hex file, or custom palette generated for the png file.

For best results, reduce the png to 64 or fewer colors in an external program such as gimp. This isn't required, but will save you some time waiting for the palette to generate and will allow you to use dithering.

If the imported png has less than the "max colors" value and is set to generate palette, the generation step can be used and the image's colors can be used as-is.

The generated palette is also sorted to attempt to fit the current palette. Colors in the generated palette are moved to the location of similar colors on the loaded palette. For example, black will attempt to stay black, and white will attempt to stay white.

If generate palette is turned off, the image will be made to fit the current palette (either picotron's default palette or an imported hex palette)

Lab color space can be selected for more accurate color matching, but increases generation time. The selected color space affects both palette generation and color sorting.

After generating you can save the image as a userdata pod. The generated palette is attached as metadata so the image can be opened in Paint with the correct palette.

See also pancelor's unrelated but similar cart, import png

Update 1.1

Added seed field so the generated palette can be deterministic
Added ability to import pal files exported from OkPal

Update 1.2

Added "palette format" option to choose whether the palette in the metadata will be in hex format (text) or pal format (userdata).
Added "keep colors" field. Specify a number of colors that will be left unchanged when generating the palette. If set to 32, the generated palette will occupy only the second half of the palette
Added ability to re-open previously saved images (pod files)
Added ability to save and open gfx files, and to save pal and hex files.
Improved color sorting
Added ability to copy generated image with ctrl+c, it can be pasted into the gfx editor

P#145217 2024-03-31 06:38 ( Edited 2024-04-08 03:34)

[ :: Read More :: ]

Cart #colorspace_generator-0 | 2024-03-24 | Embed ▽ | License: CC4-BY-NC-SA
3

Generates a colorspace graphic for the currently loaded palette, and generates colortables for precomputed color blending based on that colorspace.

Supports palettes in hex format. Just drop the palette onto the window to load it before generating the colorspace.
The colorspace is just a gfx file, so it can be opened in picotron's gfx editor.

There are four export modes:

  • Colorspace + Tables - exports the colorspace gfx with all of the currently generated color tables embedded. Saves you from having to generate the tables at runtime, but is the most expensive option for cart space.

  • Colospace - exports the generated colorspace. Does not include any color tables, so they need to be generated at runtime or loaded separately.

  • Color Tables - exports a list of the currently generated color tables. Tables that haven't been generated yet won't be included, so you need to move the slider at the bottom of the screen to make them generate.

  • Color Table - exports only the color table for the currently selected alpha level. Color tables are stored as userdata.

The default export location is /ram/cart/

To use the data exported from this cart, you can copy the colorspace.lua file into your own cart. It contains utilities for loading and working with the colorspace data.

The usage will vary depending on if you exported the colorspace or color tables.

Working with the colorspace:

The colorspace file can be loaded with Colorspace.fetch

colorspace = Colorspace.fetch("colorspace.gfx")

If you provided a paltte for the colorspace, it has been embedded inside the colorspace file for your convenience and can be loaded with colorspace:load_palette()

You can use colorspace:get_colortable to load a color table from the colorspace object. If it doesn't exist yet it will be generated. The color space object saves a reference to the table to avoid needing to re-generate it next time it's requested.

colortable = colorspace:get_colortable(0.5)

Now that you have the color table, you need to actually apply it into memory.

colortable_index=0
colorspace:apply_colortable(colortable,colortable_index)

The second parameter here is the color table index, and can be table 0, 1, 2, or 3.

If you apply the color table to table 0, then anything your draw should appear to be blended based on that table's alpha value.
*Except if you're drawing using shapes. Shapes have their default target mask set to 0x00, but it needs to be set to 0x3f for color blending to work properly.

poke(0x550b,0x3f) --set target mask for shapes to 0x3f

There's also another utility method to get the color table and apply it in one step

colorspace:set_alpha(0.5,colortable_index)

For both apply_colortable and set_alpha, if colortable_index is omitted it will default to color table 0.

There are also functions for working with the colorspace directly without color tables

colorspace:get_color takes a red green and blue argument (numbers from 0 to 255) and returns the color index that most closely matches that color. Because it reads it off the colorspace graphic, it's actually rather quick.

c=colorspace:get_color(r,g,b)

colorspace:mix_colors takes two color indexes and an alpha value, mixes them together based on the alpha, and returns the nearest color to the result.

alpha=0.5
c3=colorspace:mix_colors(c1,c2,alpha)

Working with Color Tables

If you exported your color tables individually, you can get them with fetch

colortable = fetch("colortable.pod")

If you exported a list of color tables, they are indexed based on the alpha value.

colortables = fetch("colortables.pod")
colortable = colortables[0.5]

To apply your color table, there is a function at the top of colorspace.lua you can use.

table_index=0
apply_colortable(colortable,table_index)

As before, table_index is 0 if omitted.

That's it! Now your color table is loaded and anything you draw will be alpha blended.
*Unless you're using shapes in which case you need to make sure the target mask is set to 0x3f

Drawing with the other color tables

If you don't want write to color table zero, there are a few more steps to draw with color blending.
Let's say you applied your color table to color table 2.

apply_colortable(colortable,2)

I have two more utility functions which will let you draw using data from the other color tables.

shape_colortable sets the color table to be used when drawing shapes. it also sets the appropriate masks to allow color blending to work with shapes. Call it without arguments to set everything back to normal.

shape_colortable(2)

spr_colortable sets the color table to be used when drawing sprites. This one can only use color tables 0 or 2. It uses fillp internally with a solid fill pattern.

spr_colortable(2)

Here are the loose utility functions if you don't want to have to pull them out of colorspace.lua

function apply_colortable(data,table_number)
    table_number = table_number or 0
    local address = 0x8000+4096*table_number
    memmap(address,data:copy())
end

function shape_colortable(table_index)
    if table_index==nil then
        poke(0x5508,0x3f)--read mask
        poke(0x550b,0x00)--target mask for shapes
    else
        poke(0x5508,0xff)--read mask (need high bits)
        poke(0x550b,0x3f)--target mask for shapes
        color(table_index<<6|peek(0x550c))
    end
end

function spr_colortable(table_index)
    if table_index and table_index>1 then
        fillp(0xffff)
    else
        fillp()
    end
end
P#144322 2024-03-24 22:23 ( Edited 2024-03-25 01:30)

[ :: Read More :: ]

Cart #paint-12 | 2024-03-31 | Embed ▽ | License: CC4-BY-NC-SA
44

An image editor made to imitate the look of Microsoft Paint.

It isn't meant to be a replacement for picotron's built-in graphic editor, but instead is just meant to be a nostalgic little paint toy.

❌Selection tool isn't implemented yet.

supports undo & redo history.

current tools are pencil, bucket, eraser, eye dropper, and magnifying glass.

eraser tool also supports recoloring by using right click.

Supports saving as either pod or gfx format. If you save as gfx it can be opened by picotron's graphics editor.
You can also save just the palette by saving as hex format

update v1.1 - improved the pencil and eraser tools. now they'll draw a line when moving the mouse quickly and won't push to history until you finish your stroke.

update v1.2 - tool icons now replace the cursor when hovering the canvas
added saving and loading. Loading from the menu doesn't quite work yet, I wasn't able to figure that out. It also supports loading by drag and drop however.

update v1.3 - color mixer now in its own window. Refactored most of the code. You can now save palette information with the file, or on its own as a .pal file.

update v1.4 - palette information now stored in metadata instead of content.

update v1.4.1 - import and export hex format (lospec.com) for palettes

update v1.5 - Added image resizing. Just drag the resize handle to change the image size.
Added scrollbars if the image is bigger than the display area.
Palette stored in image metadata is now hex format.
Improved history

update v1.5.1 - You can now drop images or palettes on the color mixer window to open them
Added import and export for .pal format exported from OkPal. It's a palette format in raw userdata that can be poked directly to memory
(Old table-based pal format can still be imported but can't be exported any more and is considered deprecated)

🐛The color mixer window doesn't seem to work on the web player

Planned features

  • ability to choose what format palette is stored in metadata, either hex or pal. When you import a palette the setting should be updated to match the imported palette
  • brush sizes
  • selection tool
  • paste userdata
P#143261 2024-03-16 05:17 ( Edited 2024-03-31 17:48)

[ :: Read More :: ]

Cart #gamepad_tester-5 | 2024-03-20 | Embed ▽ | License: CC4-BY-NC-SA
12

A quick gamepad tester I wrote for picotron to test the gamepad api. The tester also supports changing the player number to use multiple gamepads.

I labeled the buttons according to their corresponding keyboard inputs, and layed out the buttons according to how they mapped on my xbox controller.

The two buttons in the middle are buttons 6 and 7, which the readme lists as reserved, but I think represent start and select buttons.
Button 6 seems to map to the start and home buttons, as well as the enter key.
Button 7 doesn't seem to map to anything yet.

As of writing there seems to be a bug in picotron where higher player numbers don't work correctly.
player 0 works properly, but odd numbered players, such as player 1, will have their inputs split across two controllers.

I've also confirmed that as of writing picotron only fully supports up to 4 controllers. If you connect a 5th controller, half of their inputs will register on player 7, and player numbers higher than 7 aren't supported so only half the controller will work.

Update:
Now highlights the player tab when that player's controller has active inputs, making it easier to find what player your controller is mapped to.

Update 2:
Now reports analogue values for the sticks

P#143045 2024-03-15 02:26 ( Edited 2024-03-20 23:35)