Browse Source

Added draw functions

refactor
_ 3 years ago
parent
commit
0e870a5f44
2 changed files with 199 additions and 2 deletions
  1. 170
    2
      source/wip/pagegfx.c
  2. 29
    0
      source/wip/pagegfx.h

+ 170
- 2
source/wip/pagegfx.c View File

@@ -1,11 +1,61 @@

#include "pagegfx.h"

#include <math.h>
#include <stdio.h>
#include <string.h>

#define max(a,b) (((a) > (b)) ? (a) : (b))
#define NDOT 32 // Block X and Y size, dots

// Service function, clips regular 32x32-dot raster to bitmap in the position
// with given block coordinates (may be outside the bitmap).
void Fillblock(int blockx,
int blocky,
unsigned char *bits,
int width,
int height,
int border,
int nx,
int ny,
int dx,
int dy,
int px,
int py,
int black) {
typedef unsigned char uchar;
#define black 0
int i,j,x0,y0,x,y,m,n;
ulong t;
// Convert cell coordinates into the X-Y bitmap coordinates.
x0=blockx*(NDOT+3)*dx+2*dx+border;
y0=blocky*(NDOT+3)*dy+2*dy+border;
// Print raster.
for (j=0; j<32; j++) {
if ((j & 1)==0)
t=0x55555555;
else {
if (blocky<0 && j<=24) t=0;
else if (blocky>=ny && j>8) t=0;
else if (blockx<0) t=0xAA000000;
else if (blockx>=nx) t=0x000000AA;
else t=0xAAAAAAAA; };
for (i=0; i<32; i++) {
if (t & 1) {
for (m=0; m<py; m++) {
for (n=0; n<px; n++) {
x=x0+i*dx+n;
y=y0+j*dy+m;
if (x<0 || x>=width || y<0 || y>=height)
continue;
bits[(height-y-1)*width+x]=(uchar)black;
};
};
};
t>>=1;
};
};
};

#define NDOT 32 // Block X and Y size, dots

int Getprintablewidth(unsigned int pwidth, int ppix) {
int leftborder = ppix/2;
@@ -96,3 +146,121 @@ struct pagegfx init_pagegfx(int ppix,
p.height = drawheight;
return p;
}

void draw_grid_vlines (unsigned char *bits,
struct pagegfx p,
bool has_border,
int border) {
#define START 0
#define CLR_BLACK 0
int i, j, k;
int basex;
for (i = START; i <= p.nx; i++) {
if (has_border) {
basex = i*(NDOT + 3) * p.dx + border;
for (j = START; j < p.ny *(NDOT + 3) * p.dy + p.py + 2 * border; j++, basex += p.width) {
for (k = START; k < p.px; k++) {
bits[basex+k] = CLR_BLACK;
}
}
} else {
basex = i*(NDOT + 3) * p.dx + p.width * border + border;
for (j = START; j < p.ny *(NDOT + 3) * p.dy; j++, basex += p.width) {
for (k = START; k < p.px; k++) {
bits[basex+k] = CLR_BLACK;
}
}
}
}
}

void draw_grid_hline(unsigned char *bits,
struct pagegfx p,
bool has_border,
int border) {
#define START 0
#define CLR_BLACK 0
int i, j, k;
for (j = START; j <= p.ny; j++) {
if (has_border) {
for (k = START; k < p.py; k++) {
memset(bits + (j*(NDOT+3) * p.dy + k + border) * p.width,
CLR_BLACK,
p.width);
}
} else {
for (k = START; k < p.py; k++) {
memset(bits + (j * (NDOT+3) * p.dy + k + border) * p.width + border,
CLR_BLACK,
p.nx * (NDOT+3) * p.dx + p.px);
}
}
}
}

void fillraster(unsigned char *bits,
struct pagegfx p,
int border,
bool has_border) {
#define CLR_BLACK 0
unsigned int i, j;
if (has_border) {
for (j = -1; j <= p.ny; j++) {
Fillblock(-1,
j,
bits,
p.width,
p.height,
border,
p.nx,
p.ny,
p.dx,
p.dy,
p.px,
p.py,
CLR_BLACK);
Fillblock(p.nx,
j,
bits,
p.width,
p.height,
border,
p.nx,
p.ny,
p.dx,
p.dy,
p.px,
p.py,
CLR_BLACK);
}
for (i = 0; i < p.nx; i++) {
Fillblock(i,
-1,
bits,
p.width,
p.height,
border,
p.nx,
p.ny,
p.dx,
p.dy,
p.px,
p.py,
CLR_BLACK);
Fillblock(i,
p.ny,
bits,
p.width,
p.height,
border,
p.nx,
p.ny,
p.dx,
p.dy,
p.px,
p.py,
CLR_BLACK);
}
}
}


+ 29
- 0
source/wip/pagegfx.h View File

@@ -3,6 +3,20 @@

#include <stdbool.h>

void Fillblock(int,
int,
unsigned char *,
int,
int,
int,
int,
int,
int,
int,
int,
int,
int);

// Deals with graphics pertaining to page

int Getprintablewidth(unsigned int, int);
@@ -33,4 +47,19 @@ struct pagegfx init_pagegfx(int,
int,
int,
bool);

void draw_grid_vlines (unsigned char *,
struct pagegfx,
bool,
int);

void draw_grid_hline(unsigned char *,
struct pagegfx,
bool,
int);

void fillraster(unsigned char *,
struct pagegfx,
int,
bool);
#endif

Loading…
Cancel
Save