예제 #1
0
void Vectorizer::load_data(const char* filename)
{
  FILE* f = fopen(filename, "rb");
  if (f == NULL) error("Could not open %s for reading.", filename);
  lock_data();

  struct { char magic[4]; int ver; } hdr;
  if (fread(&hdr, sizeof(hdr), 1, f) != 1)
    error("Error reading %s", filename);

  if (hdr.magic[0] != 'H' || hdr.magic[1] != '2' || hdr.magic[2] != 'D' || hdr.magic[3] != 'V')
    error("File %s is not a Hermes2D Vectorizer file.", filename);
  if (hdr.ver > 1)
    error("File %s -- unsupported file version.", filename);

  #define read_array(array, type, n, c, what) \
    if (fread(&n, sizeof(int), 1, f) != 1) \
      error("Error reading the number of " what " from %s", filename); \
    lin_init_array(array, type, c, n); \
    if (fread(array, sizeof(type), n, f) != n) \
      error("Error reading " what " from %s", filename);

  read_array(verts, double4, nv, cv, "vertices");
  read_array(tris,  int3,    nt, ct, "triangles");
  read_array(edges, int3,    ne, ce, "edges");
  read_array(dashes, int2,   nd, cd, "dashes");

  find_min_max();
  unlock_data();
  fclose(f);
}
예제 #2
0
void
shell_unzoom(int x, int y)
{
    Evas_Coord              ex, ey, ew, eh;

    if (!drawing)
        return;
    evas_output_viewport_get(shell->evas, &ex, &ey, &ew, &eh);

    lock_data();
    y = eh + ey - y;

    drawing->old.x = drawing->x;
    drawing->old.y = drawing->y;
    drawing->old.scale = drawing->scale;

    drawing->x -= x / drawing->scale;
    drawing->y -= y / drawing->scale;
    drawing->scale /= 1.25;
    drawing->x += x / drawing->scale;
    drawing->y += y / drawing->scale;

    append_undo_double((void *)(&(drawing->x)), drawing->old.x,
                       drawing->x, 1, OBJ_DRAWING, NULL);
    append_undo_double((void *)(&(drawing->y)), drawing->old.y,
                       drawing->y, 0, 0, NULL);
    append_undo_double((void *)(&(drawing->scale)), drawing->old.scale,
                       drawing->scale, 0, 0, NULL);

    unlock_data();
    drawing_sync();
}
예제 #3
0
파일: line.c 프로젝트: playya/Enlightenment
void
line_create(void)
{
    char               *s;
    float               x1 = 0, y1 = 0, x2 = 0, y2 = 0;
    int                 res;

    serv_set_hint(DUP(_("enter first point: ")));

    serv_set_state(ST_LINE1);

    do
      {
          s = serv_get_string();
          res = get_values(s, shell->context.fx, shell->context.fy, &x1, &y1);
          if (res == 1)
              serv_set_hint(DUP(_("error, please reenter: ")));
      }
    while (res == 1);

    serv_set_state(ST_LINE2);

    if (res == 0)
      {
          serv_set_state(ST_NORMAL);
          return;
      }

    do
      {
          pre_line_x1y1(x1, y1);
          shell->context.fx = x1;
          shell->context.fy = y1;

          serv_set_hint(DUP(_("enter next point: ")));
          do
            {
                s = serv_get_string();
                res = get_values(s, x1, y1, &x2, &y2);
                if (res == 1)
                    serv_set_hint(DUP(_("error, please reenter: ")));
            }
          while (res == 1);
          if (res == 0)
            {
                serv_set_state(ST_NORMAL);
                return;
            }

          lock_data();
          _line_create(x1, y1, x2, y2);
          shell->context.fx = x2;
          shell->context.fy = y2;
          unlock_data();
          x1 = x2;
          y1 = y2;
      }
    while (1);
}
예제 #4
0
bool FmMsg::retrieve(FmMsgEntry * dst) {
	if (!lock_data() || _buf.empty()) {
		return false;
	} else {
		dst = &_buf.front();
		unlock_data();
		return true;
	}
}
예제 #5
0
FmMsgEntry FmMsg::retrieve() {
	if (!lock_data() || _buf.empty()) {
		FmMsgEntry ret(0, RAW);
		return ret;
	} else {
		FmMsgEntry ret(_buf.front(), OWNERSHIP); 
		_buf.pop();
		unlock_data();
		--_cnt;
		return ret;
	}
}
예제 #6
0
int url_check_check_preview(char *preview_data,int preview_data_len, request_t *req){
    ci_headers_list_t* req_header;
    struct url_check_data *uc=ci_service_data(req);
    struct http_info httpinf;
    int allow=1;

    if((req_header=ci_reqmod_headers(req))==NULL) /*It is not possible but who knows .....*/
	return CI_ERROR;

    get_http_info(req,req_header, &httpinf);

    ci_debug_printf(9,"URL  to host %s\n",httpinf.site);
    ci_debug_printf(9,"URL  page %s\n",httpinf.page);

    allow=check_destination(&httpinf);


    if(!allow){
	 /*The URL is not a good one so....*/
	 ci_debug_printf(9,"Oh!!! we are going to deny this site.....\n");

	 uc->body=ci_cached_file_new(strlen(error_message)+10);
	 ci_request_create_respmod(req,1,1); /*Build the responce headers*/

	 ci_respmod_add_header(req,"HTTP/1.1 403 Forbidden");/*Send an 403 Forbidden http responce to web client*/
	 ci_respmod_add_header(req,"Server: C-ICAP");
	 ci_respmod_add_header(req,"Content-Type: text/html");
	 ci_respmod_add_header(req,"Content-Language: en");
	 
	 ci_cached_file_write(uc->body,error_message,strlen(error_message),1);

    }
    else{
	 /*if we are inside preview negotiation or client allow204 responces oudsite of preview then*/
	 if(preview_data || ci_req_allow204(req)) 
	      return CI_MOD_ALLOW204;
	 
	 /*
	   Squid does not support preview of data in reqmod requests neither 204 responces outside preview
	   so we need to read all the body if exists and send it back to squid.
	   Allocate a new body for it 
	 */
	 if(ci_req_hasbody(req)){
	      int clen=ci_content_lenght(req)+100;
	      uc->body=ci_cached_file_new(clen);
	 }

    }

    unlock_data(req);
    return CI_MOD_CONTINUE;
}
예제 #7
0
bool FmMsg::insert(FmMsgEntry * src) {
	if (_cnt == _max) {
		_handle(src);
		return false;
	}

	while(!lock_data());
	_buf.push(*src);
	unlock_data();

	++_cnt;

	return true;
}
예제 #8
0
      void Orderizer::save_data_vtk(const char* file_name)
      {
        FILE* f = fopen(file_name, "wb");
        if (f == NULL) error("Could not open %s for writing.", file_name);
        lock_data();

        // Output header for vertices.
        fprintf(f, "# vtk DataFile Version 2.0\n");
        fprintf(f, "\n");
        fprintf(f, "ASCII\n\n");
        fprintf(f, "DATASET UNSTRUCTURED_GRID\n");

        // Output vertices.
        fprintf(f, "POINTS %d %s\n", this->nv, "float");
        for (int i=0; i < this->nv; i++) 
        {
          fprintf(f, "%g %g %g\n", this->verts[i][0], this->verts[i][1], 0.0);
        }

        // Output elements.
        fprintf(f, "\n");
        fprintf(f, "CELLS %d %d\n", this->nt, 4 * this->nt);
        for (int i=0; i < this->nt; i++) 
        {
          fprintf(f, "3 %d %d %d\n", this->tris[i][0], this->tris[i][1], this->tris[i][2]);
        }

        // Output cell types.
        fprintf(f, "\n");
        fprintf(f, "CELL_TYPES %d\n", this->nt);
        for (int i=0; i < this->nt; i++) 
        {
          fprintf(f, "5\n");    // The "5" means triangle in VTK.
        }

        // This outputs double solution values. Look into Hermes2D/src/output/vtk.cpp 
        // for how it is done for vectors.
        fprintf(f, "\n");
        fprintf(f, "POINT_DATA %d\n", this->nv);
        fprintf(f, "SCALARS %s %s %d\n", "Mesh", "float", 1);
        fprintf(f, "LOOKUP_TABLE %s\n", "default");
        for (int i=0; i < this->nv; i++) 
        {
          fprintf(f, "%g\n", this->verts[i][2]);
        }

        unlock_data();
        fclose(f);
      }
예제 #9
0
void
shell_drag_start(int x, int y)
{

    if (!drawing)
        return;
    pointer_push_and_set(0x1500 + POINTER_HAND);
    drag = 1;
    drag_x = x;
    drag_y = y;
    lock_data();
    drawing->old.x = drawing->x;
    drawing->old.y = drawing->y;
    unlock_data();
}
예제 #10
0
bool FmMsg::insert(int size, void * content, FmMsgEntry_type type) {
	FmMsgEntry dst(size, type);
	dst.populate(content, size, type);

	if (_cnt == _max) {
		_handle(&dst);
		return false;
	}

	while (!lock_data()); // wait for the lock.
	_buf.push(dst);
	unlock_data();

	++_cnt;

	return true;
}
예제 #11
0
void
shell_drag(int x, int y)
{

    if (!drag)
        return;
    if (!drawing)
        return;

    lock_data();
    drawing->x += ((float)(x - drag_x)) / drawing->scale;
    drawing->y -= ((float)(y - drag_y)) / drawing->scale;
    unlock_data();
    drag_x = x;
    drag_y = y;

    drawing_sync();
}
예제 #12
0
      void Orderizer::load_data(const char* filename)
      {
        FILE* f = fopen(filename, "rb");
        if (f == NULL) error("Could not open %s for reading.", filename);
        lock_data();

        struct { char magic[4]; int ver; } hdr;
        if (fread(&hdr, sizeof(hdr), 1, f) != 1)
          error("Error reading %s", filename);

        if (hdr.magic[0] != 'H' || hdr.magic[1] != '2' || hdr.magic[2] != 'D' || hdr.magic[3] != 'O')
          error("File %s is not a Hermes2D Orderizer<Scalar> file.", filename);
        if (hdr.ver > 1)
          error("File %s -- unsupported file version.", filename);

#define read_array(array, type, n, c, what) \
  if (fread(&n, sizeof(int), 1, f) != 1) \
  error("Error reading the number of " what " from %s", filename); \
  lin_init_array(array, type, c, n); \
  if (fread(array, sizeof(type), n, f) != (unsigned) n) \
  error("Error reading " what " from %s", filename);

        read_array(verts, double3, nv, cv,  "vertices");
        read_array(tris,  int3,    nt, ct,  "triangles");
        read_array(edges, int3,    ne, ce,  "edges");
        read_array(lvert, int,     nl, cl1, "label vertices");

        lin_init_array(lbox, double2, cl3, nl);
        if (fread(lbox, sizeof(double2), nl, f) != (unsigned) nl)
          error("Error reading label bounding boxes from %s", filename);

        int* orders = new int[nl];
        if (fread(orders, sizeof(int), nl, f) != (unsigned) nl)
          error("Error reading element orders from %s", filename);

        lin_init_array(ltext, char*, cl2, nl);
        for (int i = 0; i < nl; i++)
          ltext[i] = labels[H2D_GET_H_ORDER(orders[i])][H2D_GET_V_ORDER(orders[i])];

        find_min_max();
        unlock_data();
        fclose(f);
      }
예제 #13
0
void CPSampleManagerImpl::set_data(CPSample_ID p_id, int p_sample, int16_t p_data, int p_channel) {

	SampleData *sd = _getsd(p_id);
#ifdef DEBUG_ENABLED
	ERR_FAIL_COND(!valid.has(sd));
#endif

	ERR_FAIL();
	lock_data(p_id);

	int sofs = sd->stereo ? 2 : 1;
	if (sd->is16) {
		int16_t *p = (int16_t *)sd->w.ptr();
		p[p_sample * sofs + p_channel] = p_data;
	} else {
		int8_t *p = (int8_t *)sd->w.ptr();
		p[p_sample * sofs + p_channel] = p_data;
	}

	unlock_data(p_id);
}
예제 #14
0
void Vectorizer::save_data(const char* filename)
{
  FILE* f = fopen(filename, "wb");
  if (f == NULL) error("Could not open %s for writing.", filename);
  lock_data();

  if (fwrite("H2DV\001\000\000\000", 1, 8, f) != 8 ||
      fwrite(&nv, sizeof(int), 1, f) != 1 ||
      fwrite(verts, sizeof(double4), nv, f) != nv ||
      fwrite(&nt, sizeof(int), 1, f) != 1 ||
      fwrite(tris, sizeof(int3), nt, f) != nt ||
      fwrite(&ne, sizeof(int), 1, f) != 1 ||
      fwrite(edges, sizeof(int3), ne, f) != ne ||
      fwrite(&nd, sizeof(int), 1, f) != 1 ||
      fwrite(dashes, sizeof(int2), nd, f) != nd)
  {
    error("Error writing data to %s", filename);
  }

  unlock_data();
  fclose(f);
}
예제 #15
0
bool FmMsg::insert(FmMsgQ_entry * src) {
	if (!strcmp(_name, src->dst)) {
		FmMsgEntry dst(*(src->data), OWNERSHIP);

		if (_cnt == _max) {
			_handle(src->data);
			return false;
		}

		while (!lock_data()); // wait for the lock.
		_buf.push(dst);
		unlock_data();

		++_cnt;

		_flag = true;
	} else {
		_flag = false;
	}

	return _flag;
}
예제 #16
0
void
shell_drag_stop(int x, int y)
{

    if (!drawing)
        return;
    lock_data();

    drawing->x += ((float)(x - drag_x)) / drawing->scale;
    drawing->y -= ((float)(y - drag_y)) / drawing->scale;

    append_undo_double((void *)(&(drawing->x)),
                       drawing->old.x, drawing->x, 1, OBJ_DRAWING, NULL);
    append_undo_double((void *)(&(drawing->y)),
                       drawing->old.y, drawing->y, 0, 0, NULL);
    unlock_data();
    drag_x = x;
    drag_y = y;

    drawing_sync();
    drag = 0;
    pointer_pop(0x1500 + POINTER_HAND);
}
예제 #17
0
int16_t CPSampleManagerImpl::get_data(CPSample_ID p_id, int p_sample, int p_channel){

	SampleData *sd=_getsd(p_id);
#ifdef DEBUG_ENABLED
	ERR_FAIL_COND_V(!valid.has(sd),0);
#endif

	ERR_FAIL_V(0);
	lock_data(p_id);

	int sofs = sd->stereo ? 2:1;
	uint16_t v=0;
	if (sd->is16) {
		int16_t *p=(int16_t*)sd->w.ptr();
		v=p[p_sample*sofs+p_channel];
	} else {
		int8_t *p=(int8_t*)sd->w.ptr();
		v=p[p_sample*sofs+p_channel];
	}

	unlock_data(p_id);

	return v;
}
예제 #18
0
int url_check_check_preview(char *preview_data, int preview_data_len,
                            ci_request_t * req)
{
     ci_headers_list_t *req_header;
     struct url_check_data *uc = ci_service_data(req);
     struct http_info httpinf;
     struct profile *profile;
     int pass = DB_PASS;

     if ((req_header = ci_http_request_headers(req)) == NULL) /*It is not possible but who knows ..... */
          return CI_ERROR;

     if (!get_http_info(req, req_header, &httpinf)) /*Unknown method or something else...*/
	 return CI_MOD_ALLOW204;

     ci_debug_printf(9, "URL  to host %s\n", httpinf.site);
     ci_debug_printf(9, "URL  page %s\n", httpinf.url);

     profile = profile_select(req);

     if (!profile) {
          ci_debug_printf(1, "No Profile configured! Allowing the request...\n");
	  return CI_MOD_ALLOW204;
     }

     if ((pass=profile_access(profile, &httpinf)) == DB_ERROR) {
          ci_debug_printf(1,"Error searching in profile! Allow the request\n");
	  return CI_MOD_ALLOW204;;
     }


     if (pass == DB_BLOCK) {
          /*The URL is not a good one so.... */
          ci_debug_printf(9, "Oh!!! we are going to deny this site.....\n");

          uc->denied = 1;
          uc->body = ci_cached_file_new(strlen(error_message) + 10);
          ci_http_response_create(req, 1, 1); /*Build the responce headers */

          ci_http_response_add_header(req, "HTTP/1.0 403 Forbidden"); /*Send an 403 Forbidden http responce to web client */
          ci_http_response_add_header(req, "Server: C-ICAP");
          ci_http_response_add_header(req, "Content-Type: text/html");
          ci_http_response_add_header(req, "Content-Language: en");
          ci_http_response_add_header(req, "Connection: close");

          ci_cached_file_write(uc->body, error_message, strlen(error_message),
                               1);

     }
     else {
          /*if we are inside preview negotiation or client allow204 responces oudsite of preview then */
          if (preview_data || ci_req_allow204(req))
               return CI_MOD_ALLOW204;

          /*
             icap client does not support preview of data in reqmod requests neither 204 responces outside preview
             so we need to read all the body if exists and send it back to client.
             Allocate a new body for it 
           */
          if (ci_req_hasbody(req)) {
               int clen = ci_http_content_length(req) + 100;
               uc->body = ci_cached_file_new(clen);
          }

     }

     unlock_data(req);
     return CI_MOD_CONTINUE;
}
예제 #19
0
파일: request.c 프로젝트: p1rate5s/c-icap
int do_request(ci_request_t * req)
{
     int res, preview_status = 0, auth_status = CI_ACCESS_ALLOW;
     int ret_status = CI_OK; /*By default ret_status is CI_OK, on error must set to CI_ERROR*/
     res = parse_header(req);
     if (res != EC_100) {
          if (res >= 0)
               ec_responce(req, res);   /*Bad request or Service not found or Server error or what else...... */
          req->return_code = res;
          req->keepalive = 0;   // Error occured, close the connection ......
          ci_debug_printf(5, "Error %d while parsing headers :(%d)\n",
			  res ,req->request_header->bufused);
          return CI_ERROR;
     }

     auth_status = req->access_type;
     if ((auth_status = access_check_request(req)) == CI_ACCESS_DENY) {
	 if (req->auth_required) {
	      ec_responce_with_istag(req, EC_407);     /*Responce with bad request */
	      req->return_code = EC_407;
	 }
	 else {
	      ec_responce(req, EC_401);
	      req->return_code = EC_401;
	 }
          return CI_ERROR;      /*Or something that means authentication error */
     }

     if (res == EC_100)
          res = parse_encaps_headers(req);

     if (!req->current_service_mod) {
          ci_debug_printf(1, "Service not found\n");
          ec_responce(req, EC_404);
	  req->return_code = EC_404;
          return CI_ERROR;
     }

     if (req->current_service_mod->mod_init_request_data)
          req->service_data =
              req->current_service_mod->mod_init_request_data(req);
     else
          req->service_data = NULL;

     ci_debug_printf(8, "Requested service: %s\n",
                     req->current_service_mod->mod_name);

     switch (req->type) {
     case ICAP_OPTIONS:
          options_responce(req);
	  req->return_code = EC_200;
          ret_status = CI_OK;
          break;
     case ICAP_REQMOD:
     case ICAP_RESPMOD:
          preview_status = 0;
          if (req->hasbody && req->preview >= 0) {
               /*read_preview_data returns CI_OK, CI_EOF or CI_ERROR */
               if ((preview_status = read_preview_data(req)) == CI_ERROR) {
                    ci_debug_printf(5,
                                    "An error occured while reading preview data (propably timeout)\n");
                    ec_responce(req, EC_408);
		    req->return_code = EC_408;
		    ret_status = CI_ERROR;
                    /*Responce with error..... */
                    break;
               }
               else if (req->current_service_mod->mod_check_preview_handler) {
                    res =
                        req->current_service_mod->
                        mod_check_preview_handler(req->preview_data.buf,
                                                  req->preview_data.used, req);
                    if (res == CI_MOD_ALLOW204) {
			 if (ec_responce_with_istag(req, EC_204) < 0)
			     ret_status = CI_ERROR;
			 req->return_code = EC_204;
                         break; //Need no any modification.
                    }
                    if (res == CI_ERROR) {
                         ci_debug_printf(5,
                                         "An error occured in preview handler!!");
                         ec_responce(req, EC_500);
			 req->return_code = EC_500;
			 ret_status = CI_ERROR;
                         break;
                    }
                    if (preview_status > 0)
                         ec_responce(req, EC_100);
               }
          }
          else if (req->current_service_mod->mod_check_preview_handler) {
               res =
                   req->current_service_mod->mod_check_preview_handler(NULL, 0,
                                                                       req);
               if (req->allow204 && res == CI_MOD_ALLOW204) {
		   if (ec_responce_with_istag(req, EC_204) < 0) {
		       ret_status = CI_ERROR;
		       break;
		   }
		    req->return_code = EC_204;
                    /*And now parse body data we read and data the client going to send us,
                       but do not pass them to the service */
                    if (req->hasbody)
			 ret_status = get_send_body(req, 1);
                    break;
               }
          }

	  req->return_code = EC_200;
          if (req->hasbody && preview_status >= 0) {
               ci_debug_printf(9, "Going to get_send_data.....\n");
               ret_status = get_send_body(req, 0);
               if (ret_status != CI_OK) {
                    ci_debug_printf(5,
                                    "An error occured. Parse error or the client closed the connection (res:%d, preview status:%d)\n",
                                    ret_status, preview_status);
		    ret_status = CI_ERROR;
                    break;
               }
          }

          if (req->current_service_mod->mod_end_of_data_handler) {
               res = req->current_service_mod->mod_end_of_data_handler(req);
/*	       while( req->current_service_mod->mod_end_of_data_handler(req,b)== CI_MOD_NOT_READY){
		    //can send some data here .........
		    }
*/
               if (req->allow204 && res == CI_MOD_ALLOW204) {
		    if (ec_responce_with_istag(req, EC_204) < 0) {
		        ci_debug_printf(5, "An error ocured while sending allow 204 response\n");
		        ret_status = CI_ERROR;
		    }
		    req->return_code = EC_204;
                    break;      //Need no any modification.
               }
          }
          unlock_data(req);
          if ((ret_status = rest_responce(req)) != CI_OK) {
               ci_debug_printf(5,
                               "An error occured while sending rest responce. The client closed the connection (ret_status:%d)\n",
                               ret_status);
	       ret_status = CI_ERROR;
	  }
          break;
     default:
          ret_status = CI_ERROR;
          break;
     }

     if (req->current_service_mod->mod_release_request_data
         && req->service_data)
          req->current_service_mod->mod_release_request_data(req->service_data);

//     debug_print_request(req);
     return ret_status;
}
Sint16 SampleManager_MemPool::get_data(Sample_ID p_id, int p_sample, int p_channel) {
	MemPool_Sample *smp;
	if (!(smp=get_sample(p_id)))
		return 0;
	
	ERR_FAIL_INDEX_V(p_sample,smp->size,0);
	ERR_FAIL_COND_V(p_channel<0,0);
	
	if (smp->stereo) {
		
		ERR_FAIL_COND_V(p_channel>1,0);
	} else {
		
		ERR_FAIL_COND_V(p_channel>0,0);
	}
	

	if (lock_data(p_id)) {
		return 0;
	}
	
	Sint16 res;
	
	if (smp->is_16bits) {
		
		Sint16 *ptr=(Sint16*)get_data( p_id );
		
		if (ptr==0) {
			unlock_data(p_id);
			ERR_FAIL_COND_V(ptr==0,0);
		}
		
		if (smp->stereo)
			p_sample*=2;
		p_sample+=p_channel;
		
		res=ptr[p_sample];
		
		
	} else {
		
		Sint8 *ptr=(Sint8*)get_data( p_id );
		
		if (ptr==0) {
			unlock_data(p_id);
			ERR_FAIL_COND_V(ptr==0,0);
		}
		
		if (smp->stereo)
			p_sample*=2;
		p_sample+=p_channel;
		
		res=ptr[p_sample];
		
		res<<=8;
	}
	unlock_data( p_id );
	

	return res;
}
void SampleManager_MemPool::set_data(Sample_ID p_id, int p_sample, Sint16 p_data,int p_channel) {
	
	MemPool_Sample *smp;
	if (!(smp=get_sample(p_id)))
		return;
	
	ERR_FAIL_COND( p_sample<-1 || (p_sample>smp->size+1));
	ERR_FAIL_COND(p_channel<0);

	if (smp->stereo) {
		
		ERR_FAIL_COND(p_channel>1);
	} else {
		
		ERR_FAIL_COND(p_channel>0);
	}
	
	AudioLock::begin();
	if (lock_data(p_id)) {
		
		AudioLock::end();
		return ;
	}
	
	
	if (smp->is_16bits) {
		
		Sint16 *ptr=(Sint16*)get_data( p_id );
		
		if (ptr==0) {
			unlock_data(p_id);
			AudioLock::end();
			ERR_FAIL_COND(ptr==0);
		}
		
		if (smp->stereo)
			p_sample*=2;
		p_sample+=p_channel;
		
		ptr[p_sample]=p_data;
		
		
	} else {
		
		Sint8 *ptr=(Sint8*)get_data( p_id );
		
		if (ptr==0) {
			unlock_data(p_id);
			AudioLock::end();
			ERR_FAIL_COND(ptr==0);
		}
		
		if (smp->stereo)
			p_sample*=2;
		p_sample+=p_channel;
		
		ptr[p_sample]=p_data>>8;

	}
	
	unlock_data( p_id );
	AudioLock::end();
	
	if ((p_sample>=0 && p_sample<smp->size) && (p_sample==(smp->size-1) ||  (smp->loop.type!=LOOP_NONE && p_sample==smp->loop.begin && smp->loop.begin<(smp->size-1))))
		fix_loop_end( p_id );
}
예제 #22
0
void Vectorizer::process_solution(MeshFunction* xsln, int xitem, MeshFunction* ysln, int yitem, double eps)
{
  // sanity check
  if (xsln == NULL || ysln == NULL) error("One of the solutions is NULL in Vectorizer:process_solution().");


  lock_data();
  TimePeriod cpu_time;

  // initialization
  this->xsln = xsln;
  this->ysln = ysln;
  this->xitem = xitem;
  this->yitem = yitem;
  this->eps = eps;
  nv = nt = ne = nd = 0;
  del_slot = -1;

  Mesh* meshes[2] = { xsln->get_mesh(), ysln->get_mesh() };
  if (meshes[0] == NULL || meshes[1] == NULL) {
    error("One of the meshes is NULL in Vectorizer:process_solution().");
  }

  Transformable* fns[2] = { xsln, ysln };
  Traverse trav;

  // estimate the required number of vertices and triangles
  // (based on the assumption that the linear mesh will be
  // about four-times finer than the original mesh).
  int nn = meshes[0]->get_num_elements() + meshes[1]->get_num_elements();
  int ev = std::max(32 * nn, 10000);
  int et = std::max(64 * nn, 20000);
  int ee = std::max(24 * nn, 7500);
  int ed = ee;

  lin_init_array(verts, double4, cv, ev);
  lin_init_array(tris, int3, ct, et);
  lin_init_array(edges, int3, ce, ee);
  lin_init_array(dashes, int2, cd, ed);

  info = (int4*) malloc(sizeof(int4) * cv);

  // initialize the hash table
  int size = 0x1000;
  while (size*2 < cv) size *= 2;
  hash_table = (int*) malloc(sizeof(int) * size);
  memset(hash_table, 0xff, sizeof(int) * size);
  mask = size-1;


  // select the linearization quadrature
  Quad2D *old_quad_x, *old_quad_y;
  old_quad_x = xsln->get_quad_2d();
  old_quad_y = ysln->get_quad_2d();

  xsln->set_quad_2d((Quad2D*) &quad_lin);
  ysln->set_quad_2d((Quad2D*) &quad_lin);

  if (!xitem) error("Parameter 'xitem' cannot be zero.");
  if (!yitem) error("Parameter 'yitem' cannot be zero.");
  get_gv_a_b(xitem, xia, xib);
  get_gv_a_b(yitem, yia, yib);
  if (xib >= 6) error("Invalid value of paremeter 'xitem'.");
  if (yib >= 6) error("Invalid value of paremeter 'yitem'.");

  max = 1e-10;
  trav.begin(2, meshes, fns);
  Element** e;
  while ((e = trav.get_next_state(NULL, NULL)) != NULL)
  {
    xsln->set_quad_order(0, xitem);
    ysln->set_quad_order(0, yitem);
    scalar* xval = xsln->get_values(xia, xib);
    scalar* yval = ysln->get_values(yia, yib);

    for (unsigned int i = 0; i < e[0]->nvert; i++)
    {
      double fx = getvalx(i);
      double fy = getvaly(i);
      if (fabs(sqrt(fx*fx + fy*fy)) > max) max = fabs(sqrt(fx*fx + fy*fy));
    }
  }
  trav.finish();

  trav.begin(2, meshes, fns);
  // process all elements of the mesh
  while ((e = trav.get_next_state(NULL, NULL)) != NULL)
  {
    xsln->set_quad_order(0, xitem);
    ysln->set_quad_order(0, yitem);
    scalar* xval = xsln->get_values(xia, xib);
    scalar* yval = ysln->get_values(yia, yib);

    double* x = xsln->get_refmap()->get_phys_x(0);
    double* y = ysln->get_refmap()->get_phys_y(0);

    int iv[4];
    for (unsigned int i = 0; i < e[0]->nvert; i++)
    {
      double fx = getvalx(i);
      double fy = getvaly(i);
      iv[i] = create_vertex(x[i], y[i], fx, fy);
    }

    // we won't bother calculating physical coordinates from the refmap if this is not a curved element
    curved = (e[0]->cm != NULL);

    // recur to sub-elements
    if (e[0]->is_triangle())
      process_triangle(iv[0], iv[1], iv[2], 0, NULL, NULL, NULL, NULL, NULL);
    else
      process_quad(iv[0], iv[1], iv[2], iv[3], 0, NULL, NULL, NULL, NULL, NULL);

    // process edges and dashes (bold line for edge in both meshes, dashed line for edge in one of the meshes)
    Trf* xctm = xsln->get_ctm();
    Trf* yctm = ysln->get_ctm();
    double r[4] = { -1.0, 1.0, 1.0, -1.0 };
    double ref[4][2] = { {-1.0,-1.0}, {1.0,-1.0}, {1.0,1.0}, {-1.0,1.0} };
    for (unsigned int i = 0; i < e[0]->nvert; i++)
    {
      bool bold = false;
      double px = ref[i][0];
      double py = ref[i][1];
      // for odd edges (1, 3) we check x coordinate after ctm transformation, if it's the same (1 or -1) in both meshes => bold
      if (i & 1) {
        if ((xctm->m[0]*px + xctm->t[0] == r[i]) && (yctm->m[0]*px + yctm->t[0] == r[i]))
          bold = true;
      }
      // for even edges (0, 4) we check y coordinate after ctm transformation, if it's the same (-1 or 1) in both meshes => bold
      else {
        if ((xctm->m[1]*py + xctm->t[1] == r[i]) && (yctm->m[1]*py + yctm->t[1] == r[i]))
          bold = true;
      }
      int j = e[0]->next_vert(i);
      // we draw a line only if both edges lies on the boundary or if the line is from left top to right bottom
      if (((e[0]->en[i]->bnd) && (e[1]->en[i]->bnd)) ||
         (verts[iv[i]][1] < verts[iv[j]][1]) ||
         (verts[iv[i]][1] == verts[iv[j]][1] && verts[iv[i]][0] < verts[iv[j]][0]))
      {
        if (bold)
          process_edge(iv[i], iv[j], e[0]->en[i]->marker);
        else
          process_dash(iv[i], iv[j]);
      }
    }
  }
  trav.finish();

  find_min_max();

  verbose("Vectorizer created %d verts and %d tris in %0.3g s", nv, nt, cpu_time.tick().last());
  //if (verbose_mode) print_hash_stats();
  unlock_data();

   // select old quadratrues
  xsln->set_quad_2d(old_quad_x);
  ysln->set_quad_2d(old_quad_y);

  // clean up
  ::free(hash_table);
  ::free(info);

}