static void paint_terrain_colors(float min, float max)
{
	int f, i, j;
	float r, n; 
	int p;

	for (f = 0; f < 6; f++) {
		for (i = 0; i < DIM; i++) {
			for (j = 0; j < DIM; j++) {
				p = (j * DIM + i) * 4; 
				r = vec3_magnitude(&vertex[f][i][j]);
				r = (r - min) / (max - min);
				n = (noise[f][i][j] - minn) / (maxn - minn);
				color_output(f, p, r, n);
			}
		}
	}
}
Exemple #2
0
int color_parse_mem(const char *value, int value_len, char *dst)
{
	const char *ptr = value;
	int len = value_len;
	char *end = dst + COLOR_MAXLEN;
	unsigned int attr = 0;
	struct color fg = { COLOR_UNSPECIFIED };
	struct color bg = { COLOR_UNSPECIFIED };

	while (len > 0 && isspace(*ptr)) {
		ptr++;
		len--;
	}

	if (!len) {
		dst[0] = '\0';
		return 0;
	}

	if (!strncasecmp(ptr, "reset", len)) {
		xsnprintf(dst, end - dst, GIT_COLOR_RESET);
		return 0;
	}

	/* [fg [bg]] [attr]... */
	while (len > 0) {
		const char *word = ptr;
		struct color c = { COLOR_UNSPECIFIED };
		int val, wordlen = 0;

		while (len > 0 && !isspace(word[wordlen])) {
			wordlen++;
			len--;
		}

		ptr = word + wordlen;
		while (len > 0 && isspace(*ptr)) {
			ptr++;
			len--;
		}

		if (!parse_color(&c, word, wordlen)) {
			if (fg.type == COLOR_UNSPECIFIED) {
				fg = c;
				continue;
			}
			if (bg.type == COLOR_UNSPECIFIED) {
				bg = c;
				continue;
			}
			goto bad;
		}
		val = parse_attr(word, wordlen);
		if (0 <= val)
			attr |= (1 << val);
		else
			goto bad;
	}

#undef OUT
#define OUT(x) do { \
	if (dst == end) \
		die("BUG: color parsing ran out of space"); \
	*dst++ = (x); \
} while(0)

	if (attr || !color_empty(&fg) || !color_empty(&bg)) {
		int sep = 0;
		int i;

		OUT('\033');
		OUT('[');

		for (i = 0; attr; i++) {
			unsigned bit = (1 << i);
			if (!(attr & bit))
				continue;
			attr &= ~bit;
			if (sep++)
				OUT(';');
			dst += xsnprintf(dst, end - dst, "%d", i);
		}
		if (!color_empty(&fg)) {
			if (sep++)
				OUT(';');
			/* foreground colors are all in the 3x range */
			dst = color_output(dst, end - dst, &fg, '3');
		}
		if (!color_empty(&bg)) {
			if (sep++)
				OUT(';');
			/* background colors are all in the 4x range */
			dst = color_output(dst, end - dst, &bg, '4');
		}
		OUT('m');
	}
	OUT(0);
	return 0;
bad:
	return error(_("invalid color value: %.*s"), value_len, value);
#undef OUT
}
Exemple #3
0
/*
 * Print a transaction.
 */
static void print_tx(struct PN *node, const uint8_t *tx, size_t len)
{
    uint8_t *ins[MAX_INPUTS];
    size_t inlens[MAX_INPUTS];
    uint8_t *outs[MAX_OUTPUTS];
    size_t outlens[MAX_OUTPUTS];
    uint64_t outvals[MAX_OUTPUTS];

    jmp_buf env;
    struct buf buf0 = {tx, 0, len, &env};
    struct buf *buf = &buf0;
    if (setjmp(env))
    {
parse_error:
        fprintf(stderr, "error: unable to parse transaction\n");
        return;
    }

    size_t num_ins, num_outs;
    if (!parse_tx(buf, ins, inlens, &num_ins, outs, outlens, outvals,
            &num_outs))
        goto parse_error;

    // Formatting constraints:
    size_t lines = MAX(num_ins, num_outs);
    size_t in_d = lines - num_ins;
    size_t out_d = lines - num_outs;
    size_t in_s = 0 + in_d / 2;
    size_t in_e = lines - (in_d + 1) / 2;
    size_t out_s = 0 + out_d / 2;
    size_t out_e = lines - (out_d + 1) / 2;
    size_t mid = (in_s + in_e) / 2;

    time_t t = time(NULL);

    mutex_lock(&lock);

    putchar('\n');
    num_tx++;
    num_tx_bytes += len;
    for (size_t i = 0; i < lines; i++)
    {
        if (i >= in_s && i < in_e)
        {
            size_t idx = i - in_s;
            uint8_t pub_key[65];
            uint8_t script[520];
            size_t script_len;
            char addr[35];
            addr[0] = '\0';
            if (script_is_p2pkh_input(ins[idx], inlens[idx], pub_key))
            {
                size_t pub_key_len = (pub_key[0] == 0x04? 65: 33);
                make_input_addr(pub_key, pub_key_len, 0x00, addr);
            }
            else if (script_is_p2sh_input(ins[idx], inlens[idx], script,
                    &script_len))
                make_input_addr(script, script_len, 0x05, addr);
            
            if (addr[0] != '\0')
            {
                color_input();
                printf("%s", addr);
                color_clear();
                size_t len = strlen(addr);
                for (size_t j = 0; j < 34 - len; j++)
                    putchar(' ');
            }
            else
                printf("[UNKNOWN]                         ");
        }
        else
        {
            for (size_t i = 0; i < 34; i++)
                putchar(' ');
        }
        putchar(' ');

        if (i >= out_s && i < out_e)
        {
            size_t idx = i - out_s;
            uint8_t hash160[20];
            char addr[35];
            uint8_t data[80];
            size_t dlen;
            bool is_data = false;
            addr[0] = '\0';
            if (script_is_p2pkh_output(outs[idx], outlens[idx], hash160))
                make_output_addr(hash160, 0x00, addr);
            else if (script_is_p2sh_output(outs[idx], outlens[idx], hash160))
                make_output_addr(hash160, 0x05, addr);
            else if (script_is_data_output(outs[idx], outlens[idx], data,
                    &dlen))
                is_data = true;
            
            if (addr[0] != '\0')
            {
                color_output();
                printf("%s", addr);
                color_clear();
                size_t len = strlen(addr);
                for (size_t j = 0; j < 34 - len; j++)
                    putchar(' ');
            }
            else if (is_data)
            {
                color_output();
                printf("[DATA] \"");
                size_t space = 26, j;
                for (j = 0; j < dlen && j < 22; j++)
                {
                    if (isprint(data[j]))
                        putchar(data[j]);
                    else
                        putchar('?');
                    space--;
                }
                if (j < dlen)
                {
                    printf("...");
                    space -= 3;
                }
                putchar('\"');
                space--;
                for (j = 0; j < space; j++)
                    putchar(' ');
                color_clear();
            }
            else
                printf("[UNKNOWN]                         ");
            
            // The following is complicated way to ensure the number fits:
            color_value(); 
            double val = GET_BTC(outvals[idx]);
            double btc_val = (double)(unsigned)(val);
            char buf[32];
            size_t len = snprintf(buf, sizeof(buf)-1, "%u", (unsigned)btc_val);
            if (len > 8)
            {
                printf("UNKNOWN\n");
                color_clear();
                continue;
            }
            printf(" %s", buf);
            double mant = val - btc_val;
            if (mant == 0.0)
            {
                color_clear();
                putchar('\n');
                continue;
            }
            size_t prec = 8 - len;
            switch (prec)
            {
                case 1:
                    len = snprintf(buf, sizeof(buf)-1, "%.1f", mant);
                    break;
                case 2:
                    len = snprintf(buf, sizeof(buf)-1, "%.2f", mant);
                    break;
                case 3:
                    len = snprintf(buf, sizeof(buf)-1, "%.3f", mant);
                    break;
                case 4:
                    len = snprintf(buf, sizeof(buf)-1, "%.4f", mant);
                    break;
                case 5:
                    len = snprintf(buf, sizeof(buf)-1, "%.5f", mant);
                    break;
                case 6:
                    len = snprintf(buf, sizeof(buf)-1, "%.6f", mant);
                    break;
                case 7:
                    len = snprintf(buf, sizeof(buf)-1, "%.7f", mant);
                    break;
                case 8:
                    len = snprintf(buf, sizeof(buf)-1, "%.8f", mant);
                    break;
                default:
                    buf[1] = '\0';
                    len = 0;
                    break;
            }
            while (len >= 2 && buf[len-1] == '0')
            {
                buf[len-1] = '\0';
                len--;
            }
            printf("%s", buf+1);
            color_clear();
        }
        putchar('\n');
    }
    if (option_verbose)
    {
        printf("NODE  : height=%u in=%u out=%u sent=%.2gMB recv=%.2gMB\n",
            PN_get_info(node, PN_HEIGHT),
            PN_get_info(node, PN_NUM_IN_PEERS),
            PN_get_info(node, PN_NUM_OUT_PEERS),
            (double)PN_get_info(node, PN_NUM_SEND_BYTES) / 1000000.0,
            (double)PN_get_info(node, PN_NUM_RECV_BYTES) / 1000000.0);
        printf("TX    : hash=");
        hash256_t hash;
        PN_sha256d(tx, len, &hash);
        for (size_t i = 0; i < sizeof(hash); i++)
            printf("%.2x", hash.i8[32 - i - 1]);
        uint64_t tx_val = 0;
        for (size_t i = 0; i < num_outs; i++)
            tx_val += outvals[i];
        total_val += tx_val;
        printf("\n        size=%uB inputs=%u outputs=%u val=%gBTC\n",
            (unsigned)len, (unsigned)num_ins, (unsigned)num_outs,
            GET_BTC(tx_val));
        printf("TOTALS: #tx=%u #block=%u size=%uB val=%gBTC\n",
            (unsigned)num_tx, (unsigned)num_blocks, (unsigned)num_tx_bytes,
            GET_BTC(total_val));
        double vps, sps, txps;
        get_rate_info(t, tx_val, len, &vps, &sps, &txps);
        printf("RATES : tx/s=%.3g bytes/s=%g BTC/s=%g\n",
            txps, sps, GET_BTC(vps));
    }
    prev_msg = false;
    mutex_unlock(&lock);
}
Exemple #4
0
int setup_shader_interface(GLuint program, Sourceparams_t * sourceparams,
			   Displaydata_t * displaydata)
{
  int texture_location, u_texture_location, v_texture_location;
  int texture_width_location, texel_width_location;
  int texture_width, texture_height;
  int image_height, image_width;
  int even_scanlines_first_location;
  int primary_texture_unit; /* single texture unit for non-planar video  */
  int u_texture_unit, v_texture_unit; /* UV of planar YUVs  */
  int luma_texture_coord_offset_loc;
  GLfloat luma_texture_coordinate_offsets[CONVOLUTION_KERNEL_SIZE *
					  CONVOLUTION_KERNEL_SIZE * 2];

  
  /* want texture unit where image is (image_texture_unit)  */
  /* calls to glGetUniformLocation for globals in this file  */

  /* texture_height <--  displaydata->texture_height */
  /* texture_width <--  displaydata->texture_width */
  /* image_height <-- sourceparams->image_height  */
  /* texel_width <-- 1.0/sourceparams->image_width  */
  /* image_texture_unit <-- 0 for the moment  */
  /* yuv_on <-- 1 */
  /* even_scanlines_first <-- 1: should check this  */

  /* for yuv420:  */
  /* Y component in  displaydata->texture  */
  /* U displaydata->u_texture  */
  /* V displaydata->v_texture  */

  /* primary_texture_unit <-- displadata->primary_texture_unit */
  
  print_shader_uniform_vars(program);
  
  
  /* sourceparams->image_width  */
  /* sourceparams->image_height  */
  /* sourceparams->encoding  */
  /* sourceparams->  */
  /* sourceparams->  */
  /* sourceparams->  */
  /* sourceparams->  */
  /* sourceparams->  */


  /* displaydata->bytes_per_pixel*/
  /* displaydata->internal_format */
  /* displaydata->pixelformat  */
  /* displaydata->texture_width  */
  /* displaydata->texture_height  */
  /* displaydata->window_width  */
  /* displaydata->window_height  */
  /* displaydata->texturename  */

  texture_width =  displaydata->texture_width;
  texture_height = displaydata->texture_height;
  image_height = sourceparams->image_height;
  image_width = sourceparams->image_width;
  primary_texture_unit = displaydata->primary_texture_unit;
  
  texture_location = glGetUniformLocation(program, "image_texture_unit");


  
  if (-1 == texture_location)
    {
      fprintf(stderr, "Warning: can't get texture location\n");
      check_error("Warning: can't get texture location");
      exit(-3);
    }
  glUniform1i(texture_location, primary_texture_unit);
  check_error("after glUniform1i");


  if (YUV420 == sourceparams->encoding)
    {

      u_texture_unit = displaydata->u_texture_unit;
      v_texture_unit = displaydata->v_texture_unit;
 
      u_texture_location = glGetUniformLocation(program, "u_texture_unit");

      if (-1 == u_texture_location)
	{
	  fprintf(stderr, "Warning: can't get U texture location\n");
	  check_error("Warning: can't get U texture location");
	  exit(-3);
	}
      glUniform1i(u_texture_location, u_texture_unit);
      check_error("after glUniform1i");


      v_texture_location = glGetUniformLocation(program, "v_texture_unit");

      if (-1 == v_texture_location)
	{
	  fprintf(stderr, "Warning: can't get V texture location\n");
	  check_error("Warning: can't get V texture location");
	  exit(-3);
	}
      glUniform1i(v_texture_location, v_texture_unit);
      check_error("after glUniform1i");
    }
  
  texture_width_location =  glGetUniformLocation(program, "texture_width");

  if (-1 == texture_width_location)
    {
      fprintf(stderr, "Warning: can't get texture_width location\n");
      check_error("Warning: can't get texture_width location");
    }
  else
    {
      glUniform1f(texture_width_location, (float)texture_width);
      check_error("after glUniform1f");
    }
  
  /* don't need texel_width for YUV420  */
  texel_width_location =  glGetUniformLocation(program, "texel_width");

  if (-1 == texel_width_location)
    {
      fprintf(stderr, "Warning: can't get texel_width location\n");
      check_error("Warning: can't get texel_width location");
    }
  else
    {
      glUniform1f(texel_width_location, (1.0 / texture_width)); 
      check_error("after glUniform1f");
    }


  shader_on_location = glGetUniformLocation(program, "shader_on");

  if (-1 == shader_on_location)
    {
      fprintf(stderr, "Warning: can't get shader_on location\n");
      check_error("Warning: can't get shader_on location");
      exit(-3);
    }
  else
    {
      shader_on(); 
    }

#if 1
  {
    int texture_height_location, image_height_location;
    int image_width_location;
    
    /* get the heights too -gpk  9-Mar-06  */
    texture_height_location =  glGetUniformLocation(program, "texture_height");

    if (-1 == texture_height_location)
      {
	fprintf(stderr, "Warning: can't get texture_height location\n");
	check_error("Warning: can't get texture_height location");
	/* exit(-3); */
      }
    else
      {
	fprintf(stderr, "setting texture_height to %f\n",
		(float)texture_height);
	glUniform1f(texture_height_location, (float)texture_height);
	check_error("after glUniform1f");
      }
    
    image_height_location = glGetUniformLocation(program, "image_height");
    if (-1 == image_height_location)
      {
	fprintf(stderr, "Warning: can't get image_height location\n");
	check_error("Warning: can't get image_height location");
	/* exit(-3); */
      }
    else
      {
	glUniform1f(image_height_location, (float)image_height);
	check_error("after glUniform1f");
      }

    image_width_location = glGetUniformLocation(program, "image_width");
    if (-1 == image_width_location)
      {
	fprintf(stderr, "Warning: can't get image_width location\n");
	check_error("Warning: can't get image_width location");
	/* exit(-3); */
      }
    else
      {
	glUniform1f(image_width_location, (float)image_width);
	check_error("after glUniform1f");
      }
  }
#endif /* 1  */

#if 1
  {
    
    /* set global var shader_program so that the  */
    /* invert_scanline_order function can use it later.   */
    /* -gpk 15-Mar-06  */
    /* shader_program = program; */
    
    even_scanlines_first_location =
      glGetUniformLocation(program, "even_scanlines_first");

  if (-1 == even_scanlines_first_location)
    {
      fprintf(stderr, "Warning: can't get even_scanlines_first location\n");
      check_error("Warning: can't get even_scanlines_first location");
    }
  else
    {
      glUniform1i(even_scanlines_first_location, 1);
      check_error("after glUniform1i");
    }
  }
#endif /* 1  */

  {
    color_output_location = glGetUniformLocation(program, "color_output");

    if (-1 == color_output_location)
      {
	fprintf(stderr, "Warning: can't get color_output location\n");
	check_error("Warning: can't get color_output location");
      }
    else
      {
	color_output(1); /* turn color output on  */
	check_error("after glUniform1i for color_output_location");
      }
  }

  {
    luma_texture_coord_offset_loc
      = glGetUniformLocation(program, "luma_texcoord_offsets");
    
    if (-1 == luma_texture_coord_offset_loc)
      {
	fprintf(stderr, "Warning: can't get luma_texcoord_offsets location\n");
	check_error("Warning: can't get luma_texcoord_offsets location");
      }
    else
      {
	initialize_texture_coord_offsets(luma_texture_coordinate_offsets,
					 CONVOLUTION_KERNEL_SIZE,
					 displaydata->texture_width,
					 displaydata->texture_height);
	glUniform2fv(luma_texture_coord_offset_loc, CONVOLUTION_KERNEL_SIZE *
		     CONVOLUTION_KERNEL_SIZE, luma_texture_coordinate_offsets);
      }
  }

  {
    int chroma_texture_coord_offset_loc;
    GLfloat chroma_texture_coordinate_offsets[CONVOLUTION_KERNEL_SIZE *
					      CONVOLUTION_KERNEL_SIZE * 2];
    chroma_texture_coord_offset_loc
      = glGetUniformLocation(program, "chroma_texcoord_offsets");
    
    if (-1 == chroma_texture_coord_offset_loc)
      {
	fprintf(stderr,
		"Warning: can't get chroma_texcoord_offsets location\n");
	check_error("Warning: can't get chroma_texcoord_offsets location");
      }
    else
      {
	initialize_texture_coord_offsets(chroma_texture_coordinate_offsets,
					 CONVOLUTION_KERNEL_SIZE,
					 displaydata->texture_width / 2,
					 displaydata->texture_height/ 2);
	glUniform2fv(chroma_texture_coord_offset_loc,
		     CONVOLUTION_KERNEL_SIZE * CONVOLUTION_KERNEL_SIZE ,
		     chroma_texture_coordinate_offsets);
      }
  }

  {
    image_processing_location =
      glGetUniformLocation(program, "image_processing");

        
    if (-1 == image_processing_location)
      {
	fprintf(stderr, "Warning: can't get  image_processing location\n");
	check_error("Warning: can't get  image_processing  location");
      }
    else
      {
	image_processing_algorithm(0); /* pass through  */
      }
  }
  return(0);
}