npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pebble-dither

v1.0.3

Published

24bit to 6bit or 1bit dithering for Pebble smartwatch

Downloads

11

Readme

Dither Library for Pebble

Draw 6bit or 1bit dithered rectangles or replace a color in a screen region with a dithered color.

For the source and an example program, see the github page for this library:
https://github.com/robisodd/dither-library/blob/master/src/main.c
or if you are using CloudPebble, import it by:
https://cloudpebble.net/ide/import/github/robisodd/dither-library

##TL;DR How to use: #####Include:
#include <pebble-dither/dither.h>

#####Draw:
fill_rect_dithered(ctx, GRect(10, 10, 50, 50), 0, 255, 96);

#####Replace Within Region:
graphics_context_set_fill_color(ctx, GColorCeleste); graphics_fill_circle(ctx, GPoint(80, 100), 20); graphics_fill_circle(ctx, GPoint(20, 120), 10); replace_color_in_rect_with_dithered(ctx, GRect(60, 80, 40, 40), GColorCeleste, 52, 192, 12);

#####Replace Screen Color:
graphics_context_set_fill_color(ctx, GColorRed); graphics_fill_circle(ctx, GPoint(rand() % 100, rand() % 100), 10); replace_color_with_dithered(ctx, GColorRed, 52, 192, 12);

#####TL;DR Notes:

  • The coordinates for rect are in absolute screen coordinates and will not move with the layer they are called in.
  • Also, rect will not be clipped by any layers.
  • To reduce CPU time, use replace_color_in_rect_with_dithered() instead of replace_color_with_dithered() whenever possible.
  • Replace functions only replaces one color per call and therefore does not work on anti-aliased shapes.
  • Animated shapes won't flicker when drawn in different locations.

##What it does 24bit color to 6bit color or 1bit black-and-white dithering library for Pebble. Tested on Aplite, Basalt and Chalk. Should be forward compatible with Diorite, Emery and future watches.

Draws a filled rectangle to the screen which is dithered from 24bit (3 channels of 8bit colors: red, green and blue) color down to Pebble's native 6bit color, or even further down to 1bit black-and-white.

Also can replace screen colors with the dithered color, allowing you to use native pebble API calls (e.g. graphics_draw_line, graphics_fill_circle, gpath_draw_filled, etc.) with dithered colors. To do this, draw with the Pebble function using a placeholder color that doesn't occur anywhere else on the screen, then call replace_color_with_dithered (see: below) to replace that placeholder color with the dithered color. Or use replace_color_in_rect_with_dithered to only replace colors within a screen region.

Currently it does not work on antialiased shapes, unless you specifically replace each color. For instance, if you draw an antialiased red (GColorRed=0b11110000) line on a black background, you'd have to run the replacement funciton 3 times: once for red, once for darker red (GColorDarkCandyAppleRed=0b1110000) and once for darkest red (GColorBulgarianRose=0b11010000). Each will be replaced with the full dithered color, so the input 24bit RGB must be darkened to reproduce the antialiased look.

##Screenshots
Aplite:

Basalt:

Chalk:


##Function calls

#####fill_rect_dithered(ctx, rect, r, g, b)
Given a graphics context, a rect (absolute screen coordinates), and a 24bit RGB color, draws a rectangle filled with a dithered (patterned) 6-bit color. Note that rect uses absolute screen coordinates, unlike graphics_fill_rect() which draws relative to its layer.

#####replace_color_with_dithered(ctx, replacement_color, r, g, b)
Given a graphcs context, a color to look for, and a 24bit RGB dithered color to replace it with, searches the ENTIRE SCREEN for replacement_color and replaces it with a 6bit color dithered from the 24bit RGB given. Note that it currently doesn't ignore the alpha channel, though screen pixels are nearly always alpha = 3.

#####replace_color_in_rect_with_dithered(ctx, rect, replacement_color, r, g, b)
Same as replace_color_with_dithered() but only searches within the rect for replacement_color. Note that rect uses absolute screen coordinates, unlike normal Pebble API functions (e.g. graphics_fill_rect()) which draw relative to their layer.