示例#1
0
static void
dosymmetries (int x1, int x2, int y1, int y2, int xsym, int cx1, int cx2)
{
    if (cx1 != x1) {
        register int y;
        register cpixel_t *xx1, *xx2;
        for (y = y1; y <= y2; y++) {
            xx1 = p_add ((cpixel_t *) cimage.currlines[y], x1);
            xx2 = p_add ((cpixel_t *) cimage.currlines[y], 2 * xsym - x1);
            while (xx1 < xx2) {
                p_copy (xx1, 0, xx2, 0);
                p_inc (xx1, 1);
                p_inc (xx2, -1);
            }
        }
    }
    if (cx2 != x2) {
        register int y;
        register cpixel_t *xx1, *xx2;
        for (y = y1; y <= y2; y++) {
            xx1 = p_add ((cpixel_t *) cimage.currlines[y], x2);
            xx2 = p_add ((cpixel_t *) cimage.currlines[y], 2 * xsym - x2);
            while (xx1 > xx2) {
                p_copy (xx1, 0, xx2, 0);
                p_inc (xx1, -1);
                p_inc (xx2, 1);
            }
        }
    }
}
// Must be locked over the prefetch queue - can be unlocked immediately following the call
// Should not be called if the prefetch queue is already full (check that prefetch_size < max_prefetch_size)
// The "prefetch get" semaphore should be incremented following this call
void prefetch_putRequest(struct request* req) {

	fprintf(stderr, "prefetch_putRequest: Called\n");

	p_add(req);

}
示例#3
0
static void
bfill (void *dat, struct taskinfo *task, int r1, int r2)
{
    int y;
    cpixel_t *pos, *end;
    unsigned char *data;
    r1 += ystart + 1;
    r2 += ystart + 1;
    for (y = r1; y < r2; y++) {
        pos = p_add ((cpixel_t *) cimage.currlines[y], xstart + 1);
        end = p_add ((cpixel_t *) cimage.currlines[y], xend);
        data = calculated + xstart + y * CALCWIDTH + 1;
        for (; pos < end; p_inc (pos, 1), data++) {
            if (!*data)
                p_copy (pos, 0, pos, -1);
        }
    }
}
示例#4
0
文件: edged.c 项目: Jheengut/gmerlin
static void
do_edge (void *data, struct taskinfo *task, int r1, int r2)
{
  struct filter *f = (struct filter *) data;
  int y;
  unsigned int *pixels = f->image->palette->pixels;
  register unsigned int black = f->image->palette->pixels[0];
  register cpixel_t *output, *end;
  register spixel_t *up, *down, *input;
  for (y = r1; y < r2; y++)
    {
      output = p_add (((cpixel_t *) f->image->currlines[y]), 1);
      input = ((spixel_t *) f->childimage->currlines[y]) + 1;
      if (y != 0)
	up = ((spixel_t *) f->childimage->currlines[y - 1]) + 2;
      else
	up = ((spixel_t *) f->childimage->currlines[y]) + 2;
      if (y != f->image->height - 1)
	down = ((spixel_t *) f->childimage->currlines[y + 1]) + 2;
      else
	down = ((spixel_t *) f->childimage->currlines[y]) + 2;
      end =
	p_add (((cpixel_t *) f->image->currlines[y]), f->image->width - 1);
      p_setp (output, -1, 0);
      p_setp (output, f->image->width - 2, 0);
      while (output < end)
	{
	  if (input[1] != input[0] || input[0] != up[0]
	      || input[0] != down[0])
	    {
	      if (output < end - 2)
		{
		  p_set (output, pixels[input[0]]);
		  p_setp (output, 1, pixels[input[1]]);
		  p_setp (output, 2, pixels[input[2]]);
		  p_inc (output, 3);
		  input += 3;
		  up += 3;
		  down += 3;
		  while (output < end - 1
			 && (input[0] != up[-1] || input[0] != down[-1]))
		    {
		      p_set (output, pixels[input[0]]);
		      p_setp (output, 1, pixels[input[1]]);
		      p_inc (output, 2);
		      input += 2;
		      up += 2;
		      down += 2;
		    }
		  if (output < end
		      && (input[-1] != input[0] || up[-2] != input[0]
			  || down[-2] != input[0]))
		    {
		      p_set (output, pixels[input[0]]);
		      p_inc (output, 1);
		      input++;
		      up++;
		      down++;
		    }
		}
	      else
		p_set (output, pixels[*input]), p_inc (output, 1), input++,
		  up++, down++;
	    }
	  else
	    p_set (output, black), p_inc (output, 1), input++, up++, down++;
	}
    }
}
示例#5
0
     static void tracecolor (int xstart, int ystart, int xend, int yend, register int x, register int y)
{
    int dir = RIGHT, fill = 0;
    register unsigned char *calc;
    int peri = 0;
    cpixeldata_t c = (cpixeldata_t) calculatepixel (x, y, 0);
    cpixeldata_t w = (cpixeldata_t) 0;
    cpixeldata_t inset = (cpixeldata_t) cpalette.pixels[0];
    putpixel (x, y, c);
    calc = calculated + x + y * CALCWIDTH;
    *calc = (unsigned char) 1;
    while (x > xstart && getpixel (x - 1, y) == c)
        x--, calc--;
    *calc = (unsigned char) 2;
    if (c == inset)
        peri = 1;
    do {
        if (!fill && !*calc) {
            *calc = (unsigned char) 1;
            putpixel (x, y, c);
        }
        switch (dir) {
            case RIGHT:
                if (y > ystart) {
                    if (!*(calc - CALCWIDTH)) {
                        w = (cpixeldata_t) calculatepixel (x, y - 1, peri);
                        putpixel (x, y - 1, w);
                        *(calc - CALCWIDTH) = (unsigned char) 1;
                    } else
                        w = getpixel (x, y - 1);
                    if (w == c) {
                        dir = UP;
                        calc -= CALCWIDTH;
                        y--;
                        break;
                    }
                }

                if (x < xend) {
                    if (!*(calc + 1)) {
                        w = (cpixeldata_t) calculatepixel (x + 1, y, peri);
                        putpixel (x + 1, y, w);
                        *(calc + 1) = (unsigned char) 1;
                    } else
                        w = getpixel (x + 1, y);
                    if (w == c) {
                        calc++;
                        x++;
                        break;
                    }
                }

                if (y < yend) {
                    if (!*(calc + CALCWIDTH)) {
                        w = (cpixeldata_t) calculatepixel (x, y + 1, peri);
                        putpixel (x, y + 1, w);
                        *(calc + CALCWIDTH) = (unsigned char) 1;
                    } else
                        w = getpixel (x, y + 1);
                    if (w == c) {
                        dir = DOWN;
                        calc += CALCWIDTH;
                        y++;
                        break;
                    }
                }

                if (*calc == (unsigned char) 2) {
                    *calc = (unsigned char) 1;
                    return;
                }

                dir = LEFT;
                x--;
                calc--;
                break;

            case LEFT:
                if (y < yend) {
                    if (!*(calc + CALCWIDTH)) {
                        w = (cpixeldata_t) calculatepixel (x, y + 1, peri);
                        putpixel (x, y + 1, w);
                        *(calc + CALCWIDTH) = (unsigned char) 1;
                    } else
                        w = getpixel (x, y + 1);
                    if (w == c) {
                        dir = DOWN;
                        calc += CALCWIDTH;
                        y++;
                        break;
                    }
                }

                if (x > xstart) {
                    if (!*(calc - 1)) {
                        w = (cpixeldata_t) calculatepixel (x - 1, y, peri);
                        putpixel (x - 1, y, w);
                        *(calc - 1) = (unsigned char) 1;
                    } else
                        w = getpixel (x - 1, y);
                    if (w == c) {
                        calc--;
                        x--;
                        break;
                    }
                }

                if (y > ystart) {
                    if (!*(calc - CALCWIDTH)) {
                        w = (cpixeldata_t) calculatepixel (x, y - 1, peri);
                        putpixel (x, y - 1, w);
                        *(calc - CALCWIDTH) = (unsigned char) 1;
                    } else
                        w = getpixel (x, y - 1);
                    if (w == c) {
                        dir = UP;
                        calc -= CALCWIDTH;
                        y--;
                        break;
                    }
                }


                dir = RIGHT;
                x++;
                calc++;
                break;

            case UP:
                if (fill) {
                    unsigned char *calc1;
                    cpixel_t *pixel1;
                    calc1 = calc + 1;
                    pixel1 = p_add ((cpixel_t *) cimage.currlines[y], x + 1);
                    while (pixel1 <= p_add ((cpixel_t *) cimage.currlines[y], xend)) {
                        if (!*calc1)
                            *calc1 = (unsigned char) 1, p_set (pixel1, c);
                        else if (p_get (pixel1) != c)
                            break;
                        p_inc (pixel1, 1);
                        calc1++;
                    }
                }
                if (x > xstart) {
                    if (!*(calc - 1)) {
                        w = (cpixeldata_t) calculatepixel (x - 1, y, peri);
                        putpixel (x - 1, y, w);
                        *(calc - 1) = (unsigned char) 1;
                    }
                    w = getpixel (x - 1, y);
                    if (w == c) {
                        dir = LEFT;
                        calc--;
                        x--;
                        break;
                    }
                }

                if (y > ystart) {
                    if (!*(calc - CALCWIDTH)) {
                        w = (cpixeldata_t) calculatepixel (x, y - 1, peri);
                        putpixel (x, y - 1, w);
                        *(calc - CALCWIDTH) = (unsigned char) 1;
                    }
                    w = getpixel (x, y - 1);
                    if (w == c) {
                        calc -= CALCWIDTH;
                        y--;
                        break;
                    }
                }

                if (x < xend) {
                    if (!*(calc + 1)) {
                        w = (cpixeldata_t) calculatepixel (x + 1, y, peri);
                        putpixel (x + 1, y, w);
                        *(calc + 1) = (unsigned char) 1;
                    } else
                        w = getpixel (x + 1, y);
                    if (w == c) {
                        dir = RIGHT;
                        calc++;
                        x++;
                        break;
                    }
                }

                dir = DOWN;
                y++;
                calc += CALCWIDTH;
                break;
            case DOWN:
                if (x < xend) {
                    if (!*(calc + 1)) {
                        w = (cpixeldata_t) calculatepixel (x + 1, y, peri);
                        putpixel (x + 1, y, w);
                        *(calc + 1) = (unsigned char) 1;
                    } else
                        w = getpixel (x + 1, y);
                    if (w == c) {
                        dir = RIGHT;
                        calc++;
                        x++;
                        break;
                    }
                }

                if (y < yend) {
                    if (!*(calc + CALCWIDTH)) {
                        w = (cpixeldata_t) calculatepixel (x, y + 1, peri);
                        putpixel (x, y + 1, w);
                        *(calc + CALCWIDTH) = (unsigned char) 1;
                    } else
                        w = getpixel (x, y + 1);
                    if (w == c) {
                        dir = DOWN;
                        calc += CALCWIDTH;
                        y++;
                        break;
                    }
                }

                if (x > xstart) {
                    if (!*(calc - 1)) {
                        w = (cpixeldata_t) calculatepixel (x - 1, y, peri);
                        putpixel (x - 1, y, w);
                        *(calc - 1) = (unsigned char) 1;
                    } else
                        w = getpixel (x - 1, y);
                    if (w == c) {
                        dir = LEFT;
                        calc--;
                        x--;
                        break;
                    }
                }

                dir = UP;
                calc -= CALCWIDTH;
                y--;
                break;

        }
        if (*calc == (unsigned char) 2) {
            if (fill) {
                *calc = (unsigned char) 1;
                return;
            }
            fill = 1;
            dir = RIGHT;
        }
    }
    while (1);
}
示例#6
0
int mosquitto_auth_plugin_init(void **userdata, struct mosquitto_auth_opt *auth_opts, int auth_opt_count)
{
	int i;
	char *backends = NULL, *p, *q;
	struct mosquitto_auth_opt *o;
	struct userdata *ud;
	int ret = MOSQ_ERR_SUCCESS;
	int nord;
	struct backend_p **bep;
#ifdef BE_PSK
	struct backend_p **pskbep;
	char *psk_database = NULL;
#endif

	*userdata = (struct userdata *)malloc(sizeof(struct userdata));
	if (*userdata == NULL) {
		perror("allocting userdata");
		return MOSQ_ERR_UNKNOWN;
	}

	ud = *userdata;

	/*
	 * Shove all options Mosquitto gives the plugin into a hash,
	 * and let the back-ends figure out if they have all they
	 * need upon init()
	 */

	for (i = 0, o = auth_opts; i < auth_opt_count; i++, o++) {
		_log(LOG_DEBUG, "AuthOptions: key=%s, val=%s", o->key, o->value);

		p_add(o->key, o->value);

		if (!strcmp(o->key, "superusers"))
			ud->superusers = strdup(o->value);
#if 0
		if (!strcmp(o->key, "topic_prefix"))
			ud->topicprefix = strdup(o->value);
#endif
	}

	/*
	 * Set up back-ends, and tell them to initialize themselves.
	 */


	backends = p_stab("backends");
	if (backends == NULL) {
		_fatal("No backends configured.");
	}

        p = strdup(backends);

        printf("** Configured order: %s\n", p);

	ud->be_list = (struct backend_p **)malloc((sizeof (struct backend_p *)) * (NBACKENDS + 1));

	bep = ud->be_list;
	nord = 0;

#if BE_PSK
	/*
	 * Force adding PSK back-end, which must be indexed at 0
	 * The PSK back-end is a little special in that it will use
	 * a database from another back-end (e.g. mysql or sqlite)
	 * for authorization.
	 */

	if ((psk_database = p_stab("psk_database")) == NULL) {
		_fatal("PSK is configured so psk_database needs to be set");
	}

	pskbep = bep;
	*pskbep = (struct backend_p *)malloc(sizeof(struct backend_p));
	memset(*pskbep, 0, sizeof(struct backend_p));
	(*pskbep)->name = strdup("psk");

	bep = pskbep;
	bep++;
	nord++;
#endif /* BE_PSK */

        for (q = strsep(&p, ","); q && *q && (nord < NBACKENDS); q = strsep(&p, ",")) {
                int found = 0;
#if BE_MYSQL
		if (!strcmp(q, "mysql")) {
			*bep = (struct backend_p *)malloc(sizeof(struct backend_p));
			memset(*bep, 0, sizeof(struct backend_p));
			(*bep)->name = strdup("mysql");
			(*bep)->conf = be_mysql_init();
			if ((*bep)->conf == NULL) {
				_fatal("%s init returns NULL", q);
			}
			(*bep)->kill =  be_mysql_destroy;
			(*bep)->getuser =  be_mysql_getuser;
			(*bep)->superuser =  be_mysql_superuser;
			(*bep)->aclcheck =  be_mysql_aclcheck;
			found = 1;
			PSKSETUP;
		}
#endif

#if BE_CDB
		if (!strcmp(q, "cdb")) {
			*bep = (struct backend_p *)malloc(sizeof(struct backend_p));
			memset(*bep, 0, sizeof(struct backend_p));
			(*bep)->name = strdup("cdb");
			(*bep)->conf = be_cdb_init();
			if ((*bep)->conf == NULL) {
				_fatal("%s init returns NULL", q);
			}
			(*bep)->kill =  be_cdb_destroy;
			(*bep)->getuser =  be_cdb_getuser;
			(*bep)->superuser =  be_cdb_superuser;
			(*bep)->aclcheck =  be_cdb_aclcheck;
			found = 1;
			PSKSETUP;
		}
#endif

#if BE_SQLITE
		if (!strcmp(q, "sqlite")) {
			*bep = (struct backend_p *)malloc(sizeof(struct backend_p));
			memset(*bep, 0, sizeof(struct backend_p));
			(*bep)->name = strdup("sqlite");
			(*bep)->conf = be_sqlite_init();
			if ((*bep)->conf == NULL) {
				_fatal("%s init returns NULL", q);
			}
			(*bep)->kill =  be_sqlite_destroy;
			(*bep)->getuser =  be_sqlite_getuser;
			(*bep)->superuser =  be_sqlite_superuser;
			(*bep)->aclcheck =  be_sqlite_aclcheck;
			found = 1;
			PSKSETUP;
		}
#endif

#if BE_REDIS
		if (!strcmp(q, "redis")) {
			*bep = (struct backend_p *)malloc(sizeof(struct backend_p));
			memset(*bep, 0, sizeof(struct backend_p));
			(*bep)->name = strdup("redis");
			(*bep)->conf = be_redis_init();
			if ((*bep)->conf == NULL) {
				_fatal("%s init returns NULL", q);
			}
			(*bep)->kill =  be_redis_destroy;
			(*bep)->getuser =  be_redis_getuser;
			(*bep)->superuser =  be_redis_superuser;
			(*bep)->aclcheck =  be_redis_aclcheck;
			found = 1;
			PSKSETUP;
		}
#endif
                if (!found) {
                        _fatal("ERROR: configured back-end `%s' is not compiled in this plugin", q);
                }

		ud->be_list[++nord] = NULL;
		bep++;
        }

        free(p);

	return (ret);
}