Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define DIV8(n) (((n) + 7) / 8)
- #define ORDENA(a, b) {if (a > b) {int temp = a; a = b; b = temp;}}
- #define LIGA_SEGURO(img, y, x) if (x < me->colunas && x >= 0 && y < me->linhas && y >= 0) me->bitmap[y][(x)/8] |= 128 >> ((x)%8);
- pos_BwImage *pos_BwImage_new(int lin, int col) {
- pos_BwImage *res;
- unsigned char **bitmap;
- unsigned char *data;
- res = (pos_BwImage *)pos_malloc(sizeof(pos_BwImage));
- if (res == NULL)
- return NULL;
- bitmap = (unsigned char **)pos_malloc(sizeof(unsigned char*)*lin);
- if (bitmap == NULL) {
- pos_free(res);
- return NULL;
- }
- data = (unsigned char *)pos_calloc(lin*DIV8(col), sizeof(unsigned char));
- if (data == NULL) {
- pos_free(bitmap);
- pos_free(res);
- return NULL;
- }
- pos_BwImage_init(res, lin, col, bitmap, data);
- res->modoAlocacao = 2; // tudo mallocado
- return res;
- }
- pos_BwImage *pos_BwImage_init(pos_BwImage *image, int lin, int col, unsigned char **lines, unsigned char *data) {
- int i;
- image->linhas = lin;
- image->colunas = col;
- image->modoAlocacao = 0;
- image->bitmap = lines;
- for (i = 0; i < lin; i++) {
- image->bitmap[i] = data + (i*DIV8(col));
- }
- return image;
- }
- void pos_BwImage_drawRect(pos_BwImage *me, int x1, int y1, int x2, int y2) {
- int i;
- ORDENA(x1,x2);
- ORDENA(y1,y2);
- for (i=y1; i<y2;i++)
- {
- LIGA_SEGURO(img,i,x1);
- LIGA_SEGURO(img,i,x2);
- }
- for (i=x1; i<=x2;i++)
- {
- LIGA_SEGURO(img,y1,i);
- LIGA_SEGURO(img,y2,i);
- }
- }
- int main(void) {
- pos_BwImage *im1;
- pos_BwImage *im2;
- pos_BwImage *im3;
- pos_prn_Code status;
- im1 = pos_BwImage_new(1, 1);
- im2 = pos_BwImage_new(123, 345); //y=123 e x=345
- status = pos_BwImage_print(im1);
- status = pos_BwImage_print(im2);
- pos_BwImage_drawRect(im1, 0, 0, 10, 10);
- status = pos_BwImage_print(im1);
- pos_BwImage_drawRect(im2, 0, 0, 344, 124);
- status = pos_BwImage_print(im2);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement