Exemple #1
0
int set_cursor(INT loc)
{
  if (loc < 0 && base % lineLength)
    loc = 0;

  if (!tryloc(loc))
    return FALSE;

  if (loc < base) {
    if (loc - base % lineLength < 0)
      set_base(0);
    else if (!move_base(myfloor(loc - base % lineLength, lineLength) + base % lineLength - base))
      return FALSE;
    cursor = loc - base;
  } else if (loc >= base + page) {
    if (!move_base(myfloor(loc - base % lineLength, lineLength) + base % lineLength - page + lineLength - base))
      return FALSE;
    cursor = loc - base;
  } else if (loc > base + nbBytes) {
    return FALSE;
  } else
    cursor = loc - base;

  if (mark_set)
    updateMarked();

  return TRUE;
}
/** interpolateBiCub: bi-cubic interpolation function using 4x4 pixel, see interpolate */
void _FLT(interpolateBiCub)(unsigned char *rv, float x, float y,
                            unsigned char* img, int width, int height, unsigned char def)
{
    // do a simple linear interpolation at the border
    if (x < 1 || x > width - 2 || y < 1 || y > height - 2) {
        _FLT(interpolateBiLinBorder)(rv, x,y,img,width,height,def);
    } else {
        int x_f = myfloor(x);
        int y_f = myfloor(y);
        float tx = x-x_f;
        short v1 = _FLT(bicub_kernel)(tx,
                                      PIX(img, x_f-1, y_f-1, width, height),
                                      PIX(img, x_f,   y_f-1, width, height),
                                      PIX(img, x_f+1, y_f-1, width, height),
                                      PIX(img, x_f+2, y_f-1, width, height));
        short v2 = _FLT(bicub_kernel)(tx,
                                      PIX(img, x_f-1, y_f, width, height),
                                      PIX(img, x_f,   y_f, width, height),
                                      PIX(img, x_f+1, y_f, width, height),
                                      PIX(img, x_f+2, y_f, width, height));
        short v3 = _FLT(bicub_kernel)(tx,
                                      PIX(img, x_f-1, y_f+1, width, height),
                                      PIX(img, x_f,   y_f+1, width, height),
                                      PIX(img, x_f+1, y_f+1, width, height),
                                      PIX(img, x_f+2, y_f+1, width, height));
        short v4 = _FLT(bicub_kernel)(tx,
                                      PIX(img, x_f-1, y_f+2, width, height),
                                      PIX(img, x_f,   y_f+2, width, height),
                                      PIX(img, x_f+1, y_f+2, width, height),
                                      PIX(img, x_f+2, y_f+2, width, height));
        *rv = (unsigned char)_FLT(bicub_kernel)(y-y_f, v1, v2, v3, v4);
    }
}
/** interpolateBiLinBorder: bi-linear interpolation function that also works at the border.
    This is used by many other interpolation methods at and outsize the border, see interpolate */
void _FLT(interpolateBiLinBorder)(unsigned char *rv, float x, float y,
                                  unsigned char* img, int width, int height,
                                  unsigned char def)
{
    int x_f = myfloor(x);
    int x_c = x_f+1;
    int y_f = myfloor(y);
    int y_c = y_f+1;
    short v1 = PIXEL(img, x_c, y_c, width, height, def);
    short v2 = PIXEL(img, x_c, y_f, width, height, def);
    short v3 = PIXEL(img, x_f, y_c, width, height, def);
    short v4 = PIXEL(img, x_f, y_f, width, height, def);
    float s  = (v1*(x - x_f)+v3*(x_c - x))*(y - y_f) +
               (v2*(x - x_f) + v4*(x_c - x))*(y_c - y);
    *rv = (unsigned char)s;
}
/** interpolateBiLin: bi-linear interpolation function, see interpolate */
void _FLT(interpolateBiLin)(unsigned char *rv, float x, float y,
                            unsigned char* img, int width, int height,
                            unsigned char def)
{
    if (x < 0 || x > width - 1 || y < 0 || y > height - 1) {
        _FLT(interpolateBiLinBorder)(rv, x, y, img, width, height, def);
    } else {
        int x_f = myfloor(x);
        int x_c = x_f+1;
        int y_f = myfloor(y);
        int y_c = y_f+1;
        short v1 = PIX(img, x_c, y_c, width, height);
        short v2 = PIX(img, x_c, y_f, width, height);
        short v3 = PIX(img, x_f, y_c, width, height);
        short v4 = PIX(img, x_f, y_f, width, height);
        float s  = (v1*(x - x_f)+v3*(x_c - x))*(y - y_f) +
                   (v2*(x - x_f) + v4*(x_c - x))*(y_c - y);
        *rv = (unsigned char)s;
    }
}
/**
 * interpolateN: Bi-linear interpolation function for N channel image.
 *
 * Parameters:
 *             rv: destination pixel (call by reference)
 *            x,y: the source coordinates in the image img. Note this
 *                 are real-value coordinates, that's why we interpolate
 *            img: source image
 *   width,height: dimension of image
 *              N: number of channels
 *        channel: channel number (0..N-1)
 *            def: default value if coordinates are out of range
 * Return value:  None
 */
void _FLT(interpolateN)(unsigned char *rv, float x, float y,
                        unsigned char* img, int width, int height,
                        unsigned char N, unsigned char channel,
                        unsigned char def)
{
    if (x < - 1 || x > width || y < -1 || y > height) {
        *rv = def;
    } else {
        int x_f = myfloor(x);
        int x_c = x_f+1;
        int y_f = myfloor(y);
        int y_c = y_f+1;
        short v1 = PIXELN(img, x_c, y_c, width, height, N, channel, def);
        short v2 = PIXELN(img, x_c, y_f, width, height, N, channel, def);
        short v3 = PIXELN(img, x_f, y_c, width, height, N, channel, def);
        short v4 = PIXELN(img, x_f, y_f, width, height, N, channel, def);
        float s  = (v1*(x - x_f)+v3*(x_c - x))*(y - y_f) +
                   (v2*(x - x_f) + v4*(x_c - x))*(y_c - y);
        *rv = (unsigned char)s;
    }
}
/** interpolateLin: linear (only x) interpolation function, see interpolate */
void _FLT(interpolateLin)(unsigned char *rv, float x, float y,
                          unsigned char* img, int width, int height,
                          unsigned char def)
{
    int x_f = myfloor(x);
    int x_c = x_f+1;
    int y_n = myround(y);
    float v1 = PIXEL(img, x_c, y_n, width, height, def);
    float v2 = PIXEL(img, x_f, y_n, width, height, def);
    float s  = v1*(x - x_f) + v2*(x_c - x);
    *rv = (unsigned char)s;
}
Exemple #7
0
int set_base(INT loc)
{
  if (loc < 0) loc = 0;

  if (!tryloc(loc)) return FALSE;
  base = loc;
  readFile();

  if (mode != bySector && nbBytes < page - lineLength && base != 0) {
    base -= myfloor(page - nbBytes - lineLength, lineLength);
    if (base < 0) base = 0;
    readFile();
  }

  if (cursor > nbBytes) cursor = nbBytes;
  return TRUE;
}
Exemple #8
0
void initCurses(void)
{
  initscr();

#ifdef HAVE_COLORS
  if (colored) {
    start_color();
    use_default_colors();
    init_pair(1, COLOR_RED, -1);   /* null zeros */
    init_pair(2, COLOR_GREEN, -1); /* control chars */
    init_pair(3, COLOR_BLUE, -1);  /* extended chars */
  }
#endif

  refresh();
  raw();
  noecho();
  keypad(stdscr, TRUE);

  if (mode == bySector) {
    lineLength = modes[bySector].lineLength;
    page = modes[bySector].page;
    page = myfloor((LINES - 1) * lineLength, page);
    blocSize = modes[bySector].blocSize;
    if (computeLineSize() > COLS) DIE("%s: term is too small for sectored view (width)\n");
    if (page == 0) DIE("%s: term is too small for sectored view (height)\n");
  } else { /* mode == maximized */
    if (LINES <= 4) DIE("%s: term is too small (height)\n");

    blocSize = modes[maximized].blocSize;
    if (lineLength == 0) {
      for (lineLength = blocSize; computeLineSize() <= COLS; lineLength += blocSize);
      lineLength -= blocSize;
      if (lineLength == 0) DIE("%s: term is too small (width)\n");
    } else {
      if (computeLineSize() > COLS)
	DIE("%s: term is too small (width) for selected line length\n");
    }
    page = lineLength * (LINES - 1);
  }
  colsUsed = computeLineSize();
  buffer = malloc(page);
  bufferAttr = malloc(page * sizeof(*bufferAttr));
}
Exemple #9
0
int myround(double x) {
	if ((x - floor(x)) > 0.5)
		return (myceiling(x));
	else
		return (myfloor(x));
}
void adc_calibration(int via_fpga, int fd, unsigned short addr, unsigned char *pval)
{
	unsigned char data[40];
	unsigned char data0[40] = {0  ,
0  ,
0  ,
36 ,
36 ,
0  ,
0  ,
123,
42 ,
59 ,
74 ,
26 ,
77 ,
24 ,
0  ,
126,
125,
126,
72 ,
71 ,
72 ,
75 ,
74 ,
75 ,
46 ,
176,
49 ,
28 ,
176,
49 ,
28 ,
176,
49 ,
55 ,
56 ,
64 ,
64 ,
44 ,
0  ,
0  ,
};
	unsigned int rxbbf_c3_msb, rxbbf_c3_lsb, rxbbf_r2346;
	float scale_snr_dB, rc_timeConst, scale_res, scale_cap, scale_snr, maxsnr;
	float BBBW_MHz, FsADC;//需确定
	BBBW_MHz = 9;
	FsADC = 491.52;
	rxbbf_c3_msb = Ad9361ReadReg(via_fpga, fd, 0x1eb);
	rxbbf_c3_lsb = Ad9361ReadReg(via_fpga, fd, 0x1ec);
	rxbbf_r2346 = Ad9361ReadReg(via_fpga, fd, 0x1e6);
	if(BBBW_MHz > 28)
	{
		BBBW_MHz = 28;
	}
	else if(BBBW_MHz < 0.2)
	{
		BBBW_MHz = 0.2;
	}
	scale_snr_dB = (FsADC < 80) ? (0):(2);
	if(BBBW_MHz < 18)
	{
		rc_timeConst = 1/((1.4 * 2 * PI) * (18300 * rxbbf_r2346) * (160e-15 * rxbbf_c3_msb + 10e-15 * rxbbf_c3_lsb + 140e-15) * (BBBW_MHz * 1e6));
	}
	else
	{
		rc_timeConst = 1/((1.4 * 2 * PI) * (18300 * rxbbf_r2346) * (160e-15 * rxbbf_c3_msb + 10e-15 * rxbbf_c3_lsb + 140e-15) * (BBBW_MHz * 1e6) * (1 + 0.01 * (BBBW_MHz - 18)));
	}
	scale_res = sqrt(1 / rc_timeConst);
	scale_cap = sqrt(1 / rc_timeConst);
	scale_snr = pow(10, (scale_snr_dB/10));
	maxsnr = 640/160;
	data[0] = 0;
	data[1] = 0;
	data[2] = 0;
	data[3] = 0x24;
	data[4] = 0x24;
	data[5] = 0;
	data[6] = 0;
	data[7] = min(124, myfloor(-0.5 + 80 * scale_snr * scale_res * min(1, sqrt(maxsnr * FsADC / 640))));
	data[8] = min(255, myfloor(0.5 + 20 * (640 / FsADC) * (data[7] / 80.0) / (scale_res * scale_cap)));
	data[10] = min(127, myfloor(-0.5 + 77 * scale_res * min(1, sqrt(maxsnr * FsADC / 640))));
	data[9] = min(127, myfloor(0.8 * data[10]));
	data[11] = min(255, myfloor(0.5 + 20 * (640 / FsADC) * (data[10] / 77.0) / (scale_res * scale_cap)));
	data[12] = min(127, myfloor(-0.5 + 80 * scale_res * min(1, sqrt(maxsnr * FsADC / 640))));
	data[13] = min(255, myfloor(-1.5 + 20 * (640 / FsADC) * (data[12] / 80.0) / (scale_res * scale_cap)));
	data[14] = 21 * myfloor(0.1 * 640 / FsADC);
	data[15] = min(127, myround(1.025 * data[7]));
	data[16] = min(127, myfloor(data[15] * (0.98 + 0.02 * max(1, (640 / FsADC) / maxsnr))));
	data[17] = data[15];
	data[18] = min(127, myround(0.975 * data[10]));
	data[19] = min(127, myfloor(data[18] * (0.98 + 0.02 * max(1, (640 / FsADC) / maxsnr))));
	data[20] = data[18];
	data[21] = min(127, myround(0.975 * data[12]));
	data[22] = min(127, myfloor(data[21] * (0.98 + 0.02 * max(1, (640 / FsADC) / maxsnr))));
	data[23] = data[21];
	data[24] = 0x2e;
	data[25] = myfloor(128 + min(63, 63 * (FsADC / 640)));
	data[26] = myfloor(0 + min(63, 63 * (FsADC / 640) * (0.92 + 0.08 * (640 / FsADC))));
	data[27] = myfloor(0 + min(63, 32 * sqrt(FsADC / 640)));
	data[28] = myfloor(128 + min(63, 63 * (FsADC / 640)));
	data[29] = myfloor(0 + min(63, 63 * (FsADC / 640) * (0.92 + 0.08 * (640 / FsADC))));
	data[30] = myfloor(0 + min(63, 32 * sqrt(FsADC / 640)));
	data[31] = myfloor(128 + min(63, 63 * (FsADC / 640)));
	data[32] = myfloor(0 + min(63, 63 * (FsADC / 640) * (0.92 + 0.08 * (640 / FsADC))));
	data[33] = myfloor(0 + min(63, 63 * sqrt(FsADC / 640)));
	data[34] = min(127, myfloor(64 * sqrt(FsADC / 640)));
	data[35] = 0x40;
	data[36] = 0x40;
	data[37] = 0x2c;
	data[38] = 0x0;
	data[39] = 0x0;
	
	*pval = data[addr-0x200];
}