static int setupScreenKeyboardButton( int buttonID, Uint8 * charBuf )
{
	// TODO: softstretch with antialiasing
	int w, h, len, format;
	GLTexture_t * data = NULL;
	int texture_w, texture_h;
	
	if( buttonID < 5 )
		data = &(arrowImages[buttonID]);
	else
	if( buttonID < 9 )
		data = &(buttonAutoFireImages[buttonID-5]);
	else
		data = &(buttonImages[buttonID-9]);

	if( buttonID > 22 ) // Error, array too big
		return 12; // Return value bigger than zero to iterate it

	memcpy(&w, charBuf, sizeof(int));
	memcpy(&h, charBuf + sizeof(int), sizeof(int));
	memcpy(&format, charBuf + 2*sizeof(int), sizeof(int));
	w = ntohl(w);
	h = ntohl(h);
	format = ntohl(format);
	
	texture_w = power_of_2(w);
	texture_h = power_of_2(h);
	data->w = w;
	data->h = h;

	glEnable(GL_TEXTURE_2D);

	glGenTextures(1, &data->id);
	glBindTexture(GL_TEXTURE_2D, data->id);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture_w, texture_h, 0, GL_RGBA,
					format ? GL_UNSIGNED_SHORT_4_4_4_4 : GL_UNSIGNED_SHORT_5_5_5_1, NULL);
	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
	
	glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_RGBA,
						format ? GL_UNSIGNED_SHORT_4_4_4_4 : GL_UNSIGNED_SHORT_5_5_5_1,
						charBuf + 3*sizeof(int) );

	glDisable(GL_TEXTURE_2D);

	return 3*sizeof(int) + w * h * 2;
}
예제 #2
0
static int setupScreenKeyboardButton( int buttonID, Uint8 * charBuf )
{
	// TODO: softstretch with antialiasing
	int w, h,  format;
	GLTexture_t * data = NULL;
	int texture_w, texture_h;
	
	if( buttonID < 1 )
		data = &arrowImages;
	else
		data = &(buttonImages[buttonID-1]);


	memcpy(&w, charBuf, sizeof(int));
	memcpy(&h, charBuf + sizeof(int), sizeof(int));
	memcpy(&format, charBuf + 2*sizeof(int), sizeof(int));
	w = ntohl(w);
	h = ntohl(h);
	format = ntohl(format);
	
	texture_w = power_of_2(w);
	texture_h = power_of_2(h);
	data->w = texture_w;
	data->h = texture_h;
	LOGI("data w:%d, h:%d\n", w, h);

	qglEnable(GL_TEXTURE_2D);

	qglGenTextures(1, &data->id);
	
	qglBindTexture(GL_TEXTURE_2D, data->id);
	LOGI("On-screen keyboard generated OpenGL texture ID %x", data->id);

	qglTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture_w, texture_h, 0, GL_RGBA,
					format ? GL_UNSIGNED_SHORT_4_4_4_4 : GL_UNSIGNED_SHORT_5_5_5_1, NULL);
	qglPixelStorei(GL_UNPACK_ALIGNMENT, 1);
	
	qglTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_RGBA,
						format ? GL_UNSIGNED_SHORT_4_4_4_4 : GL_UNSIGNED_SHORT_5_5_5_1,
						charBuf + 3*sizeof(int) );

	qglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	qglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

	qglDisable(GL_TEXTURE_2D);

	return 3*sizeof(int) + w * h * 2;
}
JNIEXPORT void JNICALL 
JAVA_EXPORT_NAME(Settings_nativeSetupScreenKeyboardButton) ( JNIEnv*  env, jobject thiz, jint buttonID, jbyteArray charBufJava )
{
	// TODO: softstretch with antialiasing
	jboolean isCopy = JNI_TRUE;
	Uint8 * charBuf = NULL;
	int w, h, len, format;
	GLTexture_t * data = NULL;
	int texture_w, texture_h;
	len = (*env)->GetArrayLength(env, charBufJava);
	charBuf = (Uint8 *) (*env)->GetByteArrayElements(env, charBufJava, &isCopy);
	
	w = ntohl(((Uint32 *) charBuf)[0]);
	h = ntohl(((Uint32 *) charBuf)[1]);
	format = ntohl(((Uint32 *) charBuf)[2]);
	if( buttonID < 5 )
		data = &(arrowImages[buttonID]);
	else
	if( buttonID < 9 )
		data = &(buttonAutoFireImages[buttonID-5]);
	else
		data = &(buttonImages[buttonID-9]);
	
	texture_w = power_of_2(w);
	texture_h = power_of_2(h);
	data->w = w;
	data->h = h;

	glEnable(GL_TEXTURE_2D);

	glGenTextures(1, &data->id);
	glBindTexture(GL_TEXTURE_2D, data->id);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture_w, texture_h, 0, GL_RGBA,
					format ? GL_UNSIGNED_SHORT_4_4_4_4 : GL_UNSIGNED_SHORT_5_5_5_1, NULL);
	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
	
	glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_RGBA,
						format ? GL_UNSIGNED_SHORT_4_4_4_4 : GL_UNSIGNED_SHORT_5_5_5_1,
						charBuf + 12 );

	glDisable(GL_TEXTURE_2D);

	(*env)->ReleaseByteArrayElements(env, charBufJava, (jbyte *)charBuf, 0);
}
예제 #4
0
boolean_t
vm_external_within(
	vm_size_t	new_size,
	vm_size_t	old_size)
{
	vm_size_t 	new_bytes;
	vm_size_t 	old_bytes;

	assert(new_size >= old_size);

	/*
	 * "old_bytes" is calculated to be the actual amount of space
	 * allocated for a map of size "old_size".
	 */
	old_bytes = stob(old_size);
	if (old_bytes <= SMALL_SIZE) old_bytes = SMALL_SIZE;
	else if (old_bytes <= LARGE_SIZE) old_bytes = power_of_2(old_bytes);

	/*
	 * "new_bytes" is the map size required to map the "new_size" object.
	 * Since the rounding algorithms are the same, we needn't actually
	 * round up new_bytes to get the correct answer
	 */
	new_bytes = stob(new_size);

	return(new_bytes <= old_bytes);
}
예제 #5
0
파일: hamming.c 프로젝트: mattlawer/hamming
void add_parity_space(char *string) {
	int i,j, len=strlen(string);
	for (i=0; i<len; i++) {
		if (power_of_2(i+1)) {
			len+=1;
			for (j = len-1 ; j>i; j--) {
				string[j]=string[j-1];
			}
			string[i]='0';
			string[len] = '\0';
		}
	}
}
예제 #6
0
static int view_all_exec(bContext *C, wmOperator *op)
{
	SpaceClip *sc;
	ARegion *ar;
	int w, h, width, height;
	float aspx, aspy;
	int fit_view = RNA_boolean_get(op->ptr, "fit_view");
	float zoomx, zoomy;

	/* retrieve state */
	sc = CTX_wm_space_clip(C);
	ar = CTX_wm_region(C);

	ED_space_clip_get_size(sc, &w, &h);
	ED_space_clip_get_aspect(sc, &aspx, &aspy);

	w = w * aspx;
	h = h * aspy;

	/* check if the image will fit in the image with zoom == 1 */
	width  = BLI_rcti_size_x(&ar->winrct) + 1;
	height = BLI_rcti_size_y(&ar->winrct) + 1;

	if (fit_view) {
		const int margin = 5; /* margin from border */

		zoomx = (float) width / (w + 2 * margin);
		zoomy = (float) height / (h + 2 * margin);

		sclip_zoom_set(C, min_ff(zoomx, zoomy), NULL);
	}
	else {
		if ((w >= width || h >= height) && (width > 0 && height > 0)) {
			zoomx = (float) width / w;
			zoomy = (float) height / h;

			/* find the zoom value that will fit the image in the image space */
			sclip_zoom_set(C, 1.0f / power_of_2(1.0f / min_ff(zoomx, zoomy)), NULL);
		}
		else
			sclip_zoom_set(C, 1.0f, NULL);
	}

	sc->xof = sc->yof = 0.0f;

	ED_region_tag_redraw(CTX_wm_region(C));

	return OPERATOR_FINISHED;
}
예제 #7
0
/*
 * Return the number of bytes needed for a vm_external_map given the
 * size of the object to be mapped, i.e. the size of the map that was
 * created by vm_external_create.
 */
vm_size_t
vm_external_map_size(
	vm_offset_t	size)
{
	vm_size_t	bytes;

	bytes = stob(size);
	if (bytes != 0)
	        if (bytes <= SMALL_SIZE) {
			bytes = SMALL_SIZE;
		} else {
			bytes = power_of_2(bytes);
		}
	return bytes;
}
/* 
 * Compute 2D DFT on double data:
 * forward if direction==FFT_FORWARD,
 * inverse if direction==FFT_INVERSE.
 */
int fft2d(DCOMPLEX *array, int rows, int cols, int direction)
{
  int i, maxsize, errflag;
  
  if(!power_of_2(rows) || !power_of_2(cols)) {
    handle_error("fft: input array must have dimensions a power of 2");
    return(ERROR);
  }
  
  /* Allocate 1D buffer */
  bigBuffd = array;
  maxsize = rows>cols ? rows : cols;
  errflag = allocateBuffer(maxsize);
  if(errflag != NO_ERROR) return(errflag);

  /* Compute transform row by row */
  if(cols>1)
    for(i=0;i<rows;i++) 
      {
      	LoadRow(bigBuffd,i,cols);
      	FFT842(direction,cols,stageBuff);
      	StoreRow(bigBuffd,i,cols);
      }
  
  /* Compute transform column by column */
  if(rows>1)
    for(i=0;i<cols;i++) 
      {
        LoadCol(bigBuffd,i,rows,cols);
        FFT842(direction,rows,stageBuff);
        StoreCol(bigBuffd,i,rows,cols);
      }

  freeBuffer();
  return(NO_ERROR);
}
예제 #9
0
/*
* Modulo Operator
*/
word operator%(const BigInt& n, word mod)
   {
   if(mod == 0)
      throw BigInt::DivideByZero();
   if(power_of_2(mod))
      return (n.word_at(0) & (mod - 1));

   word remainder = 0;

   for(size_t j = n.sig_words(); j > 0; --j)
      remainder = bigint_modop(remainder, n.word_at(j-1), mod);

   if(remainder && n.sign() == BigInt::Negative)
      return mod - remainder;
   return remainder;
   }
예제 #10
0
파일: hamming.c 프로젝트: mattlawer/hamming
void remove_parity_space(char *string) {
	int i = 0, j=0;
	char *data = (char*)malloc(strlen(string)*sizeof(char));
	for (i=0; i<strlen(string); i++) {
		if (!power_of_2(i+1)) {
			data[j]=string[i];
			j++;
		}
	}
	for (i = 0; i < strlen(string); i++) {
		if (i<j)
			string[i]=data[i];
		else 
			string[i]='\0';
	}
	free(data);
}
예제 #11
0
void
vm_external_destroy(
	vm_external_map_t	map,
	vm_size_t		size)
{
	vm_size_t bytes;

	if (map == VM_EXTERNAL_NULL)
		return;

	bytes = stob(size);
	if (bytes <= SMALL_SIZE) {
		bytes = SMALL_SIZE;
	} else {
		bytes = power_of_2(bytes);
	}
	kfree((vm_offset_t)map, bytes);
}
예제 #12
0
bool ED_clip_view_selection(const bContext *C, ARegion *ar, bool fit)
{
	SpaceClip *sc = CTX_wm_space_clip(C);
	int w, h, frame_width, frame_height;
	float min[2], max[2];

	ED_space_clip_get_size(sc, &frame_width, &frame_height);

	if ((frame_width == 0) || (frame_height == 0) || (sc->clip == NULL))
		return false;

	if (!selected_boundbox(sc, min, max))
		return false;

	/* center view */
	clip_view_center_to_point(sc, (max[0] + min[0]) / (2 * frame_width),
	                              (max[1] + min[1]) / (2 * frame_height));

	w = max[0] - min[0];
	h = max[1] - min[1];

	/* set zoom to see all selection */
	if (w > 0 && h > 0) {
		int width, height;
		float zoomx, zoomy, newzoom, aspx, aspy;

		ED_space_clip_get_aspect(sc, &aspx, &aspy);

		width  = BLI_rcti_size_x(&ar->winrct) + 1;
		height = BLI_rcti_size_y(&ar->winrct) + 1;

		zoomx = (float)width / w / aspx;
		zoomy = (float)height / h / aspy;

		newzoom = 1.0f / power_of_2(1.0f / min_ff(zoomx, zoomy));

		if (fit || sc->zoom > newzoom)
			sc->zoom = newzoom;
	}

	return true;
}
예제 #13
0
파일: hamming.c 프로젝트: mattlawer/hamming
void calculate_parity(char *string) {
	int i = 0, j = 0, k = 0, parity;
	for (i=0; i<strlen(string); i++) {
		if (power_of_2(i+1)) {
			j=i;
			parity = 0;
			//printf("check bit %d :",i+1);
			while (j<strlen(string)) {
				for (k=j; k < j+i+1; k++) {
					if (k >= strlen(string) || k==i) {continue;}
					//printf(" %d",k+1);
					parity = (parity+string[k])%2;
				}
				j=k+i+1;
			}
			string[i]=(parity == 0) ? '0' : '1';
			//printf("\n");
		}
	}
	
}
예제 #14
0
vm_external_map_t
vm_external_create(
	vm_offset_t	size)
{
	vm_size_t		bytes;
	vm_external_map_t	result = VM_EXTERNAL_NULL;

	bytes = stob(size);
	if (bytes <= SMALL_SIZE) {
		if ((result = (vm_external_map_t)kalloc(SMALL_SIZE)) != NULL) {
			memset(result, 0, SMALL_SIZE);
		}
	} else if (bytes <= LARGE_SIZE) {
		bytes = power_of_2(bytes);

		if ((result = (vm_external_map_t)kalloc(bytes)) != NULL) {
			memset(result, 0, bytes);
		}
	}
	return(result);
}
예제 #15
0
/*
 * Determine the memory alignment required for I/O buffers.  For
 * direct I/O we request the needed information from the file
 * system; otherwise pointer alignment is fine.  Returns the
 * alignment multiple, or 0 if an error occurs.
 */
static size_t
get_alignment(char *filename, int fd)
{
	struct dioattr dioattr;

	if (! direct)
		return sizeof (void *);

	memset(&dioattr, 0, sizeof dioattr);
	if (xfscntl(filename, fd, DIOINFO, &dioattr) < 0) {
		perror("xfscntl(FIOINFO)");
		return 0;
	}

	/* Make sure the alignment meets the needs of posix_memalign() */

	if (dioattr.d_mem % sizeof (void *) || ! power_of_2(dioattr.d_mem)) {
		perror("d_mem bad");
		return 0;
	}

	/*
	 * Also make sure user doesn't specify a block size that's
	 * incompatible with the underlying file system.
	 */
	if (! dioattr.d_miniosz) {
		perror("miniosz == 0!");
		return 0;
	}
	if (blocksize % dioattr.d_miniosz) {
		fprintf(stderr, "blocksize %d must be a multiple of "
			"%d for direct I/O\n", blocksize, dioattr.d_miniosz);
		return 0;
	}

	return (size_t) dioattr.d_mem;
}
예제 #16
0
파일: hamming.c 프로젝트: mattlawer/hamming
int *bad_parity(char* string) {
	int i=0, j=0, len=strlen(string);
	int *bad_parity = (int *)malloc(sizeof(int));
	char *check = (char*)malloc(len*sizeof(char));
	
	bad_parity[0] = bad_parity[1] = -1;
	strncpy(check, string, len);
	calculate_parity(check);
	//printf("[•] parity_ck '%s' (len:%d)\n",check,(int)strlen(check));
	
	// compare all parity bits
	for(i=0; i<len; i++) {
		if (power_of_2(i+1) && string[i] != check[i]) {
			int *tmp = (int *)realloc(bad_parity, j+1*sizeof(int));
			if (tmp) {bad_parity = tmp;}
			bad_parity[j] = i;
			bad_parity[j+1] = -1;
			j++;
		}
	}
	
	free(check);
	return bad_parity;
}
예제 #17
0
/* *** MAIN *** */
int main(void) {

    //char  indata[4] = {67,7,0,0};    // 135 => 0x43070000
    //char  indata[4] = {62,32,0,0};   // 0.15625 => 0x3e200000
    //char  indata[4] = {66,92,0,0};   // 55 => 0x425c0000
    //char  indata[4] = {63,128,0,0};  // 1 => 0x3f800000
    //char  indata[4] = {67,160,0,0};  // 320 => 0x43a00000
    //char  indata[4] = {195,47,0,0};  // -175 => 0xc32f0000
    char  indata[4] = {193,58,225,72};  // -11.68 => 0xc13ae148

    char* p_binvalue;
    char  bin_data[32];
    char  exponent[8];
    char  mantissa[23];
    float sum;
    int   sign;

    // convert decimal to binary
    for (int i=0; i<4; i++) {
        p_binvalue = decimal2binary(indata[i]);
        printf("Binary string of %d is: %s\n",indata[i],p_binvalue);
        
        // print out every bits
        for (int j=0; j<8; j++) {
	    bin_data[j+i*8] = p_binvalue[j];
        }
    }
    printf("\n");

    // make a 32 bit vector and print it out
    for (int k=0; k<32; k++) {
        printf("%c",*(bin_data+k));
	if (k == 7 || k==15 || k==23) { 
            printf("\n");
        }
    }
    printf("\n");

    // check if the number negative or positive (msb)
    if (*(bin_data) == '1') {
        printf("msb: %c -> ",*(bin_data));
        printf("Negative number\n");
	sign = -1;
    }
    else {
        printf("msb: %c -> ",*(bin_data));
        printf("Positive number\n");
	sign = 1;
    }

    // find exponent, 8 bits, and assign its variable
    printf("Exponent (bin): ");
    for (int k=1; k<9; k++) {
        printf("%c",*(bin_data+k));
	exponent[k-1] = *(bin_data+k);
    }
    printf("\n");

    // make sure end of line is the last chararcter
    exponent[8] = '\n';

    // convert the exponent
    int dec_exponent = bin2dec(BIAS_ON,exponent);
    printf("Exponent (dec): %d\n",dec_exponent);


    // find mantissa, 23 bits, and assign its variable
    printf("Mantissa (bin): ");
    for (int k=9; k<32; k++) {
        printf("%c",*(bin_data+k));
	mantissa[k-9] = *(bin_data+k);
    }
    printf("\n");

    // make sure end of line is the last chararcter
    exponent[23] = '\n';

    int dec_mantissa = bin2dec(BIAS_OFF,mantissa);
    printf("Mantissa (dec): %d\n",dec_mantissa);

    for (int i=0; i<23; i++) {
        if (mantissa[i] == '1') {
	    sum += power(i);
	}
     }
   
    // remember to add implicit leading bit
    printf("sum: %.10f\n",IMPLICIT_BIT+sum);

    float x = power_of_2(dec_exponent);
    printf("x: %f\n",x);    

    printf("------------------------------\n");
    float result = sign*(IMPLICIT_BIT+sum) * x;
    printf("Result: %f\n",result);
    printf("------------------------------\n");

    free(p_binvalue);

    return 0;
}
예제 #18
0
/**************************************************************************
 *
 *  Function:  ubsec_ioctl
 *
 *************************************************************************/
static int 
ubsec_ioctl(struct inode *inode,struct file *filp,unsigned int cmd, unsigned long arg)
{

  long			Retval=0;

  int                   status = 0;
  int                   deadlockctr = 0;
  
  unsigned short        value;

  
  
  /* Simple round robin scheduling of device. We need to increment
     first since the keysetup command may block. */
  
 TheBeginning:

  deadlockctr = 0;
  do {

    /* For diagnostic related stuff do not try any available devices */
    /* Try the intended device or all devices as directed by the command */

    if (cmd >= UBSEC_DEVICEDUMP || cmd == UBSEC_SELFTEST || cmd == UBSEC_FAILDEVICE) {
      break;
    }

    if(++deadlockctr == (NumDevices * 2)) {  /* to be conservative... */
#ifdef DEBUG_FAILOVER
      PRINTK("dispatch found no more devices.\n");
#endif
      return 1; /* error: no more devices */
    }

    if ((++SelectedDevice) == NumDevices)
      SelectedDevice=0;

  } while(GetDeviceStatus(DeviceInfoList[SelectedDevice]));

#ifdef DEBUG_FAILOVER
  printk("\n");
  PRINTK("dsptch-pre: SltdDev=%d,DevStati=%d %d\n", 
	 SelectedDevice, DeviceInfoList[0].DeviceStatus, DeviceInfoList[1].DeviceStatus);
#endif


  switch(cmd) {
#ifdef BCM_OEM_1
  case BCM_OEM_1_IOCTL1:
	BCM_OEM1_IOCTL1_HANDLER();
	break;
  case BCM_OEM_1_IOCTL2:
	BCM_OEM1_IOCTL2_HANDLER();
	break;
#endif /* BCM_OEM_1 */

  case UBSEC_ENCRYPT_DECRYPT_FUNC:
    status = do_encrypt(DeviceInfoList[SelectedDevice].Context, 
			(void *)arg, DeviceInfoList[SelectedDevice].Features);
    break;

  case UBSEC_KEY_SETUP_FUNC:
    status = ubsec_keysetup(DeviceInfoList[SelectedDevice].Context, (void *)arg);
    break;

  case UBSEC_MATH_FUNC:
    status = ubsec_math(DeviceInfoList[SelectedDevice].Context, (void *)arg);
    break;

  case UBSEC_RNG_FUNC:
    if (DeviceInfoList[SelectedDevice].Features & UBSEC_EXTCHIPINFO_RNG)
      status = ubsec_rng(DeviceInfoList[SelectedDevice].Context, (void *)arg);
    else
      status = UBSEC_STATUS_NO_DEVICE;
    break;
    
  case UBSEC_TLS_HMAC_FUNC:
    status = ubsec_tlsmac(DeviceInfoList[SelectedDevice].Context, (void *)arg);
    break;
    
  case UBSEC_SSL_MAC_FUNC:
    status = ubsec_sslmac(DeviceInfoList[SelectedDevice].Context, (void *)arg);
    break;
    
  case UBSEC_SSL_HASH_FUNC:
    status = ubsec_hash(DeviceInfoList[SelectedDevice].Context, (void *)arg);
    break;

  case UBSEC_SSL_DES_FUNC:
    status = ubsec_sslcipher(DeviceInfoList[SelectedDevice].Context, (void *)arg,
			     DeviceInfoList[SelectedDevice].Features);
    break;

  case UBSEC_SSL_ARC4_FUNC:
    if (DeviceInfoList[SelectedDevice].Features & UBSEC_EXTCHIPINFO_ARC4)
      status = ubsec_sslarc4(DeviceInfoList[SelectedDevice].Context, (void *)arg);
    else
      status = UBSEC_STATUS_NO_DEVICE;
    break;

  case UBSEC_CHIPINFO_FUNC:
    status = obsolete_chipinfo(DeviceInfoList[SelectedDevice].Context, (void *)arg);
    break;

  case UBSEC_STATS_FUNC:
    {
      ubsec_stats_io_t IOInfo;
      int device_num;
      if (copy_from_user((void *) &IOInfo,(void *) arg, sizeof(ubsec_stats_io_t)))
        return -EFAULT; 
      device_num  = IOInfo.device_num;


	if ( (device_num >= NumDevices) || (device_num < 0) )
		return -1;

      ubsec_GetStatistics(DeviceInfoList[device_num].Context, &IOInfo.dev_stats);
      if (copy_to_user((void *) arg, (void *) &IOInfo, sizeof(ubsec_stats_io_t)))
        return -EFAULT;
    }
    break;
    
  case UBSEC_EXTCHIPINFO_FUNC:
    if (copy_from_user((void *)&ExtChipInfo, (void *)arg, sizeof(ubsec_chipinfo_io_t)))
      return -EFAULT; 
    if (ExtChipInfo.Status !=sizeof(ubsec_chipinfo_io_t)) {
      UserCopySize = sizeof(ubsec_chipinfo_io_t);
      if (UserCopySize > ExtChipInfo.Status)
	UserCopySize = ExtChipInfo.Status;
      ExtChipInfo.Status = UBSEC_STATUS_NO_DEVICE;
      if (copy_to_user((void *)arg, (void *)&ExtChipInfo, UserCopySize))
        return -EFAULT;
      return(-1);
    }
    else if ((ExtChipInfo.CardNum >= NumDevices) || (ExtChipInfo.CardNum < 0)) {
      ExtChipInfo.CardNum = NumDevices; 
      ExtChipInfo.Status = UBSEC_STATUS_INVALID_PARAMETER; 
    }
    else {
      status = ubsec_chipinfo(DeviceInfoList[ExtChipInfo.CardNum].Context, &ExtChipInfo); 
      ExtChipInfo.NumDevices = NumDevices; 
      ExtChipInfo.Features &= DeviceInfoList[ExtChipInfo.CardNum].Features;
      ExtChipInfo.Status = UBSEC_STATUS_SUCCESS; 
    }
    if (copy_to_user((void *)arg, (void *)&ExtChipInfo, sizeof(ubsec_chipinfo_io_t)))
      return -EFAULT; 
    if (ExtChipInfo.Status != UBSEC_STATUS_SUCCESS)
      return(-1);
    else
      return(0);
    break;
    
  case UBSEC_DEVICEDUMP:
    if (copy_from_user((void *)&PInt_Contents, (void *)arg, sizeof(int)))
      return -EFAULT;
    Retval=DumpDeviceInfo((PInt)&PInt_Contents);
    if (Retval)
      return(-1); /* Error */
    break;

  case UBSEC_FAILDEVICE:
    if (copy_from_user((void *)&PInt_Contents, (void *)arg, sizeof(int)))
      return -EFAULT;
    Retval=FailDevices((PInt)&PInt_Contents);
    if (Retval)
      return(-1); /* Error */
    break;

  case UBSEC_SELFTEST:
#ifdef BCM_OEM_1
	DISABLE_BCM_OEM1();
#endif /*BCM_OEM_1 */
    if (copy_from_user((void *)&PInt_Contents, (void *)arg, sizeof(int)))
      return -EFAULT;
    Retval=TestDevices((PInt)&PInt_Contents);
#ifdef BCM_OEM_1
	ENABLE_BCM_OEM1();
#endif /*BCM_OEM_1 */
    if (Retval)
      return (Retval); /* Error */

  case UBSEC_GETVERSION:
    if (copy_from_user((void *)&PInt_Contents, (void *)arg, sizeof(int)))
      return -EFAULT;
    Retval=GetHardwareVersion((PInt)&PInt_Contents); /* For the moment one card */
    Retval=Retval<<16;
    Retval+=Version;
    #ifdef LINUX_IA64
    return Retval;
    #else
    return(-Retval);
    #endif
    break;

  case UBSEC_GETNUMCARDS:
	if (copy_to_user((void *)arg,&NumDevices,sizeof(int)))
          return -EFAULT;
    return NumDevices;


  case  UBSEC_GET_FUNCTION_PTRS:
	{
	ubsec_Function_Ptrs_t fptrs;
	get_ubsec_Function_Ptrs(&fptrs);
      	if (copy_to_user((void *) arg, (void *) &fptrs, sizeof(ubsec_Function_Ptrs_t)))
          return -EFAULT;
	}
    break;

#ifdef DVT 
  case UBSEC_RESERVED:
    if (copy_from_user((void *)&DVTparams, (void *)arg, sizeof(DVT_Params_t)))
      return -EFAULT;
    if ((DVTparams.CardNum >= NumDevices) || (DVTparams.CardNum < 0)) {
      {PRINTK("Invalid CardNum (%d), must be 0",DVTparams.CardNum);}
      if (NumDevices == 1)
	printk("\n");
      else
	printk("-%d\n",NumDevices-1);
      return -1; 
    }
    switch (DVTparams.Command) {
    case UBSEC_DVT_PAGESIZE: /* Wrapper command */
      DVTparams.OutParameter = Page_Size;
      if (!DVTparams.InParameter) {
	DVTparams.OutParameter = Page_Size = PAGE_SIZE;
	DVTparams.Status = UBSEC_STATUS_SUCCESS;
	Retval = UBSEC_STATUS_SUCCESS;
      }      
      else if ((DVTparams.InParameter > PAGE_SIZE) ||
	       (DVTparams.InParameter < 2)) {
	DVTparams.Status = UBSEC_STATUS_INVALID_PARAMETER;
      }
      else {
	if (!power_of_2(DVTparams.InParameter))
	  DVTparams.InParameter = next_smaller_power_of_2(DVTparams.InParameter);
	DVTparams.OutParameter = Page_Size; 
	Page_Size = DVTparams.InParameter; 
	DVTparams.Status = UBSEC_STATUS_SUCCESS;
	Retval = UBSEC_STATUS_SUCCESS;
      }
      break;
    default:
      /* Pass all other commands down to the SRL */
      Retval=ubsec_dvt_handler((void *)DeviceInfoList[DVTparams.CardNum].Context,(void *)&DVTparams); 
    };
    if (copy_to_user((void *)arg, (void *)&DVTparams, sizeof(DVT_Params_t)))
      return -EFAULT;
    return(Retval);
    break;
#endif /* DVT */

  default:
    return -EINVAL;
  }
  
#ifdef DEBUG_FAILOVER
  PRINTK("dsptch-pst: SltdDev=%d,DevStati=%d %d\n", 
	 SelectedDevice, DeviceInfoList[0].DeviceStatus, DeviceInfoList[1].DeviceStatus);
  if((status == ETIMEDOUT) || (status == -ETIMEDOUT)) {
    PRINTK("dispatch.c: TIMED OUT SelectedDevice=%d, DeviceStatus=%d\n", 
	   SelectedDevice, DeviceInfoList[SelectedDevice].DeviceStatus);
  }
#endif

  switch(status) {
  case 0:
    break;

  case (ETIMEDOUT):
    status = -ETIMEDOUT;
  case (-ETIMEDOUT):
    DeviceInfoList[SelectedDevice].DeviceStatus = TestDevice(SelectedDevice);
    /*  goto TheBeginning; */
    return(status);
    break;
    
  default:
    /*  goto TheBeginning; */
    return(status);
    break;
  }
  
  return 0;
}
예제 #19
0
파일: hamming.c 프로젝트: mattlawer/hamming
int main (int argc, char *argv[], char *arge[]) {
	if (argc < 2) {
		print_usage();
		return 0;
	}
	
	// check if argv[1] is a binary string
	if (!check_binary(argv[1])) {
		fprintf(stderr, "%s is not a binary string\n", argv[1]);
		return -1;
	}
	
	// init rand()
	srand(time(NULL));
	
	// copy the argv[1] message
	// calculate final message length
	// so we don't need to realloc it everytime
	int len = strlen(argv[1]);
    int parity_len = 2;
    for (int i = 0; i<=len; i++) {
        //printf("t:%d - %s\n",t,power_of_2(t+1) ? "YES" : "NO");
        parity_len++;
        if (power_of_2(parity_len)) {
            parity_len++;
        }
    }
    printf("F2^%d -> F2^%d\n",len, parity_len-1);
	char *message = (char*)malloc(parity_len*sizeof(char));
	strncpy(message, argv[1], len+1);
	
	// print the raw binary message
	printf("[•] encoding   '%s' (len:%d)\n",message,len);
	
	// then add spaces for parity bits
	// and calculate them
	add_parity_space(message);
	calculate_parity(message);
	printf("[•] sent       '%s' (len:%d)\n",message,(int)strlen(message));
	
	// copy the message and alter one bit
	char *bad = (char*)malloc(strlen(message)*sizeof(char));
	strncpy(bad, message, strlen(message));
	alter_a_bit(bad);
	
	// print altered message
	printf("[•] recieve    '%s' (len:%d)\n",bad,(int)strlen(bad));
	
	// check parity to correct the altered message
	int *bad_bits = bad_parity(bad);
	int i = 0, sum=0;
	printf("[?] corrupted parity bits :");
	while (bad_bits[i] != -1) {
		sum+=bad_bits[i]+1;
		printf(" %d",bad_bits[i]+1);
		i++;
	}
	printf("\n");
	printf("[?] fixed data bit at index %d\n",sum);
	free(bad_bits);
	
	// correct if necessary
	if (sum>0) {
		bad[sum-1] = (bad[sum-1] == '0') ? '1' : '0';
		printf("[•] corrected  '%s' (len:%d)\n",bad,(int)strlen(bad));
	}else {
		printf("[•] already_ok '%s' (len:%d)\n",bad,(int)strlen(bad));
	}
	
	// remove the parity bits
	remove_parity_space(bad);
	printf("[•] decoding   '%s' (len:%d)\n",bad,(int)strlen(bad));
	
	// compare with original message
	printf("[•] %s\n",strncmp(argv[1],bad,len) == 0 ? "message successfully decoded" : "failed to decode message");
    
    //printf(" in: '%s'\n",argv[1]);
    //printf("out: '%s'\n",bad);
	
	// free memory space
	free(message);
	free(bad);
	
	return 0;
}
예제 #20
0
static int
GL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
{
    GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata;
    GL_TextureData *data;
    GLint internalFormat;
    GLenum format, type;
    int texture_w, texture_h;
    GLenum result;

    GL_ActivateRenderer(renderer);

    if (!convert_format(renderdata, texture->format, &internalFormat,
                        &format, &type)) {
        SDL_SetError("Texture format %s not supported by OpenGL",
                     SDL_GetPixelFormatName(texture->format));
        return -1;
    }

    data = (GL_TextureData *) SDL_calloc(1, sizeof(*data));
    if (!data) {
        SDL_OutOfMemory();
        return -1;
    }

    if (texture->access == SDL_TEXTUREACCESS_STREAMING) {
        size_t size;
        data->pitch = texture->w * SDL_BYTESPERPIXEL(texture->format);
        size = texture->h * data->pitch;
        if (texture->format == SDL_PIXELFORMAT_YV12 ||
            texture->format == SDL_PIXELFORMAT_IYUV) {
            /* Need to add size for the U and V planes */
            size += (2 * (texture->h * data->pitch) / 4);
        }
        data->pixels = SDL_malloc(size);
        if (!data->pixels) {
            SDL_OutOfMemory();
            SDL_free(data);
            return -1;
        }
    }

    texture->driverdata = data;

    renderdata->glGetError();
    renderdata->glGenTextures(1, &data->texture);
    if (renderdata->GL_ARB_texture_rectangle_supported) {
        data->type = GL_TEXTURE_RECTANGLE_ARB;
        texture_w = texture->w;
        texture_h = texture->h;
        data->texw = (GLfloat) texture_w;
        data->texh = (GLfloat) texture_h;
    } else {
        data->type = GL_TEXTURE_2D;
        texture_w = power_of_2(texture->w);
        texture_h = power_of_2(texture->h);
        data->texw = (GLfloat) (texture->w) / texture_w;
        data->texh = (GLfloat) texture->h / texture_h;
    }

    data->format = format;
    data->formattype = type;
    data->scaleMode = GL_LINEAR;
    renderdata->glEnable(data->type);
    renderdata->glBindTexture(data->type, data->texture);
    renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_S,
                                GL_CLAMP_TO_EDGE);
    renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_T,
                                GL_CLAMP_TO_EDGE);
#ifdef __MACOSX__
#ifndef GL_TEXTURE_STORAGE_HINT_APPLE
#define GL_TEXTURE_STORAGE_HINT_APPLE       0x85BC
#endif
#ifndef STORAGE_CACHED_APPLE
#define STORAGE_CACHED_APPLE                0x85BE
#endif
#ifndef STORAGE_SHARED_APPLE
#define STORAGE_SHARED_APPLE                0x85BF
#endif
    if (texture->access == SDL_TEXTUREACCESS_STREAMING) {
        renderdata->glTexParameteri(data->type, GL_TEXTURE_STORAGE_HINT_APPLE,
                                    GL_STORAGE_SHARED_APPLE);
    } else {
        renderdata->glTexParameteri(data->type, GL_TEXTURE_STORAGE_HINT_APPLE,
                                    GL_STORAGE_CACHED_APPLE);
    }
    if (texture->access == SDL_TEXTUREACCESS_STREAMING
        && texture->format == SDL_PIXELFORMAT_ARGB8888) {
        renderdata->glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE);
        renderdata->glTexImage2D(data->type, 0, internalFormat, texture_w,
                                 texture_h, 0, format, type, data->pixels);
    }
    else
#endif
    {
        renderdata->glTexImage2D(data->type, 0, internalFormat, texture_w,
                                 texture_h, 0, format, type, NULL);
    }
    renderdata->glDisable(data->type);
    result = renderdata->glGetError();
    if (result != GL_NO_ERROR) {
        GL_SetError("glTexImage2D()", result);
        return -1;
    }

    if (texture->format == SDL_PIXELFORMAT_YV12 ||
        texture->format == SDL_PIXELFORMAT_IYUV) {
        data->yuv = SDL_TRUE;

        renderdata->glGenTextures(1, &data->utexture);
        renderdata->glGenTextures(1, &data->vtexture);
        renderdata->glEnable(data->type);

        renderdata->glBindTexture(data->type, data->utexture);
        renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_S,
                                    GL_CLAMP_TO_EDGE);
        renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_T,
                                    GL_CLAMP_TO_EDGE);
        renderdata->glTexImage2D(data->type, 0, internalFormat, texture_w/2,
                                 texture_h/2, 0, format, type, NULL);

        renderdata->glBindTexture(data->type, data->vtexture);
        renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_S,
                                    GL_CLAMP_TO_EDGE);
        renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_T,
                                    GL_CLAMP_TO_EDGE);
        renderdata->glTexImage2D(data->type, 0, internalFormat, texture_w/2,
                                 texture_h/2, 0, format, type, NULL);

        renderdata->glDisable(data->type);
    }
    return 0;
}
    L_tmp = mac_16by16_to_int32(L_tmp, pred[2], past_qua_en[2]);      /* Q13*Q10 -> Q24 */
    L_tmp = mac_16by16_to_int32(L_tmp, pred[3], past_qua_en[3]);      /* Q13*Q10 -> Q24 */

    gcode0 = extract_h(L_tmp);             /* From Q24 to Q8  */

    /*
     * gcode0 = pow(10.0, gcode0/20)
     *        = pow(2, 3.321928*gcode0/20)
     *        = pow(2, 0.166096*gcode0)
     */

    L_tmp = ((int32)gcode0 * 5443) >> 7;      /* *0.166096 in Q15 -> Q24     */

    int32_to_dpf(L_tmp, &exp_gcode0, &frac);  /* Extract exponant of gcode0  */

    gcode0 = (int16)(power_of_2(14, frac));    /* Put 14 as exponant so that  */
    /* output of Pow2() will be:   */
    /* 16384 < Pow2() <= 32767     */
    exp_gcode0 -= 14;

    /* Read the quantized gains */

    //读取量化增益
    if (nbits == 6)
    {
        p = &t_qua_gain6b[index<<1];
    }
    else
    {
        p = &t_qua_gain7b[index<<1];
    }
예제 #22
0
static int
GLES_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
{
    GLES_RenderData *renderdata = (GLES_RenderData *) renderer->driverdata;
    GLES_TextureData *data;
    GLint internalFormat;
    GLenum format, type;
    int texture_w, texture_h;
    GLenum result;

    switch (texture->format) {
    case SDL_PIXELFORMAT_BGR24:
        internalFormat = GL_RGB;
        format = GL_RGB;
        type = GL_UNSIGNED_BYTE;
        break;
    case SDL_PIXELFORMAT_ABGR8888:
        internalFormat = GL_RGBA;
        format = GL_RGBA;
        type = GL_UNSIGNED_BYTE;
        break;
    case SDL_PIXELFORMAT_BGR565:
        internalFormat = GL_RGB;
        format = GL_RGB;
        type = GL_UNSIGNED_SHORT_5_6_5;
        break;
    case SDL_PIXELFORMAT_ABGR1555:
        internalFormat = GL_RGBA;
        format = GL_RGBA;
        type = GL_UNSIGNED_SHORT_5_5_5_1;
        break;
    case SDL_PIXELFORMAT_ABGR4444:
        internalFormat = GL_RGBA;
        format = GL_RGBA;
        type = GL_UNSIGNED_SHORT_4_4_4_4;
        break;
    default:
        SDL_SetError("Unsupported by OpenGL ES texture format");
        return -1;
    }

    data = (GLES_TextureData *) SDL_calloc(1, sizeof(*data));
    if (!data) {
        SDL_OutOfMemory();
        return -1;
    }

    if (texture->access == SDL_TEXTUREACCESS_STREAMING) {
        data->pitch = texture->w * SDL_BYTESPERPIXEL(texture->format);
        data->pixels = SDL_malloc(texture->h * data->pitch);
        if (!data->pixels) {
            SDL_OutOfMemory();
            SDL_free(data);
            return -1;
        }
    }

    texture->driverdata = data;

    renderdata->glGetError();
    renderdata->glEnable(GL_TEXTURE_2D);
    renderdata->glGenTextures(1, &data->texture);

    data->type = GL_TEXTURE_2D;
    /* no NPOV textures allowed in OpenGL ES (yet) */
    texture_w = power_of_2(texture->w);
    texture_h = power_of_2(texture->h);
    data->texw = (GLfloat) texture->w / texture_w;
    data->texh = (GLfloat) texture->h / texture_h;

    data->format = format;
    data->formattype = type;
    renderdata->glBindTexture(data->type, data->texture);
    renderdata->glTexParameteri(data->type, GL_TEXTURE_MIN_FILTER,
                                GL_NEAREST);
    renderdata->glTexParameteri(data->type, GL_TEXTURE_MAG_FILTER,
                                GL_NEAREST);
    renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_S,
                                GL_CLAMP_TO_EDGE);
    renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_T,
                                GL_CLAMP_TO_EDGE);

    renderdata->glTexImage2D(data->type, 0, internalFormat, texture_w,
                             texture_h, 0, format, type, NULL);
    renderdata->glDisable(GL_TEXTURE_2D);

    result = renderdata->glGetError();
    if (result != GL_NO_ERROR) {
        GLES_SetError("glTexImage2D()", result);
        return -1;
    }
    return 0;
}
예제 #23
0
void set_up_ztransverse(ZTRANSVERSE *ztransverse, RUN *run, long pass, long particles, CHARGE *charge,
                        double timeSpan)
{
  long i, nfreq;
  double df;

  if (charge) {
    ztransverse->macroParticleCharge = charge->macroParticleCharge;
  } else if (pass==0) {
    ztransverse->macroParticleCharge = 0;
    if (ztransverse->charge<0)
      bombElegant("ZTRANSVERSE charge parameter should be non-negative. Use change_particle to set particle charge state.", NULL);
#if (!USE_MPI)
    if (particles)
      ztransverse->macroParticleCharge = ztransverse->charge/particles;
#else
      if (USE_MPI) {
	long particles_total;

	MPI_Allreduce(&particles, &particles_total, 1, MPI_LONG, MPI_SUM, workers);
	if (particles_total)
	  ztransverse->macroParticleCharge = ztransverse->charge/particles_total;  
      } 
#endif
  }

  if (ztransverse->initialized)
    return;

  ztransverse->SDDS_wake_initialized = 0;

  if (ztransverse->broad_band) {
    /* Use impedance Z = -i*wr/w*Rs/(1 + i*Q(w/wr-wr/w))
       */
    double term;
    if (ztransverse->bin_size<=0)
      bombElegant("bin_size must be positive for ZTRANSVERSE element", NULL);
    if (ztransverse->n_bins%2!=0)
      bombElegant("ZTRANSVERSE element must have n_bins divisible by 2", NULL);
    if (ztransverse->ZxReal || ztransverse->ZxImag ||
        ztransverse->ZyReal || ztransverse->ZyImag )
      bombElegant("can't specify both broad_band impedance and Z(f) files for ZTRANSVERSE element", NULL);

    optimizeBinSettingsForImpedance(timeSpan, ztransverse->freq, ztransverse->Q,
                                    &(ztransverse->bin_size), &(ztransverse->n_bins),
                                    ztransverse->max_n_bins);
    
    nfreq = ztransverse->n_bins/2 + 1;
    ztransverse->iZ[0] = tmalloc(sizeof(**(ztransverse->iZ))*ztransverse->n_bins);
    ztransverse->iZ[1] = tmalloc(sizeof(**(ztransverse->iZ))*ztransverse->n_bins);
    /* df is the frequency spacing normalized to the resonant frequency */
    df = 1/(ztransverse->n_bins*ztransverse->bin_size)/(ztransverse->freq);
    /* DC term of iZ is 0  */
    ztransverse->iZ[0][0] = ztransverse->iZ[1][0] = 0;
    for (i=1; i<nfreq-1; i++) {
      term = ztransverse->Q*(i*df-1.0/(i*df));
      /* real part of i*Z */
      ztransverse->iZ[0][2*i-1] =  
        ztransverse->iZ[1][2*i-1] =  
	ztransverse->Rs/(i*df)/(1+term*term);
      /* imaginary part of i*Z is -Real[i*Z]*term */
      ztransverse->iZ[0][2*i] = 
        ztransverse->iZ[1][2*i] = 
	-term*ztransverse->iZ[0][2*i-1];
    }
    /* Nyquist term--real part of iZ only */
    term = ztransverse->Q*(1.0/(nfreq*df)-nfreq*df);
    ztransverse->iZ[0][ztransverse->n_bins-1] = 
      ztransverse->iZ[1][ztransverse->n_bins-1] = 
      ztransverse->Rs/(nfreq*df)/(1+term*term);
    df *= ztransverse->freq;
  } else {
    double *ZReal[2], *ZImag[2], *freqData;
    double df_spect;
    long n_spect;
    SDDS_DATASET SDDSin;
    if (!ztransverse->freqColumn || !ztransverse->inputFile)
      bombElegant("you must give an inputFile and freqColumn, or use a broad band model (ZTRANSVERSE)", NULL);
    if (!ztransverse->ZxReal && !ztransverse->ZxImag &&
        !ztransverse->ZyReal && !ztransverse->ZxImag)
      bombElegant("you must either give broad_band=1, or Z[xy]Real and/or Z[xy]Imag (ZTRANSVERSE)", NULL);
    if (!SDDS_InitializeInputFromSearchPath(&SDDSin, ztransverse->inputFile) || !SDDS_ReadPage(&SDDSin)) {
      fprintf(stdout, "unable to read file %s\n", ztransverse->inputFile);
      fflush(stdout);
      SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors); 
      exitElegant(1);
    }
    if ((n_spect=SDDS_RowCount(&SDDSin))<4) {
      fprintf(stdout, "too little data in %s\n", ztransverse->inputFile);
      fflush(stdout);
      exitElegant(1);
    }
    if (!power_of_2(n_spect-1))
      bombElegant("number of spectrum points must be 2^n+1, n>1 (ZTRANSVERSE)", NULL);
    ZReal[0] = getTransverseImpedance(&SDDSin, ztransverse->ZxReal);
    ZImag[0] = getTransverseImpedance(&SDDSin, ztransverse->ZxImag);
    ZReal[1] = getTransverseImpedance(&SDDSin, ztransverse->ZyReal);
    ZImag[1] = getTransverseImpedance(&SDDSin, ztransverse->ZyImag);
    if (!(freqData=SDDS_GetColumnInDoubles(&SDDSin, ztransverse->freqColumn))) {
      fprintf(stdout, "Unable to read column %s (ZTRANSVERSE)\n", ztransverse->freqColumn);
      fflush(stdout);
      exitElegant(1);
    }
    if (!checkPointSpacing(freqData, n_spect, 1e-6)) {
      fprintf(stdout, "Frequency values are not equispaced (ZTRANSVERSE)\n");
      fflush(stdout);
      exitElegant(1);
    }
    if ((df_spect = (freqData[n_spect-1]-freqData[0])/(n_spect-1))<=0) {
      fprintf(stdout, "Zero or negative frequency spacing in %s (ZTRANSVERSE)\n",
              ztransverse->inputFile);
      fflush(stdout);
      exitElegant(1);
    }
    df = df_spect;
    nfreq = n_spect;
    ztransverse->n_bins = 2*(n_spect-1);
    ztransverse->bin_size = 1.0/(ztransverse->n_bins*df_spect);
    if (!SDDS_Terminate(&SDDSin)) {
      fprintf(stdout, "Error closing data set %s\n",
              ztransverse->inputFile);
      fflush(stdout);
      SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors);
      exitElegant(1);
    }
    if (!(ztransverse->iZ[0] =
          calloc(sizeof(*ztransverse->iZ[0]), n_spect*2)) ||
        !(ztransverse->iZ[1] =
          calloc(sizeof(*ztransverse->iZ[1]), n_spect*2)))
      bombElegant("memory allocation failure (ZTRANSVERSE)", NULL);
    for (i=0; i<n_spect; i++) {
      if (i==0) {
        /* DC term */
        ztransverse->iZ[0][i] = -ZImag[0][i];
        ztransverse->iZ[1][i] = -ZImag[1][i];
      } else if (i==n_spect-1 && ztransverse->n_bins%2==0) {
        /* Nyquist term */
        ztransverse->iZ[0][2*i-1] = -ZImag[0][i];
        ztransverse->iZ[1][2*i-1] = -ZImag[1][i];
      } else {
        /* real part of iZ */
        ztransverse->iZ[0][2*i-1] = -ZImag[0][i];
        ztransverse->iZ[1][2*i-1] = -ZImag[1][i];
        /* imaginary part of iZ */
        ztransverse->iZ[0][2*i  ] = ZReal[0][i];
        ztransverse->iZ[1][2*i  ] = ZReal[1][i];
      }
    }
    free(ZReal[0]);
    free(ZReal[1]);
    free(ZImag[0]);
    free(ZImag[1]);
  }

#if (!USE_MPI)
  /* Only the serial version will dump this part of output */
  if (ztransverse->wakes) {
    ztransverse->wakes = compose_filename(ztransverse->wakes, run->rootname);
    if (ztransverse->broad_band) 
      SDDS_ElegantOutputSetup(&ztransverse->SDDS_wake, ztransverse->wakes, SDDS_BINARY, 
			      1, "transverse wake",
			      run->runfile, run->lattice, wake_parameter, BB_WAKE_PARAMETERS,
			      wake_column, WAKE_COLUMNS, "set_up_ztransverse", 
			      SDDS_EOS_NEWFILE|SDDS_EOS_COMPLETE);
    else {
      SDDS_ElegantOutputSetup(&ztransverse->SDDS_wake, ztransverse->wakes, SDDS_BINARY, 
			      1, "transverse wake",
			      run->runfile, run->lattice, wake_parameter, NBB_WAKE_PARAMETERS,
			      wake_column, WAKE_COLUMNS, "set_up_ztransverse", 
			      SDDS_EOS_NEWFILE|SDDS_EOS_COMPLETE);
    }
    ztransverse->SDDS_wake_initialized = 1;
  }
#endif

  if (ztransverse->highFrequencyCutoff0>0) {
    applyLowPassFilterToImpedance(ztransverse->iZ[0], nfreq,
                                  ztransverse->highFrequencyCutoff0, 
                                  ztransverse->highFrequencyCutoff1);
    applyLowPassFilterToImpedance(ztransverse->iZ[1], nfreq,
                                  ztransverse->highFrequencyCutoff0, 
                                  ztransverse->highFrequencyCutoff1);
  }

#if 0
  if (!ztransverse->initialized) {
    FILE *fp;
    fp = fopen_e("ztransverse.sdds", "w", 0);
    fprintf(fp, "SDDS1\n&column name=f units=Hz type=double &end\n");
    fprintf(fp, "&column name=ZReal type=double &end\n");
    fprintf(fp, "&column name=ZImag type=double &end\n");
    fprintf(fp, "&data mode=ascii no_row_counts=1 &end\n");
    for (i=0; i<nfreq; i++) 
      fprintf(fp, "%21.15e %21.15e %21.15e\n",
              i*df, ztransverse->iZ[0][2*i], i>0?-ztransverse->iZ[0][2*i-1]:0);
    fclose(fp);
  }
#endif
  
  ztransverse->initialized = 1;
}
예제 #24
0
static int
GLES_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
{
    GLES_RenderData *renderdata = (GLES_RenderData *) renderer->driverdata;
    GLES_TextureData *data;
    GLint internalFormat;
    GLenum format, type;
    int texture_w, texture_h;
    GLenum scaleMode;
    GLenum result;

    GLES_ActivateRenderer(renderer);

    switch (texture->format) {
    case SDL_PIXELFORMAT_ABGR8888:
        internalFormat = GL_RGBA;
        format = GL_RGBA;
        type = GL_UNSIGNED_BYTE;
        break;
    default:
        return SDL_SetError("Texture format not supported");
    }

    data = (GLES_TextureData *) SDL_calloc(1, sizeof(*data));
    if (!data) {
        return SDL_OutOfMemory();
    }

    if (texture->access == SDL_TEXTUREACCESS_STREAMING) {
        data->pitch = texture->w * SDL_BYTESPERPIXEL(texture->format);
        data->pixels = SDL_calloc(1, texture->h * data->pitch);
        if (!data->pixels) {
            SDL_free(data);
            return SDL_OutOfMemory();
        }
    }

    
    if (texture->access == SDL_TEXTUREACCESS_TARGET) {
        if (!renderdata->GL_OES_framebuffer_object_supported) {
            SDL_free(data);
            return SDL_SetError("GL_OES_framebuffer_object not supported");
        }
        data->fbo = GLES_GetFBO(renderer->driverdata, texture->w, texture->h);
    } else {
        data->fbo = NULL;
    }
    

    renderdata->glGetError();
    renderdata->glEnable(GL_TEXTURE_2D);
    renderdata->glGenTextures(1, &data->texture);
    result = renderdata->glGetError();
    if (result != GL_NO_ERROR) {
        SDL_free(data);
        return GLES_SetError("glGenTextures()", result);
    }

    data->type = GL_TEXTURE_2D;
    /* no NPOV textures allowed in OpenGL ES (yet) */
    texture_w = power_of_2(texture->w);
    texture_h = power_of_2(texture->h);
    data->texw = (GLfloat) texture->w / texture_w;
    data->texh = (GLfloat) texture->h / texture_h;

    data->format = format;
    data->formattype = type;
    scaleMode = GetScaleQuality();
    renderdata->glBindTexture(data->type, data->texture);
    renderdata->glTexParameteri(data->type, GL_TEXTURE_MIN_FILTER, scaleMode);
    renderdata->glTexParameteri(data->type, GL_TEXTURE_MAG_FILTER, scaleMode);
    renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

    renderdata->glTexImage2D(data->type, 0, internalFormat, texture_w,
                             texture_h, 0, format, type, NULL);
    renderdata->glDisable(GL_TEXTURE_2D);

    result = renderdata->glGetError();
    if (result != GL_NO_ERROR) {
        SDL_free(data);
        return GLES_SetError("glTexImage2D()", result);
    }
    
    texture->driverdata = data;
    return 0;
}
static int
GLES_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
{
    GLES_RenderData *renderdata = (GLES_RenderData *) renderer->driverdata;
    GLES_TextureData *data;
    GLint internalFormat;
    GLenum format, type;
    int texture_w, texture_h;
    GLenum result;

    switch (texture->format) {
    case SDL_PIXELFORMAT_RGB24:
        internalFormat = GL_RGB;
        format = GL_RGB;
        type = GL_UNSIGNED_BYTE;
        break;
    case SDL_PIXELFORMAT_BGR888:
    case SDL_PIXELFORMAT_ABGR8888:
        internalFormat = GL_RGBA;
        format = GL_RGBA;
        type = GL_UNSIGNED_BYTE;
        break;
    case SDL_PIXELFORMAT_RGB565:
        internalFormat = GL_RGB;
        format = GL_RGB;
        type = GL_UNSIGNED_SHORT_5_6_5;
        break;
    case SDL_PIXELFORMAT_RGBA5551:
        internalFormat = GL_RGBA;
        format = GL_RGBA;
        type = GL_UNSIGNED_SHORT_5_5_5_1;
        break;
    case SDL_PIXELFORMAT_RGBA4444:
        internalFormat = GL_RGBA;
        format = GL_RGBA;
        type = GL_UNSIGNED_SHORT_4_4_4_4;
        break;
    default:
        SDL_SetError("Texture format %s not supported by OpenGL ES",
                     SDL_GetPixelFormatName(texture->format));
        return -1;
    }

    data = (GLES_TextureData *) SDL_calloc(1, sizeof(*data));
    if (!data) {
        SDL_OutOfMemory();
        return -1;
    }

    if (texture->access == SDL_TEXTUREACCESS_STREAMING) 
    {
        data->pitch = texture->w * SDL_BYTESPERPIXEL(texture->format);
        data->pixels = SDL_malloc(texture->h * data->pitch);
        if (!data->pixels) {
            SDL_OutOfMemory();
            SDL_free(data);
            return -1;
        }
    }

    texture->driverdata = data;

    renderdata->glGetError();
    renderdata->glEnable(GL_TEXTURE_2D);
    renderdata->glGenTextures(1, &data->texture);

    data->type = GL_TEXTURE_2D;
    /* no NPOV textures allowed in OpenGL ES (yet) */
    texture_w = power_of_2(texture->w);
    texture_h = power_of_2(texture->h);
    data->texw = (GLfloat) texture->w / texture_w;
    data->texh = (GLfloat) texture->h / texture_h;
    if( renderer->info.max_texture_width < texture_w || renderer->info.max_texture_height < texture_h )
        __android_log_print(ANDROID_LOG_WARN, "libSDL", "GLES: Allocated texture of size %dx%d which is bigger than largest possible device texture %dx%d",
                            texture_w, texture_h, renderer->info.max_texture_width, renderer->info.max_texture_height );
    else if( texture_w > 1024 || texture_h > 1024 )
        __android_log_print(ANDROID_LOG_WARN, "libSDL", "GLES: Allocated texture of size %dx%d which is bigger than 1024x1024 - this code will not work on HTC G1", texture_w, texture_h );

    data->format = format;
    data->formattype = type;
    renderdata->glBindTexture(data->type, data->texture);
    renderdata->glTexParameteri(data->type, GL_TEXTURE_MIN_FILTER,
                                GL_NEAREST);
    renderdata->glTexParameteri(data->type, GL_TEXTURE_MAG_FILTER,
                                GL_NEAREST);
    renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_S,
                                GL_CLAMP_TO_EDGE);
    renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_T,
                                GL_CLAMP_TO_EDGE);

    renderdata->glTexImage2D(data->type, 0, internalFormat, texture_w,
                             texture_h, 0, format, type, NULL);
    renderdata->glDisable(GL_TEXTURE_2D);

    result = renderdata->glGetError();
    if (result != GL_NO_ERROR) {
        GLES_SetError("glTexImage2D()", result);
        return -1;
    }
    return 0;
}