aboutsummaryrefslogtreecommitdiffstats
path: root/keyboards/jm60
ModeNameSize
d---------boards / JM60_BOARD37logstatsplain
-rw-r--r--chconf.h16460logstatsplain
-rw-r--r--config.h2122logstatsplain
-rw-r--r--halconf.h10664logstatsplain
-rw-r--r--jm60.c692logstatsplain
-rw-r--r--jm60.h2301logstatsplain
d---------keymaps67logstatsplain
d---------ld46logstatsplain
-rw-r--r--led.c735logstatsplain
-rw-r--r--matrix.c4115logstatsplain
-rw-r--r--mcuconf.h7463logstatsplain
-rw-r--r--readme.md749logstatsplain
-rw-r--r--rules.mk1703logstatspre { line-height: 125%; margin: 0; } td.linenos pre { color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px; } span.linenos { color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px; } td.linenos pre.special { color: #000000; background-color: #ffffc0; padding: 0 5px 0 5px; } span.linenos.special { color: #000000; background-color: #ffffc0; padding: 0 5px 0 5px; } .highlight .hll { background-color: #ffffcc } .highlight { background: #ffffff; } .highlight .c { color: #888888 } /* Comment */ .highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */ .highlight .k { color: #008800; font-weight: bold } /* Keyword */ .highlight .ch { color: #888888 } /* Comment.Hashbang */ .highlight .cm { color: #888888 } /* Comment.Multiline */ .highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */ .highlight .cpf { color: #888888 } /* Comment.PreprocFile */ .highlight .c1 { color: #888888 } /* Comment.Single */ .highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */ .highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */ .highlight .ge { font-style: italic } /* Generic.Emph */ .highlight .gr { color: #aa0000 } /* Generic.Error */ .highlight .gh { color: #333333 } /* Generic.Heading */ .highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */ .highlight .go { color: #888888 } /* Generic.Output */ .highlight .gp { color: #555555 } /* Generic.Prompt */ .highlight .gs { font-weight: bold } /* Generic.Strong */ .highlight .gu { color: #666666 } /* Generic.Subheading */ .highlight .gt { color: #aa0000 } /* Generic.Traceback */ .highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
/*-*-c++-*-
 * $Id$
 *
 * This file is part of plptools.
 *
 *  Copyright (C) 1999-2001 Fritz Elfert <felfert@to.com>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */

#include <plp_inttypes.h>
#include "psibitmap.h"

void
encodeBitmap(int width, int height, getPixelFunction_t getPixel, bool /*rle*/,
	     bufferStore &out) {
    bufferStore ib;

    ib.addDWord(0x00000028);   // hdrlen
    ib.addDWord(width);        // xPixels
    ib.addDWord(height);       // yPixels
    ib.addDWord(0);            // xTwips (unspecified)
    ib.addDWord(0);            // yTwips (unspecified)
    ib.addDWord(2);            // bitsPerPixel
    ib.addDWord(0);            // unknown1
    ib.addDWord(0);            // unknown2
    ib.addDWord(0);            // RLEflag

    bufferStore rawBuf;
    for (int y = 0; y < height; y++) {
	int ov = 0;
	int shift = 0;
	int bc = 0;

	for (int x = 0; x < width; x++) {
	    int v = getPixel(x, y) / 85;
	    ov |= (v << shift);
	    if (shift == 6) {
		rawBuf.addByte(ov);
		bc++;
		shift = 0;
		ov = 0;
	    } else
		shift += 2;
	}
	if (shift != 0) {
	    rawBuf.addByte(ov);
	    shift = 0;
	    ov = 0;
	    bc++;
	}
	while (bc % 4) {
	    rawBuf.addByte(0);
	    bc++;
	}
    }

#if 1
    ib.addBuff(rawBuf);
#else
    //TODO: RLE encoding

    int rawLen = rawBuf.getLen();
    int eqCount = 1;
    int lastByte = rawBuf.getByte(0);
    bufferStore diBuf;

    for (int i = 1; i <= rawLen; i++) {
	int v;
	if (i < rawLen)
	    v = rawBuf.getByte(i);
	else
	    v = lastByte + 1;
	if (v == lastByte) {
	    if (diBuf.getLen()) {
		ib.addByte(0x100 - diBuf.getLen());
		ib.addBuff(diBuf);
		diBuf.init();
	    }
	    eqCount++;
	    if (eqCount > 0x7f) {
		ib.addByte(0x7f);
		ib.addByte(v);
		eqCount = 1;
	    }
	} else {
	    if (eqCount > 1) {
		ib.addByte(eqCount);
		ib.addByte(lastByte);
		eqCount = 1;
	    } else {
		diBuf.addByte(lastByte);
		if ((diBuf.getLen() > 0x7f) || (i == rawLen)) {
		    ib.addByte(0x100 - diBuf.getLen());
		    ib.addBuff(diBuf);
		    diBuf.init();
		}
	    }
	}
	lastByte = v;
    }
#endif

    out.addDWord(ib.getLen() + 4);
    out.addBuff(ib);
}

#define splitByte(v)                                \
do {                                                \
    int j;                                          \
                                                    \
    if (x < bytesPerLine)                           \
	for (j = 0; j < pixelsPerByte; j++) {       \
	    if (j && ((oidx % xPixels) == 0))       \
		break;                              \
	    else                                    \
              if (oidx >= picsize)                  \
		return false;                       \
	    else {                                  \
		out.addByte((v & mask) * grayVal);  \
                v >>= bitsPerPixel;                 \
		oidx++;                             \
	    }                                       \
	}                                           \
    if (++x >= linelen)                             \
	x = 0;                                      \
} while (0)

bool
decodeBitmap(const unsigned char *p, int &width, int &height, bufferStore &out)
{
    u_int32_t totlen = *((u_int32_t*)p); p += 4;
    u_int32_t hdrlen = *((u_int32_t*)p); p += 4;
    u_int32_t datlen = totlen - hdrlen;
    u_int32_t xPixels = *((u_int32_t*)p); p += 4;
    u_int32_t yPixels = *((u_int32_t*)p); p += 4;
    u_int32_t xTwips = *((u_int32_t*)p); p += 4;
    u_int32_t yTwips = *((u_int32_t*)p); p += 4;
    u_int32_t bitsPerPixel = *((u_int32_t*)p); p += 4;
    u_int32_t unknown1 = *((u_int32_t*)p); p += 4;
    u_int32_t unknown2 = *((u_int32_t*)p); p += 4;
    u_int32_t RLEflag = *((u_int32_t*)p); p += 4;

    width = xPixels;
    height = yPixels;

    u_int32_t picsize = xPixels * yPixels;
    u_int32_t linelen;
    int pixelsPerByte = (8 / bitsPerPixel);
    int nColors = 1 << bitsPerPixel;
    int grayVal = 255 / (nColors - 1);
    int bytesPerLine = (xPixels + pixelsPerByte - 1) / pixelsPerByte;
    int mask = (bitsPerPixel << 1) - 1;

    int oidx = 0;
    int x = 0;
    int y = 0;
    int offset = 0;

    if (RLEflag) {
	int i = 0;
	while (offset < datlen) {
	    unsigned char b = *(p + offset);
	    if (b >= 0x80) {
		offset += 0x100 - b + 1;
		i += 0x100 - b;
	    } else {
		offset += 2;
		i += b + 1;
	    }
	}
	linelen = i / yPixels;
	offset = 0;
	while (offset < datlen) {
	    unsigned char b = *(p + offset++);
	    if (b >= 0x80) {
		for (i = 0; i < 0x100 - b; i++, offset++) {
		    if (offset >= datlen)
			return false; // data corrupted
		    unsigned char b2 = *(p + offset);
		    splitByte(b2);
		}
	    } else {
		if (offset >= datlen)
		    return false;
		else {
		    unsigned char b2 = *(p + offset);
		    unsigned char bs = b2;
		    for (i = 0; i <= b; i++) {
			splitByte(b2);
			b2 = bs;
		    }
		}
		offset++;
	    }
	}
    } else {
	linelen = datlen / yPixels;
	while (offset < datlen) {
	    unsigned char b = *(p + offset++);
	    splitByte(b);
	}
    }
    return true;
}

/*
 * Local variables:
 * c-basic-offset: 4
 * End:
 */