コード例 #1
0
// creates the error texture for fe and stores it in texture
int Error3DViewerWidget::fillTexture(const struct face_error *fe,
				     GLubyte *texture) const 
{
  int i,j,i2,j2,k,n,sz,cidx;
  GLubyte r=0, g=0, b=0; // to keep compiler happy
  float drange;
  float e1,e2,e3;

  n = fe->sample_freq;
  if (n == 0) { /* no samples, using no error value gray */
    for (i=0, k=0; i<9; i++) { /* set border and center to no_err_value */
      texture[k++] = (GLubyte) (255*no_err_value);
      texture[k++] = (GLubyte) (255*no_err_value);
      texture[k++] = (GLubyte) (255*no_err_value);
    }
    return 1;
  } else {
    sz = 1<<ceilLog2(n);
    drange = model->max_error - model->min_error;
    if (drange < FLT_MIN*100) drange = 1;
    for (i2=-1, k=0; i2<=sz; i2++) {
      i = (i2 >= 0) ? ((i2 < sz) ? i2 : sz-1) : 0;
      for (j2=-1; j2<=sz; j2++) {
        j = (j2 >= 0) ? ((j2 < sz) ? j2 : sz-1) : 0;
        if (i<n && j<(n-i)) { /* sample point */
          cidx = (int) (CMAP_LENGTH*(fe->serror[j+i*(2*n-i+1)/2]-
                                     model->min_error)/drange);
          if (cidx >= CMAP_LENGTH) cidx = CMAP_LENGTH-1;
          r = (GLubyte) (255*colormap[cidx][0]);
          g = (GLubyte) (255*colormap[cidx][1]);
          b = (GLubyte) (255*colormap[cidx][2]);
        } else if (j == n-i) {
          /* diagonal border texel, can be used in GL_LINEAR texture mode */
          e1 = (i>0 && j>0) ? fe->serror[(j-1)+(i-1)*(2*n-(i-1)+1)/2] : 0;
          e2 = (j>0) ? fe->serror[(j-1)+i*(2*n-i+1)/2] : 0;
          e3 = (i>0) ? fe->serror[j+(i-1)*(2*n-(i-1)+1)/2] : 0;
          cidx = (int) (CMAP_LENGTH*(e2+e3-e1-model->min_error)/drange);
          if (cidx < 0) {
            cidx = 0;
          } else if (cidx >= CMAP_LENGTH) {
            cidx = CMAP_LENGTH-1;
          }
          r = (GLubyte) (255*colormap[cidx][0]);
          g = (GLubyte) (255*colormap[cidx][1]);
          b = (GLubyte) (255*colormap[cidx][2]);
        } else { /* out of triangle point, this texel will never be used */
          r = g = b = 0; /* black */
        }
        texture[k++] = r;
        texture[k++] = g;
        texture[k++] = b;
      }
    }
    return sz;
  }
}
コード例 #2
0
 // Assume _size is already a power of 2
 // map must point to a memory area written by "write_blocks". No header
 array(char *map, size_t _size, uint_t _key_len, uint_t _val_len,
       uint_t _reprobe_limit, size_t *_reprobes,
       SquareBinaryMatrix &_hash_matrix, 
       SquareBinaryMatrix &_hash_inverse_matrix) :
   lsize(ceilLog2(_size)), size(_size), size_mask(size-1),
   reprobe_limit(_reprobe_limit, _reprobes, size), key_len(_key_len),
   key_mask(key_len <= lsize ? 0 : (((word)1) << (key_len - lsize)) - 1),
   key_off(key_len <= lsize ? 0 : key_len - lsize),
   offsets(key_off + bitsize(reprobe_limit.val() + 1), _val_len,
           reprobe_limit.val() + 1),
   data((word *)map), reprobes(_reprobes),
   hash_matrix(_hash_matrix), hash_inverse_matrix(_hash_inverse_matrix)
 { }
コード例 #3
0
 array(size_t _size, uint_t _key_len, uint_t _val_len,
       uint_t _reprobe_limit, size_t *_reprobes) :
   size(((size_t)1) << ceilLog2(_size)),
   size_mask(size - 1),
   reprobe_limit(_reprobe_limit), 
   offsets(_key_len, _val_len, _reprobe_limit),
   mem_block(div_ceil(size, (size_t)offsets.get_block_len()) * offsets.get_block_word_len() * sizeof(word)),
   data((word *)mem_block.get_ptr()),
   zero_count(0),
   reprobes(_reprobes)
 {
   if(!data) {
     // TODO: should throw an error
     std::cerr << "allocation failed";
   }
 }
コード例 #4
0
 array(size_t _size, uint_t _key_len, uint_t _val_len,
       uint_t _reprobe_limit, size_t *_reprobes) :
   lsize(ceilLog2(_size)), size(((size_t)1) << lsize),
   size_mask(size - 1),
   reprobe_limit(_reprobe_limit, _reprobes, size), key_len(_key_len),
   key_mask(key_len <= lsize ? 0 : (((word)1) << (key_len - lsize)) - 1),
   key_off(key_len <= lsize ? 0 : key_len - lsize),
   offsets(key_off + bitsize(reprobe_limit.val() + 1), _val_len,
           reprobe_limit.val() + 1),
   mem_block(div_ceil(size, (size_t)offsets.get_block_len()) * offsets.get_block_word_len() * sizeof(word)),
   data((word *)mem_block.get_ptr()), reprobes(_reprobes),
   hash_matrix(key_len), 
   hash_inverse_matrix(hash_matrix.init_random_inverse())
 {
   if(!data)
     eraise(ErrorAllocation) << "Failed to allocate " 
                            << (div_ceil(size, (size_t)offsets.get_block_len()) * offsets.get_block_word_len() * sizeof(word))
                            << " bytes of memory";
 }
コード例 #5
0
/********************************************************
  Function Name
  -------------
  static Void cacll_encode()

  Arguments
  ---------
  None.

  
  Description
  -----------
  Encode DC information for one color component.

  Functions Called
  ----------------
  mzte_ac_encoder_init()
  mzte_ac_model_init()
  mzte_ac_encode_symbol()
  mzte_ac_model_done()
  mzte_ac_encoder_done()

  Return Value
  ------------
  None.

********************************************************/ 
Void CVTCEncoder::cacll_encode()
{
  Int dc_h, dc_w,i,j;
	Int numBP, bp; // 1124

  dc_w=mzte_codec.m_iDCWidth;
  dc_h=mzte_codec.m_iDCHeight;

  // 1124
  /* init arithmetic coder */
  numBP = ceilLog2(mzte_codec.m_iMaxDC+1); // modified by Sharp (99/2/16)
  mzte_ac_encoder_init(&ace);
  if ((acm_bpdc=(ac_model *)calloc(numBP,sizeof(ac_model)))==NULL)
    errorHandler("Can't allocate memory for prob model.");
  
  for (i=0; i<numBP; i++) {
    acm_bpdc[i].Max_frequency = Bitplane_Max_frequency;
    mzte_ac_model_init(&(acm_bpdc[i]),2,NULL,ADAPT,1);
  }
  coeffinfo=mzte_codec.m_SPlayer[color].coeffinfo;

//Modified by Sarnoff for error resilience, 3/5/99
 if(mzte_codec.m_usErrResiDisable){ //no error resi case
  for (bp=numBP-1; bp>=0; bp--) {
    for(i=0;i<dc_h;i++)
      for(j=0;j<dc_w;j++){
		 // printf("%d %d \n", i,j);
	if( coeffinfo[i][j].mask == 1) 
	  mzte_ac_encode_symbol(&ace, &(acm_bpdc[bp]),
				((coeffinfo[i][j].quantized_value)>>bp)&1);
      }
  }
  /* close arithmetic coder */
  for (i=0; i<numBP; i++) 
    mzte_ac_model_done(&(acm_bpdc[i]));
  free(acm_bpdc); 
  bit_stream_length=mzte_ac_encoder_done(&ace);
 }
 else{ //error resilience case
コード例 #6
0
// Generate the texture for error display
void Error3DViewerWidget::genErrorTextures() 
{
  static const GLint internalformat = GL_R3_G3_B2;
  GLubyte *texture;
  GLint tw,max_n;
  QString tmps;
  int i;

  // Only in error mapping mode and if not disabled
  if (!texture_enabled) 
    return;
  makeCurrent(); // make sure we use the correct GL context
  // Allocate texture names (IDs) if not present
  if (etex_id == NULL) {
    etex_id = (GLuint*) xa_malloc(sizeof(*etex_id)*model->mesh->num_faces);
    etex_sz = (int*) xa_malloc(sizeof(*etex_sz)*model->mesh->num_faces);
    glGenTextures(model->mesh->num_faces,etex_id);
  }
  // Get maximum texture size
  max_n = 0;
  for (i=0; i<model->mesh->num_faces; i++) {
    if (max_n < model->fe[i].sample_freq) max_n = model->fe[i].sample_freq;
  }
  max_n = 1<<ceilLog2(max_n); // round (towards infinity) to power of two
  // Test if OpenGL implementation can deal with maximum texture size
  // Unfortunately GL_PROXY_TEXTURE_2D fails on IRIX 6.2 for some SGI
  // machines, so use older GL_MAX_TEXTURE_SIZE method.
  glGetIntegerv(GL_MAX_TEXTURE_SIZE,&tw);
  checkGLErrors("error texture size check");
  if (tw < max_n) {
    tmps.sprintf("The OpenGL implementation does not support\n"
                 "the required texture size (%ix%i).\n"
                 "Using plain white color",max_n,max_n);
    QMessageBox::critical(this,"OpenGL texture size exceeded",tmps);
    // Displaying another window can change the current GL context 
    makeCurrent();
    for (i=0; i<model->mesh->num_faces; i++) {
      etex_sz[i] = 1; // avoid having divide by zero texture coords
    }
    return;
  }
  // What follows is a potentially slow operation
  QApplication::setOverrideCursor(Qt::waitCursor);
  // Allocate temporary texture storage
  texture = (GLubyte*) xa_malloc(sizeof(*texture)*3*(max_n+2)*(max_n+2));
  glPixelStorei(GL_UNPACK_ALIGNMENT,1); /* pixel rows aligned on bytes only */
  for (i=0; i<model->mesh->num_faces; i++) {
    glBindTexture(GL_TEXTURE_2D,etex_id[i]);
    etex_sz[i] = fillTexture(&(model->fe[i]),texture);
    glTexImage2D(GL_TEXTURE_2D,0,internalformat,etex_sz[i]+2,etex_sz[i]+2,1,
                 GL_RGB,GL_UNSIGNED_BYTE,texture);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP);
    // Default GL_TEXTURE_MIN_FILTER requires mipmaps!
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
  }
  checkGLErrors("error texture generation");
  free(texture);
  QApplication::restoreOverrideCursor();
}