Ejemplo n.º 1
0
void Textgrafs::fill_grid(const Pixel & p){
  for(int y = 0; y < rows_; ++y){
    for(int x = 0; x < cols_; ++x){
      add_pixel(p, x, y);
    }
  }
}
Ejemplo n.º 2
0
/* 
void Textgrafs::add_image(std::vector<std::vector<std::string>> & img_ref, int px, int py){
  
  for(int y = 0; y < img_ref.size(); ++y){
    for(int x = 0; x < img_ref[y].size(); ++x){
      Pixel p(img_ref[y][x]);
      add_pixel(p, px+x, py+y);
    }
  }
}
*/
void Textgrafs::add_image(const std::vector<std::vector<Pixel>> & imgref, int px, int py){
  for(int y = 0; y <  imgref.size(); ++y){
    for(int x = 0; x < imgref[y].size(); ++x){
      add_pixel(imgref[y][x], px+x, py+y);
    }
  }
}
Ejemplo n.º 3
0
void Textgrafs::add_rect(const Pixel & p, int px, int py, int sizex, int sizey){
  for(int y = py; y < py+sizey; ++y){
    for(int x = px; x < px+sizex; ++x){
      add_pixel(p, x, y);
    }
  }
}
Ejemplo n.º 4
0
void Textgrafs::clear_grid_specific(int px, int py, int sizex, int sizey){
  for(int y = py; y < py+sizey; ++y){
    for(int x = px; x < px+sizex; ++x){
      Pixel p;
      add_pixel(p,x,y);
    }
  } 
}
Ejemplo n.º 5
0
void Textgrafs::clear_grid(){
  //Fills the grid with space
  for(int y = 0; y < grid.size(); ++y){
    for(int x = 0; y < grid[y].size();++x){
      Pixel p;
      add_pixel(p, x, y);
    }
  }
}
Ejemplo n.º 6
0
void Textgrafs::add_border(const Pixel & p, int px, int py, int sizex, int sizey){
  for(int y = py; y < py+sizey; ++y){
    for(int x = px; x < px+sizex; ++x){
      if(x == px || y == py || x == px+sizex-1 || y == py+sizey-1){
	add_pixel(p, x, y);
      }
    }
  }
}
Ejemplo n.º 7
0
static gboolean
gst_spectra_scope_render (GstBaseAudioVisualizer * bscope, GstBuffer * audio,
    GstBuffer * video)
{
  GstSpectraScope *scope = GST_SPECTRA_SCOPE (bscope);
  guint32 *vdata = (guint32 *) GST_BUFFER_DATA (video);
  gint16 *adata = (gint16 *) g_memdup (GST_BUFFER_DATA (audio),
      GST_BUFFER_SIZE (audio));
  GstFFTS16Complex *fdata = scope->freq_data;
  guint x, y, off;
  guint l, h = bscope->height - 1;
  gfloat fr, fi;
  guint w = bscope->width;

  if (bscope->channels > 1) {
    guint ch = bscope->channels;
    guint num_samples = GST_BUFFER_SIZE (audio) / (ch * sizeof (gint16));
    guint i, c, v, s = 0;

    /* deinterleave and mixdown adata */
    for (i = 0; i < num_samples; i++) {
      v = 0;
      for (c = 0; c < ch; c++) {
        v += adata[s++];
      }
      adata[i] = v / ch;
    }
  }

  /* run fft */
  gst_fft_s16_window (scope->fft_ctx, adata, GST_FFT_WINDOW_HAMMING);
  gst_fft_s16_fft (scope->fft_ctx, adata, fdata);
  g_free (adata);

  /* draw lines */
  for (x = 0; x < bscope->width; x++) {
    /* figure out the range so that we don't need to clip,
     * or even better do a log mapping? */
    fr = (gfloat) fdata[1 + x].r / 512.0;
    fi = (gfloat) fdata[1 + x].i / 512.0;
    y = (guint) (h * fabs (fr * fr + fi * fi));
    if (y > h)
      y = h;
    y = h - y;
    off = (y * w) + x;
    vdata[off] = 0x00FFFFFF;
    for (l = y + 1; l <= h; l++) {
      off += w;
      add_pixel (&vdata[off], 0x007F7F7F);
    }
  }
  return TRUE;
}
Ejemplo n.º 8
0
static void add_line(renderbuf_t*buf, double x1, double y1, double x2, double y2, edgestyle_t*fs, segment_dir_t dir, int polygon_nr)
{
    x1 *= buf->zoom;
    y1 *= buf->zoom;
    x2 *= buf->zoom;
    y2 *= buf->zoom;
    double diffx, diffy;
    double ny1, ny2, stepx;

    if(y2 < y1) {
		int dirint =(int)dir;
        dirint ^= DIR_UP^DIR_DOWN;
		dir = (segment_dir_t)dirint;
        double x,y;
	x = x1;x1 = x2;x2=x;
	y = y1;y1 = y2;y2=y;
    }

    diffx = x2 - x1;
    diffy = y2 - y1;
    ny1 = floor(y1)+CUT;
    ny2 = floor(y2)+CUT;

    if(ny1 < y1) {
        ny1 = floor(y1) + 1.0 + CUT;
    }
    if(ny2 >= y2) {
        ny2 = floor(y2) - 1.0 + CUT;
    }
    if(ny1 > ny2)
        return;

    stepx = diffx/diffy;
    x1 = x1 + (ny1-y1)*stepx;
    x2 = x2 + (ny2-y2)*stepx;

    int posy=floor(ny1);
    int endy=floor(ny2);
    double posx=0;
    double startx = x1;

    //printf("line %d from %f to %f dir=%s\n", polygon_nr, y1, y2, dir==DIR_UP?"up":"down");

    while(posy<=endy) {
        double xx = startx + posx;
        add_pixel(buf, xx, posy, dir, fs, polygon_nr);
        posx+=stepx;
        posy++;
    }
}
Ejemplo n.º 9
0
static void
reconstruct_glyph(struct glyph *cursor, struct glyph *mask, char *name,
		  struct reconstructed_glyph *glyph)
{
	int minx = min(-cursor->hotx, -mask->hotx);
	int maxx = max(cursor->right_bearing, mask->right_bearing);

	int miny = min(-cursor->hoty, -mask->hoty);
	int maxy = max(cursor->height - cursor->hoty,
		       mask->height - mask->hoty);

	int width = maxx - minx;
	int height = maxy - miny;

	glyph->name = strdup(name);
	glyph->width = width;
	glyph->height = height;
	glyph->hotspot_x = -minx;
	glyph->hotspot_y = -miny;
	glyph->offset = data_buffer.size;

	int x, y;
	for (y = miny; y < maxy; ++y) {
		for (x = minx; x < maxx; ++x) {
			char alpha = get_glyph_pixel(mask, x, y);
			if (alpha) {
				char color = get_glyph_pixel(cursor, x, y);
				if (color)
					add_pixel(0xff000000);
				else
					add_pixel(0xffffffff);
			} else {
				add_pixel(0);
			}
		}
	}
}
Ejemplo n.º 10
0
/************************************************************
 * Add the 8 compass neighbors to the stack with conditions.
 ************************************************************/
static void add_neighbours(int loc,
			   int *stack,
			   int *visited,
			   int *trusted,
			   int *nstack,
			   int nx, int ny)
{
  int x = loc % nx;
  int y = loc / nx;

  add_pixel(x,  y+1,stack,visited,trusted,nstack,nx,ny);
  add_pixel(x+1,y+1,stack,visited,trusted,nstack,nx,ny);
  add_pixel(x+1,y  ,stack,visited,trusted,nstack,nx,ny);
  add_pixel(x+1,y-1,stack,visited,trusted,nstack,nx,ny);
  add_pixel(x  ,y-1,stack,visited,trusted,nstack,nx,ny);
  add_pixel(x-1,y-1,stack,visited,trusted,nstack,nx,ny);
  add_pixel(x-1,y  ,stack,visited,trusted,nstack,nx,ny);
  add_pixel(x-1,y+1,stack,visited,trusted,nstack,nx,ny);
}
Ejemplo n.º 11
0
static void add_line(renderbuf_t*buf, double x1, double y1, double x2, double y2, fillstyle_t*fs, int polygon_nr)
{
    x1 *= buf->zoom;
    y1 *= buf->zoom;
    x2 *= buf->zoom;
    y2 *= buf->zoom;
    double diffx, diffy;
    double ny1, ny2, stepx;
    segment_dir_t dir = DIR_DOWN;
    if(y2 < y1) {
        dir = DIR_UP;
        double x,y;
	x = x1;x1 = x2;x2=x;
	y = y1;y1 = y2;y2=y;
    }
    diffx = x2 - x1;
    diffy = y2 - y1;
    ny1 = floor(y1)+CUT;
    ny2 = floor(y2)+CUT;

    if(ny1 < y1) {
        ny1 = floor(y1) + 1.0 + CUT;
    }
    if(ny2 >= y2) {
        ny2 = floor(y2) - 1.0 + CUT;
    }
    if(ny1 > ny2)
        return;

    stepx = diffx/diffy;
    x1 = x1 + (ny1-y1)*stepx;
    x2 = x2 + (ny2-y2)*stepx;

    int posy=floor(ny1);
    int endy=floor(ny2);
    double posx=0;
    double startx = x1;

    while(posy<=endy) {
        double xx = startx + posx;
        add_pixel(buf, xx, posy, dir, fs, polygon_nr);
        posx+=stepx;
        posy++;
    }
}
Ejemplo n.º 12
0
image resize_image(image im, int w, int h)
{
    image resized = make_image(w, h, im.c);   
    image part = make_image(w, im.h, im.c);
    int r, c, k;
    float w_scale = (float)(im.w - 1) / (w - 1);
    float h_scale = (float)(im.h - 1) / (h - 1);
    for(k = 0; k < im.c; ++k){
        for(r = 0; r < im.h; ++r){
            for(c = 0; c < w; ++c){
                float val = 0;
                if(c == w-1 || im.w == 1){
                    val = get_pixel(im, im.w-1, r, k);
                } else {
                    float sx = c*w_scale;
                    int ix = (int) sx;
                    float dx = sx - ix;
                    val = (1 - dx) * get_pixel(im, ix, r, k) + dx * get_pixel(im, ix+1, r, k);
                }
                set_pixel(part, c, r, k, val);
            }
        }
    }
    for(k = 0; k < im.c; ++k){
        for(r = 0; r < h; ++r){
            float sy = r*h_scale;
            int iy = (int) sy;
            float dy = sy - iy;
            for(c = 0; c < w; ++c){
                float val = (1-dy) * get_pixel(part, c, iy, k);
                set_pixel(resized, c, r, k, val);
            }
            if(r == h-1 || im.h == 1) continue;
            for(c = 0; c < w; ++c){
                float val = dy * get_pixel(part, c, iy+1, k);
                add_pixel(resized, c, r, k, val);
            }
        }
    }

    free_image(part);
    return resized;
}
Ejemplo n.º 13
0
static void add_line(renderbuf_t*buf, double x1, double y1, double x2, double y2, signed char direction)
{
    x1 *= buf->zoom;
    y1 *= buf->zoom;
    x2 *= buf->zoom;
    y2 *= buf->zoom;
    double diffx, diffy;
    double ny1, ny2, stepx;
    if(y2 < y1) {
        double x,y;
	x = x1;x1 = x2;x2=x;
	y = y1;y1 = y2;y2=y;
    }
    diffx = x2 - x1;
    diffy = y2 - y1;
    ny1 = INT(y1)+CUT;
    ny2 = INT(y2)+CUT;

    if(ny1 < y1) {
        ny1 = INT(y1) + 1.0 + CUT;
    }
    if(ny2 >= y2) {
        ny2 = INT(y2) - 1.0 + CUT;
    }
    if(ny1 > ny2)
        return;

    stepx = diffx/diffy;
    x1 = x1 + (ny1-y1)*stepx;
    x2 = x2 + (ny2-y2)*stepx;

    int posy=INT(ny1);
    int endy=INT(ny2);
    double posx=0;
    double startx = x1;

    while(posy<=endy) {
        double xx = startx + posx;
        add_pixel(buf, xx, posy, direction);
        posx+=stepx;
        posy++;
    }
}
Ejemplo n.º 14
0
static void add_line(RENDERBUF*buf, double x1, double y1, double x2, double y2, renderpoint_t*p)
{
    renderbuf_internal*i = (renderbuf_internal*)buf->internal;
    double diffx, diffy;
    double ny1, ny2, stepx;
    /*    if(DEBUG&4) {
     int l = sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1));
     printf(" l[%d - %.2f/%.2f -> %.2f/%.2f]\n", l, x1/20.0, y1/20.0, x2/20.0, y2/20.0);
     }*/
    assert(p->shapeline);
    
    y1=y1*i->multiply;
    y2=y2*i->multiply;
    x1=x1*i->multiply;
    x2=x2*i->multiply;
    
    y1 = y1/20.0;
    y2 = y2/20.0;
    x1 = x1/20.0;
    x2 = x2/20.0;
    
    if(y2 < y1) {
        double x;
        double y;
        x = x1;x1 = x2;x2=x;
        y = y1;y1 = y2;y2=y;
    }
    
    diffx = x2 - x1;
    diffy = y2 - y1;
    
    ny1 = INT(y1)+CUT;
    ny2 = INT(y2)+CUT;
    
    if(ny1 < y1) {
        ny1 = INT(y1) + 1.0 + CUT;
    }
    if(ny2 >= y2) {
        ny2 = INT(y2) - 1.0 + CUT;
    }
    
    if(ny1 > ny2)
        return;
    
    stepx = diffx/diffy;
    x1 = x1 + (ny1-y1)*stepx;
    x2 = x2 + (ny2-y2)*stepx;
    
    {
        int posy=INT(ny1);
        int endy=INT(ny2);
        double posx=0;
        double startx = x1;
        
        while(posy<=endy) {
            float xx = (float)(startx + posx);
            add_pixel(buf, xx ,posy, p);
            posx+=stepx;
            posy++;
        }
    }
}
Ejemplo n.º 15
0
static gboolean
gst_spectra_scope_render (GstBaseAudioVisualizer * bscope, GstBuffer * audio,
    GstBuffer * video)
{
  GstSpectraScope *scope = GST_SPECTRA_SCOPE (bscope);
  gint16 *mono_adata;
  GstFFTS16Complex *fdata = scope->freq_data;
  guint x, y, off;
  guint l, h = bscope->height - 1;
  gfloat fr, fi;
  guint w = bscope->width;
  GstMapInfo amap, vmap;
  guint32 *vdata;
  gint channels;

  gst_buffer_map (audio, &amap, GST_MAP_READ);
  gst_buffer_map (video, &vmap, GST_MAP_WRITE);
  vdata = (guint32 *) vmap.data;

  channels = GST_AUDIO_INFO_CHANNELS (&bscope->ainfo);

  mono_adata = (gint16 *) g_memdup (amap.data, amap.size);

  if (channels > 1) {
    guint ch = channels;
    guint num_samples = amap.size / (ch * sizeof (gint16));
    guint i, c, v, s = 0;

    /* deinterleave and mixdown adata */
    for (i = 0; i < num_samples; i++) {
      v = 0;
      for (c = 0; c < ch; c++) {
        v += mono_adata[s++];
      }
      mono_adata[i] = v / ch;
    }
  }

  /* run fft */
  gst_fft_s16_window (scope->fft_ctx, mono_adata, GST_FFT_WINDOW_HAMMING);
  gst_fft_s16_fft (scope->fft_ctx, mono_adata, fdata);
  g_free (mono_adata);

  /* draw lines */
  for (x = 0; x < bscope->width; x++) {
    /* figure out the range so that we don't need to clip,
     * or even better do a log mapping? */
    fr = (gfloat) fdata[1 + x].r / 512.0;
    fi = (gfloat) fdata[1 + x].i / 512.0;
    y = (guint) (h * fabs (fr * fr + fi * fi));
    if (y > h)
      y = h;
    y = h - y;
    off = (y * w) + x;
    vdata[off] = 0x00FFFFFF;
    for (l = y + 1; l <= h; l++) {
      off += w;
      add_pixel (&vdata[off], 0x007F7F7F);
    }
  }
  gst_buffer_unmap (video, &vmap);
  gst_buffer_unmap (audio, &amap);
  return TRUE;
}
Ejemplo n.º 16
0
static gboolean
gst_spectra_scope_render (GstAudioVisualizer * bscope, GstBuffer * audio,
    GstVideoFrame * video)
{
  GstSpectraScope *scope = GST_SPECTRA_SCOPE (bscope);
  gint16 *mono_adata;
  GstFFTS16Complex *fdata = scope->freq_data;
  guint x, y, off, l;
  guint w = GST_VIDEO_INFO_WIDTH (&bscope->vinfo);
  guint h = GST_VIDEO_INFO_HEIGHT (&bscope->vinfo) - 1;
  gfloat fr, fi;
  GstMapInfo amap;
  guint32 *vdata;
  gint channels;

  gst_buffer_map (audio, &amap, GST_MAP_READ);
  vdata = (guint32 *) GST_VIDEO_FRAME_PLANE_DATA (video, 0);

  channels = GST_AUDIO_INFO_CHANNELS (&bscope->ainfo);

  mono_adata = (gint16 *) g_memdup (amap.data, amap.size);

  if (channels > 1) {
    guint ch = channels;
    guint num_samples = amap.size / (ch * sizeof (gint16));
    guint i, c, v, s = 0;

    /* deinterleave and mixdown adata */
    for (i = 0; i < num_samples; i++) {
      v = 0;
      for (c = 0; c < ch; c++) {
        v += mono_adata[s++];
      }
      mono_adata[i] = v / ch;
    }
  }

  /* run fft */
  gst_fft_s16_window (scope->fft_ctx, mono_adata, GST_FFT_WINDOW_HAMMING);
  gst_fft_s16_fft (scope->fft_ctx, mono_adata, fdata);
  g_free (mono_adata);

  /* draw lines */
  for (x = 0; x < w; x++) {
    /* figure out the range so that we don't need to clip,
     * or even better do a log mapping? */
    fr = (gfloat) fdata[1 + x].r / 512.0;
    fi = (gfloat) fdata[1 + x].i / 512.0;
    y = (guint) (h * sqrt (fr * fr + fi * fi));
    if (y > h)
      y = h;
    y = h - y;
    off = (y * w) + x;
    vdata[off] = 0x00FFFFFF;
    for (l = y; l < h; l++) {
      off += w;
      add_pixel (&vdata[off], 0x007F7F7F);
    }
    /* ensure bottom line is full bright (especially in move-up mode) */
    add_pixel (&vdata[off], 0x007F7F7F);
  }
  gst_buffer_unmap (audio, &amap);
  return TRUE;
}
Ejemplo n.º 17
0
static PyObject * blobproperties (PyObject *self, 
				  PyObject *args,  
				  PyObject *keywds)
{
   PyArrayObject *dataarray=NULL,*blobarray=NULL; /* in (not modified) */

   PyArrayObject *results=NULL;
   static char *kwlist[] = {
     "data",
     "blob",
     "npeaks",
     "omega",
     "verbose", 
     NULL};
   double *res;
   double fval;
   double omega=0;
   
   int np=0,verbose=0,type,f,s,peak,bad;

   int i,j, percent;
   npy_intp safelyneed[3];
   
   if(!PyArg_ParseTupleAndKeywords(args,keywds, "O!O!i|di",kwlist,      
				   &PyArray_Type, 
				   &dataarray,   /* array args - data */
				   &PyArray_Type, 
				   &blobarray,   /* blobs */
				   &np,  /* Number of peaks to treat */	   
				   &omega, /* omega angle - put 0 if unknown */
				   &verbose))     /* optional verbosity */
      return NULL;

   if(verbose)printf("omega = %f",omega);

   /* Check array is two dimensional */
   if(dataarray->nd != 2){     
     PyErr_SetString(PyExc_ValueError,
		     "data array must be 2d, first arg problem");
     return NULL;
   } 
   if(verbose!=0)printf("Welcome to blobproperties\n");
   /* Check array is two dimensional and int - 
      results from connectedpixels above */
   if(blobarray->nd != 2 && blobarray->descr->type_num != PyArray_INT){     
     PyErr_SetString(PyExc_ValueError,
		     "Blob array must be 2d and integer, second arg problem");
     return NULL;
   }

   type=dataarray->descr->type_num;
   /* Decide on fast/slow loop - inner versus outer */
   if(blobarray->strides[0] > blobarray->strides[1]) {
     f=1;  s=0;}
   else {
     f=0;  s=1;
   }
      
   if (verbose!=0){
     printf("Fast index is %d, slow index is %d, ",f,s);
     printf("strides[0]=%d, strides[1]=%d\n",
	    dataarray->strides[0],
	    dataarray->strides[1]);
   }
   /* results arrays */
   safelyneed[0]=np;
   safelyneed[1]=NPROPERTY;

   results = (PyArrayObject *) PyArray_SimpleNew(2, 
						safelyneed, 
						PyArray_DOUBLE);

   if( results == NULL){
     PyErr_SetString(PyExc_ValueError,
		     "Malloc failed fo results");
     return NULL;
   }
   Py_BEGIN_ALLOW_THREADS

   if(verbose>0)printf("malloc'ed the results\n");

   res = (double*)results->data;

   /* Initialise the results */
   for ( i=0 ; i<safelyneed[0] ; i++) {
     for ( j=0 ; j<NPROPERTY; j++){
           res[i*NPROPERTY+j]=0.;
        } 
     /* Set min to max +1 and vice versa */
     res[i*NPROPERTY+bb_mn_f]=blobarray->dimensions[f]+1;
     res[i*NPROPERTY+bb_mn_s]=blobarray->dimensions[s]+1;
     res[i*NPROPERTY+bb_mx_f]=-1;
     res[i*NPROPERTY+bb_mx_s]=-1;
     /* All pixels have the same omega in this frame */
     res[i*NPROPERTY+bb_mx_o]=omega;
     res[i*NPROPERTY+bb_mn_o]=omega;
   }
      
   if(verbose!=0)printf("Got some space to put the results in\n");

   percent=(blobarray->dimensions[s]-1)/80.0;
   if(percent < 1)percent=1;
   bad = 0;
   if(verbose!=0)printf("Scanning image\n");

   /* i,j is looping along the indices data array */
   for( i = 0 ; i <= (blobarray->dimensions[s]-1) ; i++ ){  
     if(verbose!=0 && (i%percent == 0) )printf(".");
     for( j = 0 ; j <= (blobarray->dimensions[f]-1) ; j++ ){

       peak =  *(int *) getptr(blobarray,f,s,i,j);
       
       if( peak > 0  && peak <=np ) {
	    fval = getval(getptr(dataarray,f,s,i,j),type);
	    /* printf("i,j,f,s,fval,peak %d %d %d %d %f %d\n",i,j,f,s,fval,peak); */
	    add_pixel( &res[NPROPERTY*(peak-1)] ,i , j ,fval , omega);
       }
       else{
	 if(peak!=0){
	   bad++;
	   if(verbose!=0 && bad<10){
	     printf("Found %d in your blob image at i=%d, j=%d\n",peak,i,j);}
	   /* Only complain 10 times - otherwise piles of crap go to screen */
	 }
       }
     } /* j */
   } /* i */
   if(verbose){
     printf("\nFound %d bad pixels in the blob image\n",bad);
   }
  Py_END_ALLOW_THREADS

   return Py_BuildValue("O", PyArray_Return(results) ); 
}