⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 prediction.c

📁 linux下将各类格式图片转换工具
💻 C
📖 第 1 页 / 共 2 页
字号:
      mvt = prange.mv_tree_bits;            prange.image           = 0;      prange.address         = 0;      prange.tree_bits       = 0;      prange.matrix_bits     = 0;      prange.weights_bits    = 0;      prange.mv_coord_bits   = 0;      prange.mv_tree_bits    = 0;      prange.nd_weights_bits = 0;      prange.nd_tree_bits    = 0;      compute_ip_images_state (prange.image, prange.address, prange.level,			       1, 0, wfa, c);      costs += subdivide (max_costs - costs, band, y_state, &prange,			  wfa, c, NO, YES);      if (costs < max_costs)		/* use motion compensation */      {	 unsigned img, adr;		/* temp. values */	 	 img                  = range->image;	 adr                  = range->address;	 *range               = prange;	 range->image         = img;	 range->address       = adr;	 range->mv_coord_bits = mvc;	 range->mv_tree_bits  = mvt;	 range->prediction    = YES;	 for (state = last_state + 1; state < wfa->states; state++)	    if (need_image (state, wfa))	       memset (c->ip_images_state [state], 0,		       size_of_tree (c->products_level) * sizeof (real_t));	 costs = (range->tree_bits + range->matrix_bits + range->weights_bits		  + range->mv_tree_bits + range->mv_coord_bits		  + range->nd_tree_bits + range->nd_weights_bits) * price		 + range->err;      }      else	 costs = MAXCOSTS;      for (state = 0; state <= last_state; state++)	 if (need_image (state, wfa))	 {	    Free (c->ip_images_state[state]);	    c->ip_images_state[state] = ipi [state];	 }      Free (c->pixels);   }   else      costs = MAXCOSTS;      Free (mcpe);   return costs;}static real_tnd_prediction (real_t max_costs, real_t price, unsigned band, int y_state,	       range_t *range, wfa_t *wfa, coding_t *c){   real_t  costs;			/* current approximation costs */   range_t lrange = *range;      /*    *  Predict 'range' with DC component approximation    */   {      real_t x = get_ip_image_state (range->image, range->address,				     range->level, 0, c);      real_t y = get_ip_state_state (0, 0, range->level, c);      real_t w = btor (rtob (x / y, c->coeff->dc_rpf), c->coeff->dc_rpf);      word_t s [2] = {0, -1};      lrange.into [0] 	     = 0;      lrange.into [1] 	     = NO_EDGE;      lrange.weight [0]      = w;      lrange.mv_coord_bits   = 0;      lrange.mv_tree_bits    = 0;      lrange.nd_tree_bits    = tree_bits (LEAF, lrange.level, &c->p_tree);      lrange.nd_weights_bits = 0;      lrange.tree_bits       = 0;      lrange.matrix_bits     = 0;      lrange.weights_bits    = c->coeff->bits (&w, s, range->level, c->coeff);   }   costs = price * (lrange.weights_bits + lrange.nd_tree_bits);      /*    *  Recursive aproximation of difference image    */   if (costs < max_costs)		   {      unsigned  state;      range_t  	rrange;			/* range: recursive subdivision */      unsigned  last_state;		/* last WFA state before recursion */      real_t   *ipi [MAXSTATES];	/* inner products pointers */      unsigned 	width  = width_of_level (range->level);      unsigned  height = height_of_level (range->level);      real_t   *pixels;      /*       *  Generate difference image original - approximation       */      {	 unsigned  n;	 real_t *src, *dst;		/* pointers to image data */	 real_t w = - lrange.weight [0] * c->images_of_state [0][0];		     	 src = c->pixels + range->address * size_of_level (range->level); 	 dst = c->pixels = pixels = Calloc (width * height, sizeof (real_t));	 for (n = width * height; n; n--)	    *dst++ = *src++ + w;      }            /*       *  Approximate difference recursively.       */      rrange                 = *range;      rrange.tree_bits       = 0;      rrange.matrix_bits     = 0;      rrange.weights_bits    = 0;      rrange.mv_coord_bits   = 0;      rrange.mv_tree_bits    = 0;      rrange.nd_tree_bits    = 0;      rrange.nd_weights_bits = 0;      rrange.image           = 0;      rrange.address         = 0;      last_state = wfa->states - 1;      for (state = 0; state <= last_state; state++)	 if (need_image (state, wfa))	 {	    ipi [state] = c->ip_images_state[state];	    c->ip_images_state[state]	       = Calloc (size_of_tree (c->products_level), sizeof (real_t));	 }            compute_ip_images_state (rrange.image, rrange.address, rrange.level,			       1, 0, wfa, c);            costs += subdivide (max_costs - costs, band, y_state, &rrange, wfa, c,			  NO, YES);            Free (pixels);      if (costs < max_costs && ischild (rrange.tree)) /* use prediction */      {	 unsigned img, adr;	 unsigned edge;	 img                     = range->image;	 adr                     = range->address;	 *range                  = rrange;	 range->image            = img;	 range->address          = adr;	 range->nd_tree_bits    += lrange.nd_tree_bits;	 range->nd_weights_bits += lrange.weights_bits;	 	 for (edge = 0; isedge (lrange.into [edge]); edge++)	 {	    range->into [edge]   = lrange.into [edge];	    range->weight [edge] = lrange.weight [edge];	 }	 range->into [edge] = NO_EDGE;	 range->prediction  = edge;	 for (state = last_state + 1; state < wfa->states; state++)	    if (need_image (state, wfa))	       memset (c->ip_images_state [state], 0,		       size_of_tree (c->products_level) * sizeof (real_t));      }      else	 costs = MAXCOSTS;            for (state = 0; state <= last_state; state++)	 if (need_image (state, wfa))	 {	    Free (c->ip_images_state [state]);	    c->ip_images_state [state] = ipi [state];	 }   }   else      costs = MAXCOSTS;   return costs;}static state_data_t *store_state_data (unsigned from, unsigned to, unsigned max_level,		  wfa_t *wfa, coding_t *c)/* *  Save and remove all states starting from state 'from'. * *  Return value: *	pointer to array of state_data structs */{   state_data_t *data;			/* array of savestates */   state_data_t *sd;			/* pointer to current savestates */   unsigned	 state, label, level;   if (to < from)      return NULL;			/* nothing to do */      data = Calloc (to - from + 1, sizeof (state_data_t));      for (state = from; state <= to; state++)   {      sd = &data [state - from];      sd->final_distribution = wfa->final_distribution [state];      sd->level_of_state     = wfa->level_of_state [state];      sd->domain_type        = wfa->domain_type [state];      sd->images_of_state    = c->images_of_state [state];      sd->inner_products     = c->ip_images_state [state];            wfa->domain_type [state]   = 0;      c->images_of_state [state] = NULL;      c->ip_images_state [state] = NULL;				         for (label = 0; label < MAXLABELS; label++)       {	 sd->tree [label]     	= wfa->tree [state][label];	 sd->y_state [label]  	= wfa->y_state [state][label];	 sd->y_column [label] 	= wfa->y_column [state][label];	 sd->mv_tree [label]  	= wfa->mv_tree [state][label];	 sd->x [label]        	= wfa->x [state][label];	 sd->y [label]        	= wfa->y [state][label];	 sd->prediction [label] = wfa->prediction [state][label];	 memcpy (sd->weight [label], wfa->weight [state][label], 		 sizeof (real_t) * (MAXEDGES + 1));	 memcpy (sd->int_weight [label], wfa->int_weight [state][label], 		 sizeof (word_t) * (MAXEDGES + 1));	 memcpy (sd->into [label], wfa->into [state][label], 		 sizeof (word_t) * (MAXEDGES + 1));	 wfa->into [state][label][0] = NO_EDGE;	 wfa->tree [state][label]    = RANGE;	 wfa->y_state [state][label] = RANGE;      }      for (level = c->options.images_level + 1; level <= max_level;	   level++)      {	 sd->ip_states_state [level]       = c->ip_states_state [state][level];	 c->ip_states_state [state][level] = NULL;      }   }   return data;}static voidrestore_state_data (unsigned from, unsigned to, unsigned max_level,		    state_data_t *data, wfa_t *wfa, coding_t *c)/* *  Restore all state data starting from state 'from'. *   *  No return value. */{   state_data_t *sd;			/* pointer to state_data item */   unsigned	 state, label, level;   if (to < from)      return;				/* nothing to do */      for (state = from; state <= to; state++)   {      sd = &data [state - from];            wfa->final_distribution [state] = sd->final_distribution;      wfa->level_of_state [state]     = sd->level_of_state;      wfa->domain_type [state]        = sd->domain_type;            if (c->images_of_state [state] != NULL)	 Free (c->images_of_state [state]);      c->images_of_state [state] = sd->images_of_state;      if (c->ip_images_state [state] != NULL)	 Free (c->ip_images_state [state]);      c->ip_images_state [state] = sd->inner_products;      for (label = 0; label < MAXLABELS; label++)      {	 wfa->tree [state][label]     	= sd->tree [label];	 wfa->y_state [state][label]  	= sd->y_state [label];	 wfa->y_column [state][label] 	= sd->y_column [label];	 wfa->mv_tree [state][label]  	= sd->mv_tree [label];	 wfa->x [state][label]        	= sd->x [label];	 wfa->y [state][label]        	= sd->y [label];	 wfa->prediction [state][label] = sd->prediction [label];	 	 memcpy (wfa->weight [state][label], sd->weight [label], 		 sizeof(real_t) * (MAXEDGES + 1));	 memcpy (wfa->int_weight [state][label], sd->int_weight [label], 		 sizeof(word_t) * (MAXEDGES + 1));	 memcpy (wfa->into [state][label], sd->into [label],  		 sizeof(word_t) * (MAXEDGES + 1));      }	       for (level = c->options.images_level + 1; level <= max_level;	   level++)      {	 if (c->ip_states_state [state][level] != NULL)	    Free (c->ip_states_state [state][level]);	 c->ip_states_state [state][level] = sd->ip_states_state [level];      }   }   Free (data);   wfa->states = to + 1;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -