Skip to content

Commit

Permalink
made drawing barcodes more efficient and simpler
Browse files Browse the repository at this point in the history
  • Loading branch information
Str8AWay committed May 12, 2015
1 parent f6ec9ca commit 9d900c6
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 32 deletions.
19 changes: 4 additions & 15 deletions src/card_layer.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "a2_strdup.h"
#include "card_layer.h"
#include "defines.h"
#include "tobinstr.h"

#define BARCODE_SUB_BITMAP_COUNT 8

Expand Down Expand Up @@ -64,7 +63,6 @@ Layer *card_layer_get_layer(CardLayer *card_layer) {
}

static void draw_barcode_matrix(CardLayer *card_layer, GContext* ctx) {
char block[9];
int16_t raw_x, raw_y, point_x, point_y;
raw_x = 0;
raw_y = 0;
Expand All @@ -80,10 +78,8 @@ static void draw_barcode_matrix(CardLayer *card_layer, GContext* ctx) {
current_byte++
) {

tobinstr(card_layer->barcode_data[current_byte], 8, block);

for (int8_t p = 7; p >= 0; p--) {
if (block[p] == '1') { // TODO: What is 49??? 49 is the ascii representation of 1. WTF dude?!
for (int8_t p = 0; p < 8; p++) {
if (card_layer->barcode_data[current_byte] & (1 << p)) {
// Non-linear barcodes are scaled 2x to save persistent storage space.

point_x = ( PEBBLE_WIDTH/2 - card_layer->barcode_width ) + raw_x * 2;
Expand All @@ -101,13 +97,10 @@ static void draw_barcode_matrix(CardLayer *card_layer, GContext* ctx) {
raw_y++;
}
}

memset(block, 0, 9);
}
}

static void draw_barcode_linear(CardLayer *card_layer, GContext* ctx) {
char block[9];
int16_t raw_x, point_x, point_y;

raw_x = 0;
Expand All @@ -123,10 +116,8 @@ static void draw_barcode_linear(CardLayer *card_layer, GContext* ctx) {
current_byte++
) {

tobinstr(card_layer->barcode_data[current_byte], 8, block);

for (int16_t current_pixel = 7; current_pixel >= 0; current_pixel--) {
if (block[current_pixel] == 49) {
for (int16_t current_pixel = 0; current_pixel < 8; current_pixel++) {
if (card_layer->barcode_data[current_byte] & (1 << current_pixel)) {
for (int16_t current_vertical = 0; current_vertical < card_layer->barcode_height; current_vertical++) {
point_x = ( PEBBLE_WIDTH / 2 - card_layer->barcode_width / 2 ) + raw_x;
point_y = ( PEBBLE_HEIGHT / 2 - card_layer->barcode_height / 2 ) + current_vertical;
Expand All @@ -137,8 +128,6 @@ static void draw_barcode_linear(CardLayer *card_layer, GContext* ctx) {

raw_x++;
}

memset(block, 0, 9);
}
}

Expand Down
1 change: 0 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include <pebble.h>

#include "a2_strdup.h"
#include "card_layer.h"
#include "defines.h"
#include "error_window.h"
Expand Down
1 change: 0 additions & 1 deletion src/pager_layer.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include "a2_strdup.h"
#include "pager_layer.h"

struct PagerLayer {
Expand Down
12 changes: 0 additions & 12 deletions src/tobinstr.c

This file was deleted.

3 changes: 0 additions & 3 deletions src/tobinstr.h

This file was deleted.

0 comments on commit 9d900c6

Please sign in to comment.