示例#1
0
static void waterReset(CompScreen * s)
{
	int size, i, j;

	WATER_SCREEN(s);

	ws->height = TEXTURE_SIZE;
	ws->width = (ws->height * s->width) / s->height;

	if (s->textureNonPowerOfTwo ||
	    (POWER_OF_TWO(ws->width) && POWER_OF_TWO(ws->height))) {
		ws->target = GL_TEXTURE_2D;
		ws->tx = ws->ty = 1.0f;
	} else {
		ws->target = GL_TEXTURE_RECTANGLE_NV;
		ws->tx = ws->width;
		ws->ty = ws->height;
	}

	if (!s->fragmentProgram)
		return;

	if (s->fbo) {
		loadWaterProgram(s);
		if (!ws->fbo)
			(*s->genFramebuffers) (1, &ws->fbo);
	}

	ws->fboStatus = 0;

	for (i = 0; i < TEXTURE_NUM; i++) {
		if (ws->texture[i]) {
			glDeleteTextures(1, &ws->texture[i]);
			ws->texture[i] = 0;
		}
	}

	if (ws->data)
		free(ws->data);

	size = (ws->width + 2) * (ws->height + 2);

	ws->data = calloc(1, (sizeof(float) * size * 2) +
			  (sizeof(GLubyte) * ws->width * ws->height * 4));
	if (!ws->data)
		return;

	ws->d0 = ws->data;
	ws->d1 = (ws->d0 + (size));
	ws->t0 = (unsigned char *)(ws->d1 + (size));

	for (i = 0; i < ws->height; i++) {
		for (j = 0; j < ws->width; j++) {
			(ws->t0 + (ws->width * 4 * i + j * 4))[0] = 0xff;
		}
	}
}
示例#2
0
FFT* newFFT(int size)
{
    FFT* fft = (FFT*)malloc(sizeof(FFT));
    if (fft == NULL)
        return NULL;
    
    // Check if the size is a power of two
    assert(POWER_OF_TWO(size));
    fft->size = size;
    fft->sizeOverTwo = fft->size / 2;
    fft->normalize = 1.0 / (2.0 * fft->size);
    
    // create fft setup
    fft->logTwo = log2f(fft->size);
    fft->fftSetup = vDSP_create_fftsetup(fft->logTwo, FFT_RADIX2);
    
    if (fft->fftSetup == 0)
    {
        freeFFT(fft);
        return NULL;
    }

    fft->window = NULL;
    
    return fft;
}
示例#3
0
文件: H5I.c 项目: gang-liu/paraview
/*-------------------------------------------------------------------------
 * Function:  H5I_init_group
 *
 * Purpose:  Initialize an ID group whose ID number is specified by GRP,
 *    If the group has already been initialized, this routine just
 *    increments the count of number of initializations and returns
 *    without trying to change the size of the hash table.  A
 *    specific number (RESERVED) of group entries may be reserved
 *    to enable "constant" values to be handed out which are valid
 *    IDs in the group, but which do not map to any data structures
 *    and are not allocated dynamicly later. HASH_SIZE is the
 *    minimum hash table size to use for the group. FREE_FUNC is
 *    called with an object pointer when the object is removed from
 *    the group.
 *
 * Return:  Success:  Non-negative
 *
 *    Failure:  Negative
 *
 * Programmer:  Robb Matzke
 *    Friday, February 19, 1999
 *
 * Modifications:
 *     Bill Wendling, 2000-05-05
 *     Instead of the ugly test of whether hash_size is a power of
 *     two, I placed it in a macro POWER_OF_TWO which uses the fact
 *     that a number that is a power of two has only 1 bit set.
 *
 *     Bill Wendling, 2000-05-09
 *     Changed POWER_OF_TWO macro to allow 1 as a valid power of two.
 *     Changed test below accordingly.
 *
 *-------------------------------------------------------------------------
 */
int
H5I_init_group(H5I_type_t grp, size_t hash_size, unsigned reserved,
         H5I_free_t free_func)
{
    H5I_id_group_t  *grp_ptr = NULL;  /*ptr to the atomic group*/
    int    ret_value = SUCCEED;  /*return value    */

    FUNC_ENTER_NOAPI(H5I_init_group, FAIL);

    /* Check arguments */
    if ((grp <= H5I_BADID || grp >= H5I_NGROUPS) && hash_size > 0)
  HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, FAIL, "invalid group number");
#ifdef HASH_SIZE_POWER_2
    if (!POWER_OF_TWO(hash_size) || hash_size == 1)
  HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, FAIL, "invalid hash size");
#endif /* HASH_SIZE_POWER_2 */

    if (H5I_id_group_list_g[grp] == NULL) {
  /* Allocate the group information for new group */
  if (NULL==(grp_ptr = H5MM_calloc(sizeof(H5I_id_group_t))))
      HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed");
  H5I_id_group_list_g[grp] = grp_ptr;
    } else {
  /* Get the pointer to the existing group */
  grp_ptr = H5I_id_group_list_g[grp];
    }

    if (grp_ptr->count == 0) {
  /* Initialize the ID group structure for new groups */
  grp_ptr->hash_size = hash_size;
  grp_ptr->reserved = reserved;
  grp_ptr->wrapped = 0;
  grp_ptr->ids = 0;
  grp_ptr->nextid = reserved;
  grp_ptr->free_func = free_func;
  grp_ptr->id_list = H5MM_calloc(hash_size*sizeof(H5I_id_info_t *));
  if (NULL==grp_ptr->id_list)
      HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed");
    }

    /* Increment the count of the times this group has been initialized */
    grp_ptr->count++;

done:
    if (ret_value<0) {
  /* Error condition cleanup */
  if (grp_ptr != NULL) {
      H5MM_xfree(grp_ptr->id_list);
      H5MM_xfree(grp_ptr);
  }
    }

    FUNC_LEAVE_NOAPI(ret_value);
}
AGLPbuffer
glitz_agl_pbuffer_create (glitz_agl_thread_info_t *thread_info,
			  int                     width,
			  int                     height)
{
    AGLPbuffer pbuffer;
    glitz_gl_enum_t target;

    if (!POWER_OF_TWO (width) || !POWER_OF_TWO (height)) {
	if (thread_info->agl_feature_mask &
	    GLITZ_AGL_FEATURE_TEXTURE_RECTANGLE_MASK)
	    target = GLITZ_GL_TEXTURE_RECTANGLE;
	else
	    return (AGLPbuffer) 0;
    } else
	target = GLITZ_GL_TEXTURE_2D;

    aglCreatePBuffer (width, height, target, GLITZ_GL_RGBA, 0, &pbuffer);

    return pbuffer;
}
示例#5
0
void
glitz_texture_init (glitz_texture_t *texture,
                    int             width,
                    int             height,
                    glitz_gl_int_t  texture_format,
                    glitz_fourcc_t  fourcc,
                    unsigned long   feature_mask,
                    glitz_bool_t    unnormalized)
{
    texture->param.filter[0] = texture->param.filter[1] = GLITZ_GL_NEAREST;
    texture->param.wrap[0] = texture->param.wrap[1] = GLITZ_GL_CLAMP;
    texture->param.border_color.red = texture->param.border_color.green =
                                          texture->param.border_color.blue =
                                                  texture->param.border_color.alpha = 0;

    texture->format = texture_format;
    texture->fourcc = fourcc;
    texture->name   = 0;

    switch (fourcc) {
    case GLITZ_FOURCC_YV12:
        /* U and V plane added below */
        texture->box.x1 = texture->box.y1 = 0;
        texture->box.x2 = width;
        texture->box.y2 = height;
        texture->width  = (width + 1) & ~1;
        texture->height = (height + 1) & ~1;
        texture->height += texture->height >> 1;
        texture->flags  = GLITZ_TEXTURE_FLAG_PADABLE_MASK;
        break;
    case GLITZ_FOURCC_YUY2:
        /* 1 RGBA texel for 2 YUY2 pixels */
        texture->box.x1 = texture->box.y1 = 0;
        texture->box.x2 = texture->width  = width >> 1;
        texture->box.y2 = texture->height = height;
        texture->flags  = GLITZ_TEXTURE_FLAG_CLAMPABLE_MASK |
                          GLITZ_TEXTURE_FLAG_REPEATABLE_MASK |
                          GLITZ_TEXTURE_FLAG_PADABLE_MASK;
        break;
    default:
        texture->box.x1 = texture->box.y1 = 0;
        texture->box.x2 = texture->width = width;
        texture->box.y2 = texture->height = height;

        texture->flags = GLITZ_TEXTURE_FLAG_PADABLE_MASK |
                         GLITZ_TEXTURE_FLAG_REPEATABLE_MASK;

        if (feature_mask & GLITZ_FEATURE_TEXTURE_BORDER_CLAMP_MASK)
            texture->flags |= GLITZ_TEXTURE_FLAG_CLAMPABLE_MASK;
    }

    if (!unnormalized &&
            ((feature_mask & GLITZ_FEATURE_TEXTURE_NON_POWER_OF_TWO_MASK) ||
             (POWER_OF_TWO (texture->width) && POWER_OF_TWO (texture->height))))
    {
        texture->target = GLITZ_GL_TEXTURE_2D;
    }
    else
    {
        texture->flags &= ~GLITZ_TEXTURE_FLAG_REPEATABLE_MASK;

        if (feature_mask & GLITZ_FEATURE_TEXTURE_RECTANGLE_MASK)
        {
            texture->target = GLITZ_GL_TEXTURE_RECTANGLE;
        }
        else
        {
            texture->target = GLITZ_GL_TEXTURE_2D;
            texture->flags &= ~GLITZ_TEXTURE_FLAG_PADABLE_MASK;

            if (!POWER_OF_TWO (texture->width))
                texture->width = glitz_uint_to_power_of_two (texture->width);

            if (!POWER_OF_TWO (texture->height))
                texture->height = glitz_uint_to_power_of_two (texture->height);
        }
    }

    if (texture->target == GLITZ_GL_TEXTURE_2D)
    {
        texture->texcoord_width_unit = 1.0f / texture->width;
        texture->texcoord_height_unit = 1.0f / texture->height;
    }
    else
    {
        texture->texcoord_width_unit = 1.0f;
        texture->texcoord_height_unit = 1.0f;
    }
}
示例#6
0
void
WaterScreen::waterSetup ()
{
    int size;
    std::string buffer;

    texHeight = TEXTURE_SIZE;
    texWidth  = (texHeight * screen->width ()) / screen->height ();

#ifdef USE_GLES
    target = GL_TEXTURE_2D;
    tx = ty = 1.0f;
#else
    if (GL::textureNonPowerOfTwo ||
	(POWER_OF_TWO (texWidth) && POWER_OF_TWO (texHeight)))
    {
	target = GL_TEXTURE_2D;
	tx = ty = 1.0f;
    }
    else
    {
	target = GL_TEXTURE_RECTANGLE_NV;
	tx = texWidth;
	ty = texHeight;
    }
#endif

    size = (texWidth + 2) * (texHeight + 2);

    data = calloc (1, (sizeof (float) * size * 2) +
		   (sizeof (GLubyte) * texWidth * texHeight * 4));
    if (!data)
	return;

    d0 = (float *)data;
    d1 = (d0 + (size));
    t0 = (unsigned char *) (d1 + (size));

    if (GL::vboEnabled && GL::shaders)
    {
	char buf[8192];
	program[SET] = new GLProgram (set_water_vertices_vertex_shader,
	                              set_water_vertices_fragment_shader);

	if (target == GL_TEXTURE_2D)
	    sprintf (buf, update_water_vertices_fragment_shader.c_str (),
		     "2D", "2D",
		     1.0f / (float) texWidth,  1.0f / (float) texWidth,
		     1.0f / (float) texHeight, 1.0f / (float) texHeight,
		     "2D", "2D", "2D", "2D");
	else
	    sprintf (buf, update_water_vertices_fragment_shader.c_str (),
		     "RECT", "RECT",
		     1.0f, 1.0f, 1.0f, 1.0f,
		     "RECT", "RECT", "RECT", "RECT");

	buffer.assign (buf);
	program[UPDATE] = new GLProgram (update_water_vertices_vertex_shader,
				         buffer);

	sprintf (buf, paint_water_vertices_fragment_shader.c_str (),
		     screen->width (), screen->height ());

	buffer.assign (buf);
	program[PAINT]  = new GLProgram (paint_water_vertices_vertex_shader,
				         buffer);

	vertexBuffer[SET] = new GLVertexBuffer (GL::DYNAMIC_DRAW);
	vertexBuffer[SET]->setProgram (program[SET]);

	vertexBuffer[UPDATE] = new GLVertexBuffer (GL::STATIC_DRAW);
	vertexBuffer[UPDATE]->setProgram (program[UPDATE]);

	vertexBuffer[PAINT] = new GLVertexBuffer (GL::STATIC_DRAW);
	vertexBuffer[PAINT]->setProgram (program[PAINT]);
    }

    if (GL::fboEnabled)
    {
	CompSize size(texWidth, texHeight);
	for (int i = 0; i < TEXTURE_NUM; i++)
	{
	    waterFbo[i] = new GLFramebufferObject ();
	    waterFbo[i]->allocate (size, (char *) t0,
				   GL_BGRA, GL_UNSIGNED_BYTE);
	    // check if FBOs are working. If not, fallback to software textures
	    oldFbo = waterFbo[i]->bind ();
	    waterFbo[i]->rebind (oldFbo);
	    if (!waterFbo[i]->checkStatus ())
	    {
		useFbo = false;
		delete waterFbo[i];
		break;
	    }
	}
    }
}
示例#7
0
文件: texture.c 项目: zmike/compiz
static Bool
imageToTexture(CompScreen *screen,
               CompTexture *texture,
               const char *image,
               unsigned int width,
               unsigned int height,
               GLenum format,
               GLenum type)
{
   char *data;
   int i;
   GLint internalFormat;

   data = malloc(4 * width * height);
   if (!data)
     return FALSE;

   for (i = 0; i < height; i++)
     memcpy(&data[i * width * 4],
            &image[(height - i - 1) * width * 4],
            width * 4);

   makeScreenCurrent(screen);
   releasePixmapFromTexture(screen, texture);

   if (screen->textureNonPowerOfTwo ||
       (POWER_OF_TWO(width) && POWER_OF_TWO(height)))
     {
        texture->target = GL_TEXTURE_2D;
        texture->matrix.xx = 1.0f / width;
        texture->matrix.yy = -1.0f / height;
        texture->matrix.y0 = 1.0f;
        texture->mipmap = TRUE;
     }
   else
     {
        texture->target = GL_TEXTURE_RECTANGLE_NV;
        texture->matrix.xx = 1.0f;
        texture->matrix.yy = -1.0f;
        texture->matrix.y0 = height;
        texture->mipmap = FALSE;
     }

   if (!texture->name)
     compiz_glapi->glGenTextures(1, &texture->name);

   compiz_glapi->glBindTexture(texture->target, texture->name);

   internalFormat =
     (screen->opt[COMP_SCREEN_OPTION_TEXTURE_COMPRESSION].value.b &&
      screen->textureCompression ?
      GL_COMPRESSED_RGBA_ARB : GL_RGBA);

   compiz_glapi->glTexImage2D(texture->target, 0, internalFormat, width, height, 0,
                              format, type, data);

   texture->filter = GL_NEAREST;

   compiz_glapi->glTexParameteri(texture->target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
   compiz_glapi->glTexParameteri(texture->target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

   compiz_glapi->glTexParameteri(texture->target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
   compiz_glapi->glTexParameteri(texture->target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

   texture->wrap = GL_CLAMP_TO_EDGE;

   compiz_glapi->glBindTexture(texture->target, 0);

   free(data);

   return TRUE;
}
示例#8
0
文件: texture.c 项目: zmike/compiz
Bool
bindPixmapToTexture(CompScreen *screen,
                    CompTexture *texture,
                    Pixmap pixmap,
                    int width,
                    int height,
                    int depth)
{
   unsigned int target = 0;
   CompFBConfig *config = &screen->glxPixmapFBConfigs[depth];
   int attribs[7], i = 0;

   if (!config->fbConfig)
     {
        compLogMessage("core", CompLogLevelWarn,
                       "No GLXFBConfig for depth %d",
                       depth);

        return FALSE;
     }

   attribs[i++] = GLX_TEXTURE_FORMAT_EXT;
   attribs[i++] = config->textureFormat;
   attribs[i++] = GLX_MIPMAP_TEXTURE_EXT;
   attribs[i++] = config->mipmap;

   /* If no texture target is specified in the fbconfig, or only the
      TEXTURE_2D target is specified and GL_texture_non_power_of_two
      is not supported, then allow the server to choose the texture target. */
   if (config->textureTargets & GLX_TEXTURE_2D_BIT_EXT &&
       (screen->textureNonPowerOfTwo ||
        (POWER_OF_TWO(width) && POWER_OF_TWO(height))))
     target = GLX_TEXTURE_2D_EXT;
   //else if (config->textureTargets & GLX_TEXTURE_RECTANGLE_BIT_EXT)
   //target = GLX_TEXTURE_RECTANGLE_EXT;

   /* Workaround for broken texture from pixmap implementations,
      that don't advertise any texture target in the fbconfig. */
   if (!target)
     {
        //if (!(config->textureTargets & GLX_TEXTURE_2D_BIT_EXT))
        //target = GLX_TEXTURE_RECTANGLE_EXT;
        //else
        if (!(config->textureTargets & GLX_TEXTURE_RECTANGLE_BIT_EXT))
          target = GLX_TEXTURE_2D_EXT;
     }

   if (target)
     {
        attribs[i++] = GLX_TEXTURE_TARGET_EXT;
        attribs[i++] = target;
     }

   attribs[i++] = None;

   makeScreenCurrent(screen);
   texture->pixmap = (*screen->createPixmap)(screen->display->display,
                                             config->fbConfig, pixmap,
                                             attribs);
   if (!texture->pixmap)
     {
        compLogMessage("core", CompLogLevelWarn,
                       "glXCreatePixmap failed");

        return FALSE;
     }

   if (!target)
     (*screen->queryDrawable)(screen->display->display,
                              texture->pixmap,
                              GLX_TEXTURE_TARGET_EXT,
                              &target);

   switch (target)
     {
      case GLX_TEXTURE_2D_EXT:
        texture->target = GL_TEXTURE_2D;

        texture->matrix.xx = 1.0f / width;
        if (config->yInverted)
          {
             texture->matrix.yy = 1.0f / height;
             texture->matrix.y0 = 0.0f;
          }
        else
          {
             texture->matrix.yy = -1.0f / height;
             texture->matrix.y0 = 1.0f;
          }
        texture->mipmap = config->mipmap;
        break;
      //case GLX_TEXTURE_RECTANGLE_EXT:
      //texture->target = GL_TEXTURE_RECTANGLE_ARB;

      //texture->matrix.xx = 1.0f;
      //if (config->yInverted)
      //{
      //texture->matrix.yy = 1.0f;
      //texture->matrix.y0 = 0;
      //}
      //else
      //{
      //texture->matrix.yy = -1.0f;
      //texture->matrix.y0 = height;
      //}
      //texture->mipmap = FALSE;
      //break;
      default:
        compLogMessage("core", CompLogLevelWarn,
                       "pixmap 0x%x can't be bound to texture",
                       (int)pixmap);

        (*screen->destroyPixmap)(screen->display->display, texture->pixmap);
        texture->pixmap = None;

        return FALSE;
     }

   if (!texture->name)
     compiz_glapi->glGenTextures(1, &texture->name);

   compiz_glapi->glBindTexture(texture->target, texture->name);

   if (!strictBinding)
     {
        (*screen->bindTexImage)(screen->display->display,
                                texture->pixmap,
                                GLX_FRONT_LEFT_EXT,
                                NULL);
     }

   texture->filter = GL_NEAREST;

   compiz_glapi->glTexParameteri(texture->target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
   compiz_glapi->glTexParameteri(texture->target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

   compiz_glapi->glTexParameteri(texture->target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
   compiz_glapi->glTexParameteri(texture->target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

   texture->wrap = GL_CLAMP_TO_EDGE;

   compiz_texture_bind(texture);

   compiz_glapi->glBindTexture(texture->target, 0);

   return TRUE;
}
Bool
readImageToTexture (CompScreen   *screen,
		    CompTexture  *texture,
		    char	 *imageFileName,
		    unsigned int *returnWidth,
		    unsigned int *returnHeight)
{
    char	 *data, *image;
    unsigned int width, height;
    int		 i;

    if (!readPng (imageFileName, &image, &width, &height))
    {
	fprintf (stderr, "%s: Failed to load image: %s\n",
		 programName, imageFileName);
	return FALSE;
    }

    data = malloc (4 * width * height);
    if (!data)
    {
	free (image);
	return FALSE;
    }

    for (i = 0; i < height; i++)
	memcpy (&data[i * width * 4],
		&image[(height - i - 1) * width * 4],
		width * 4);

    free (image);

    releasePixmapFromTexture (screen, texture);

    if (screen->textureNonPowerOfTwo ||
	(POWER_OF_TWO (width) && POWER_OF_TWO (height)))
    {
	texture->target = GL_TEXTURE_2D;
	texture->matrix.xx = 1.0f / width;
	texture->matrix.yy = -1.0f / height;
	texture->matrix.y0 = 1.0f;
    }
    else
    {
	texture->target = GL_TEXTURE_RECTANGLE_NV;
	texture->matrix.xx = 1.0f;
	texture->matrix.yy = -1.0f;
	texture->matrix.y0 = height;
    }

    if (!texture->name)
	glGenTextures (1, &texture->name);

    glBindTexture (texture->target, texture->name);

    glTexImage2D (texture->target, 0, GL_RGB, width, height, 0, GL_BGRA,

#if IMAGE_BYTE_ORDER == MSBFirst
		  GL_UNSIGNED_INT_8_8_8_8_REV,
#else
		  GL_UNSIGNED_BYTE,
#endif

		  data);

    texture->filter = COMP_TEXTURE_FILTER_FAST;

    glTexParameteri (texture->target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri (texture->target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

    glTexParameteri (texture->target, GL_TEXTURE_WRAP_S, GL_CLAMP);
    glTexParameteri (texture->target, GL_TEXTURE_WRAP_T, GL_CLAMP);

    glBindTexture (texture->target, 0);

    free (data);

    *returnWidth = width;
    *returnHeight = height;

    return TRUE;
}
示例#10
0
EBOOL eggListView_insert(HEGGLISTVIEW hEggListView, epointer pNodes, size32_t ndSz)
{
    if(EGGLISTVIEW_IS_INVALID(hEggListView))
    {
        return EGG_FALSE;
    }
    HVIEWSTREAM lp_view_stream = hEggListView->hViewStream;
    HEGGLISTINF lp_list_info = hEggListView->hInfo;
    offset64_t n_block_off = lp_list_info->headOff;
    
    EGGLISTBLOCK st_list_block = {0};
    char* lp_cur_node = pNodes;
    size32_t n_cur_sz = ndSz;
    
    
    if(n_block_off)
    {
        
        ViewStream_read(lp_view_stream, &st_list_block, sizeof(st_list_block), n_block_off);

//        printf("[%u][%u][%u] \n", st_list_block.aCnt, st_list_block.uCnt, st_list_block.next );

        size32_t n_unused_sz = (st_list_block.aCnt - st_list_block.uCnt) * lp_list_info->nodeSz;
        offset64_t n_tmp_off =  n_block_off + sizeof(st_list_block) + st_list_block.uCnt * lp_list_info->nodeSz;
            
        if(n_unused_sz >= n_cur_sz)
        {
            ViewStream_update(lp_view_stream, lp_cur_node, n_cur_sz, n_tmp_off);
            st_list_block.uCnt += n_cur_sz / lp_list_info->nodeSz;
            n_cur_sz = 0;
            ViewStream_update(lp_view_stream, &st_list_block, sizeof(st_list_block), n_block_off);
        }
        else
        {
            
            count_t n_real_cnt = st_list_block.uCnt + n_cur_sz / lp_list_info->nodeSz;
            count_t n_pow2_cnt = 0;
            
            count_t n_tmp_cnt = n_real_cnt;
            POWER_OF_TWO(n_pow2_cnt, n_tmp_cnt);
            
            
            if(n_pow2_cnt < EGGBLOCK_LIMIT_COUNT)
            {
                
                size32_t n_total_sz = n_pow2_cnt * lp_list_info->nodeSz + sizeof(st_list_block);
                size32_t n_read_sz = st_list_block.uCnt * lp_list_info->nodeSz;
                char* lp_total_buf = (char*)malloc(n_total_sz);
                memset(lp_total_buf, 0, n_total_sz);

                //read old nodes
                ViewStream_read(lp_view_stream, lp_total_buf + sizeof(st_list_block),
                                n_read_sz, n_block_off + sizeof(EGGLISTBLOCK));

                //copy new nodes
                memcpy(lp_total_buf + sizeof(st_list_block) + n_read_sz, pNodes, ndSz);

                //free old block
                ViewStream_free_area(lp_view_stream, n_block_off,
                                    sizeof(EGGLISTBLOCK) + st_list_block.aCnt * lp_list_info->nodeSz);

                //update  block info
                st_list_block.aCnt = n_pow2_cnt;
                st_list_block.uCnt = n_real_cnt;

                memcpy((lp_total_buf), &st_list_block, sizeof(st_list_block));
                
                lp_list_info->headOff = ViewStream_write(lp_view_stream, lp_total_buf, n_total_sz);
                free(lp_total_buf);
                n_cur_sz = 0;
            }
            else
            {
                ViewStream_update(lp_view_stream, lp_cur_node, n_unused_sz, n_tmp_off);
                st_list_block.uCnt = st_list_block.aCnt;
                lp_cur_node += n_unused_sz;
                n_cur_sz -= n_unused_sz;
                ViewStream_update(lp_view_stream, &st_list_block, sizeof(st_list_block), n_block_off);

            }
        }
        
     
    }


    while(n_cur_sz)
    {
        
        
        count_t n_real_cnt = n_cur_sz / lp_list_info->nodeSz;
        count_t n_total_cnt = 0;
        size32_t n_write_cnt = 0;
        
        size32_t n_write_sz = 0;
        size32_t n_total_sz = 0;

        char* lp_total_buf = EGG_NULL;

        count_t n_tmp_cnt = n_real_cnt;
        POWER_OF_TWO(n_total_cnt, n_tmp_cnt);
        n_total_cnt = (n_total_cnt < EGGBLOCK_LIMIT_COUNT ? n_total_cnt : EGGBLOCK_LIMIT_COUNT) ;

        n_total_sz = sizeof(st_list_block) + n_total_cnt * lp_list_info->nodeSz;

        n_write_cnt = n_total_cnt >= n_real_cnt ?n_real_cnt : n_total_cnt;
        n_write_sz = n_write_cnt * lp_list_info->nodeSz;
        
        st_list_block.aCnt = n_total_cnt;
        st_list_block.uCnt = n_write_cnt;
        st_list_block.next = lp_list_info->headOff;

        lp_total_buf = (char*)malloc(n_total_sz);
        memset(lp_total_buf, 0, n_total_sz);

        memcpy(lp_total_buf, &st_list_block, sizeof(st_list_block));
        memcpy((HEGGLISTBLOCK)(lp_total_buf) + 1, lp_cur_node, n_write_sz);
        
        lp_list_info->headOff = ViewStream_write(lp_view_stream, lp_total_buf, n_total_sz);
        lp_list_info->blkCnt ++;
        
        
        lp_cur_node += n_write_sz;
        n_cur_sz -= n_write_sz;
        free(lp_total_buf);
    }
    lp_list_info->nodeCnt += ndSz / lp_list_info->nodeSz;
    lp_list_info->curCnt += ndSz / lp_list_info->nodeSz;

    ViewStream_update_nolock(lp_view_stream, lp_list_info, sizeof(EGGLISTINF), hEggListView->hInfo->ownOff);



    
    return EGG_TRUE;
}