void avbv_v(lhs_rhs_element & vec1,
                  lhs_rhs_element const & vec2, ScalarType1 const & alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha,
                  lhs_rhs_element const & vec3, ScalarType2 const & beta,  vcl_size_t len_beta,  bool reciprocal_beta,  bool flip_sign_beta)
      {
        assert(   vec1.type_family == VECTOR_TYPE_FAMILY && vec1.subtype == DENSE_VECTOR_TYPE
               && vec2.type_family == VECTOR_TYPE_FAMILY && vec2.subtype == DENSE_VECTOR_TYPE
               && vec3.type_family == VECTOR_TYPE_FAMILY && vec3.subtype == DENSE_VECTOR_TYPE
               && bool("Arguments are not vector types!"));

        switch (vec1.numeric_type)
        {
          case FLOAT_TYPE:
            assert(vec2.numeric_type == FLOAT_TYPE && vec3.numeric_type == FLOAT_TYPE && bool("Vectors do not have the same scalar type"));
            viennacl::linalg::avbv_v(*vec1.vector_float,
                                     *vec2.vector_float, convert_to_float(alpha), len_alpha, reciprocal_alpha, flip_sign_alpha,
                                     *vec3.vector_float, convert_to_float(beta),  len_beta,  reciprocal_beta,  flip_sign_beta);
            break;
          case DOUBLE_TYPE:
            assert(vec2.numeric_type == DOUBLE_TYPE && vec3.numeric_type == DOUBLE_TYPE && bool("Vectors do not have the same scalar type"));
            viennacl::linalg::avbv_v(*vec1.vector_double,
                                     *vec2.vector_double, convert_to_double(alpha), len_alpha, reciprocal_alpha, flip_sign_alpha,
                                     *vec3.vector_double, convert_to_double(beta),  len_beta,  reciprocal_beta,  flip_sign_beta);
            break;
          default:
            throw statement_not_supported_exception("Invalid arguments in scheduler when calling avbv_v()");
        }
      }
Пример #2
0
// Perform at most one value conversion from the following set:
//
//    - integer conversions
//    - float conversions
//    - numeric conversions (int to float)
//    - boolean conversions
//
// TODO: Support conversion of T[N] to T[].
//
// TODO: Support pointer conversions.
//
// TODO: Support character conversions separately from integer
// conversions?
//
// TODO: Why are references not converted in C++?
Expr&
convert_value(Expr& e, Type& t)
{
  // Value conversions do not apply to reeference types.
  if (is<Reference_type>(&e.type()))
    return e;

  // Ignore qualifications in this comparison. Value categories
  // include the cv-qualified versions of types.
  Type& u = t.unqualified_type();

  // Try a boolean conversion.
  if (Boolean_type* b = as<Boolean_type>(&u))
    return convert_to_bool(e, *b);

  // Try an integer conversion.
  if (Integer_type* z = as<Integer_type>(&u))
    return convert_to_wider_integer(e, *z);

  // Try one of the floating point conversions.
  if (Float_type* f = as<Float_type>(&u))
    return convert_to_float(e, *f);

  return e;
}
Пример #3
0
int CMixer::Mixing(float* pOutput, int out_samples, BYTE* pInput, int in_samples)
{
    int in_ch  = av_popcount(m_in_layout);
    int out_ch = av_popcount(m_out_layout);

    float* buf  = NULL;
    if (m_in_avsf != m_in_avsf_used) { // need convert
        buf = new float[in_samples * in_ch];
        convert_to_float(m_in_avsf, (WORD)in_ch, in_samples, pInput, buf); // convert to float
        pInput = (BYTE*)buf;
    }

    // int in_plane_size  = in_samples * (av_sample_fmt_is_planar(in_avsf) ? 1 : in_ch) * av_get_bytes_per_sample(in_avsf);
    int in_plane_size  = in_samples * in_ch * av_get_bytes_per_sample(m_in_avsf_used);
    int out_plane_size = out_samples * out_ch * sizeof(float);

    out_samples = avresample_convert(m_pAVRCxt, (uint8_t**)&pOutput, in_plane_size, out_samples, (uint8_t**)&pInput, out_plane_size, in_samples);
    if (buf) {
        delete [] buf;
    }
    if (out_samples < 0) {
        TRACE(_T("Mixer: avresample_convert failed\n"));
        return 0;
    }

    return out_samples;
}
Пример #4
0
void
uncouple(bsi_t *bsi,audblk_t *audblk,stream_coeffs_t *coeffs)
{
	int i,j;

	for(i=0; i< bsi->nfchans; i++)
	{
		for(j=0; j < audblk->endmant[i]; j++)
			 convert_to_float(audblk->fbw_exp[i][j],audblk->chmant[i][j],
					 (uint_32*) &coeffs->fbw[i][j]);
	}

	if(audblk->cplinu)
	{

		for(j=audblk->cplstrtmant; j < audblk->cplendmant; j++)
			 convert_to_float(audblk->cpl_exp[j],audblk->cplmant[j],
					(uint_32*) &cpl_tmp[j]);

		for(i=0; i< bsi->nfchans; i++)
		{
			if(audblk->chincpl[i])
			{
				uncouple_channel(coeffs,audblk,i, bsi );
			}
		}

	}

	if(bsi->lfeon)
	{
		/* There are always 7 mantissas for lfe */
		for(j=0; j < 7 ; j++)
			 convert_to_float(audblk->lfe_exp[j],audblk->lfemant[j],
					 (uint_32*) &coeffs->lfe[j]);

	}
}
void as(lhs_rhs_element & s1,
        lhs_rhs_element const & s2, ScalarType1 const & alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha)
{
  assert(   s1.type_family == SCALAR_TYPE_FAMILY && (s1.subtype == HOST_SCALAR_TYPE || s1.subtype == DEVICE_SCALAR_TYPE)
            && s2.type_family == SCALAR_TYPE_FAMILY && (s2.subtype == HOST_SCALAR_TYPE || s2.subtype == DEVICE_SCALAR_TYPE)
            && bool("Arguments are not vector types!"));

  switch (s1.numeric_type)
  {
  case FLOAT_TYPE:
    assert(s2.numeric_type == FLOAT_TYPE && bool("Vectors do not have the same scalar type"));
    viennacl::linalg::av(*s1.vector_float,
                         *s2.vector_float, convert_to_float(alpha), len_alpha, reciprocal_alpha, flip_sign_alpha);
    break;
  case DOUBLE_TYPE:
    assert(s2.numeric_type == DOUBLE_TYPE && bool("Vectors do not have the same scalar type"));
    viennacl::linalg::av(*s1.vector_double,
                         *s2.vector_double, convert_to_double(alpha), len_alpha, reciprocal_alpha, flip_sign_alpha);
    break;
  default:
    throw statement_not_supported_exception("Invalid arguments in scheduler when calling av()");
  }
}
Пример #6
0
string styles_view (void * webserver_request)
{
  Webserver_Request * request = (Webserver_Request *) webserver_request;
  
  string page;
  
  Assets_Header header = Assets_Header (translate("Style"), webserver_request);
  header.addBreadCrumb (menu_logic_settings_menu (), menu_logic_settings_text ());
  header.addBreadCrumb (styles_indexm_url (), menu_logic_styles_indexm_text ());
  page = header.run ();
  
  Assets_View view;


  Database_Styles database_styles;
  
  
  string sheet = request->query ["sheet"];
  view.set_variable ("sheet", filter_string_sanitize_html (sheet));
  
  
  string style = request->query ["style"];
  view.set_variable ("style", filter_string_sanitize_html (style));

  
  Database_Styles_Item marker_data = database_styles.getMarkerData (sheet, style);
  
  
  // Whether the logged-in user has write access to the stylesheet.
  string username = request->session_logic ()->currentUser ();
  int userlevel = request->session_logic ()->currentLevel ();
  bool write = database_styles.hasWriteAccess (username, sheet);
  if (userlevel >= Filter_Roles::admin ()) write = true;
  

  // The style's name.
  string name = marker_data.name;
  if (request->query.count ("name")) {
    Dialog_Entry dialog_entry = Dialog_Entry ("view", translate("Please enter the name for the style"), name, "name", "");
    dialog_entry.add_query ("sheet", sheet);
    dialog_entry.add_query ("style", style);
    page += dialog_entry.run ();
    return page;
  }
  if (request->post.count ("name")) {
    name = request->post["entry"];
    if (write) database_styles.updateName (sheet, style, name);
  }
  view.set_variable ("name", filter_string_sanitize_html (name));
  

  // The style's info.
  string info = marker_data.info;
  if (request->query.count ("info")) {
    Dialog_Entry dialog_entry = Dialog_Entry ("view", translate("Please enter the description for the style"), info, "info", "");
    dialog_entry.add_query ("sheet", sheet);
    dialog_entry.add_query ("style", style);
    page += dialog_entry.run ();
    return page;
  }
  if (request->post.count("info")) {
    info = request->post["entry"];
    if (write) database_styles.updateInfo (sheet, style, info);
  }
  view.set_variable ("info", filter_string_sanitize_html (info));
  
  
  // The style's category.
  string category = marker_data.category;
  if (request->query.count("category")) {
    category = request->query["category"];
    if (category == "") {
      Dialog_List dialog_list = Dialog_List ("view", translate("Would you like to change the category of this style?"),translate("Here are the various categories:"), translate("Please pick one."));
      dialog_list.add_query ("sheet", sheet);
      dialog_list.add_query ("style", style);
      dialog_list.add_row (styles_logic_category_text ("id"),  "category", "id");
      dialog_list.add_row (styles_logic_category_text ("ith"), "category", "ith");
      dialog_list.add_row (styles_logic_category_text ("ipp"), "category", "ipp");
      dialog_list.add_row (styles_logic_category_text ("ioe"), "category", "ioe");
      dialog_list.add_row (styles_logic_category_text ("t"),   "category", "t");
      dialog_list.add_row (styles_logic_category_text ("h"),   "category", "h");
      dialog_list.add_row (styles_logic_category_text ("cv"),  "category", "cv");
      dialog_list.add_row (styles_logic_category_text ("p"),   "category", "p");
      dialog_list.add_row (styles_logic_category_text ("l"),   "category", "l");
      dialog_list.add_row (styles_logic_category_text ("pe"),  "category", "pe");
      dialog_list.add_row (styles_logic_category_text ("te"),  "category", "te");
      dialog_list.add_row (styles_logic_category_text ("f"),   "category", "f");
      dialog_list.add_row (styles_logic_category_text ("x"),   "category", "x");
      dialog_list.add_row (styles_logic_category_text ("xsn"), "category", "xsn");
      dialog_list.add_row (styles_logic_category_text ("st"),  "category", "st");
      dialog_list.add_row (styles_logic_category_text ("cs"),  "category", "cs");
      dialog_list.add_row (styles_logic_category_text ("sb"),  "category", "sb");
      dialog_list.add_row (styles_logic_category_text ("sf"),  "category", "sf");
      dialog_list.add_row (styles_logic_category_text ("pm"),  "category", "pm");
      dialog_list.add_row (styles_logic_category_text (""),    "category", "");
      page += dialog_list.run ();
      return page;
    } else {
      if (write) database_styles.updateCategory (sheet, style, category);
    }
  }
  view.set_variable ("category", styles_logic_category_text(category));

  
  // The style's type.
  int type = marker_data.type;
  if (request->query.count ("type")) {
    string s = request->query["type"];
    type = convert_to_int (s);
    if (s == "") {
      Dialog_List dialog_list = Dialog_List ("view", translate("Would you like to change the type of this style?"), translate("Here are the various types:"), translate("Please pick one."));
      dialog_list.add_query ("sheet", sheet);
      dialog_list.add_query ("style", style);
      for (int i = 0; i < 99; i++) {
        string text = styles_logic_type_text (i);
        if (text.length () > 2) {
          dialog_list.add_row (text, "type", convert_to_string (i));
        }
      }
      page += dialog_list.run ();
      return page;
    } else {
      if (write) database_styles.updateType (sheet, style, type);
    }
  }
  view.set_variable ("type", convert_to_string (type));
  view.set_variable ("type_text", styles_logic_type_text (type));
  

  // The style's subtype.
  int subtype = marker_data.subtype;
  if (request->query.count ("subtype")) {
    string s = request->query["subtype"];
    subtype = convert_to_int (s);
    if (s == "") {
      Dialog_List dialog_list = Dialog_List ("view", translate("Would you like to change the sub type of this style?"), "", "");
      dialog_list.add_query ("sheet", sheet);
      dialog_list.add_query ("style", style);
      Database_Styles_Item marker_data = database_styles.getMarkerData (sheet, style);
      int type = marker_data.type;
      for (int i = 0; i < 99; i++) {
        string text = styles_logic_subtype_text (type, i);
        if (text.length () > 2) {
          dialog_list.add_row (text, "subtype", convert_to_string (i));
        }
      }
      page += dialog_list.run ();
      return page;
    } else {
      if (write) database_styles.updateSubType (sheet, style, subtype);
    }
  }
  view.set_variable ("subtype",convert_to_string (subtype));
  string subtype_text = styles_logic_subtype_text (type, subtype);
  view.set_variable ("subtype_text", subtype_text);
  if (subtype_text.length () > 2) view.enable_zone ("subtype_text");
  
  
  // The fontsize.
  if (styles_logic_fontsize_is_relevant (type, subtype)) view.enable_zone ("fontsize_relevant");
  float fontsize = marker_data.fontsize;
  if (request->query.count ("fontsize")) {
    Dialog_Entry dialog_entry = Dialog_Entry ("view", translate("Please enter a fontsize between 5 and 60 points"), convert_to_string (fontsize), "fontsize", translate ("The value to enter is just a number, e.g. 12."));
    dialog_entry.add_query ("sheet", sheet);
    dialog_entry.add_query ("style", style);
    page += dialog_entry.run ();
    return page;
  }
  if (request->post.count("fontsize")) {
    float fs = convert_to_float (request->post["entry"]);
    if ((fs >= 5) && (fs <= 60)) {
      fontsize = fs;
      if (write) database_styles.updateFontsize (sheet, style, fontsize);
    }
  }
  view.set_variable ("fontsize", convert_to_string (fontsize));


  // Italics, bold, underline, small caps relevance.
  if (styles_logic_italic_bold_underline_smallcaps_are_relevant (type, subtype)) view.enable_zone ("ibus_relevant");

  
  // Italic.
  int italic = marker_data.italic;
  if (request->query.count ("italic")) {
    string s = request->query["italic"];
    if (s == "") {
      Dialog_List dialog_list = Dialog_List ("view", translate("Would you like to change whether this style is in italics?"), "", "");
      dialog_list.add_query ("sheet", sheet);
      dialog_list.add_query ("style", style);
      Database_Styles_Item marker_data = database_styles.getMarkerData (sheet, style);
      int last_value = ooitOn;
      if (styles_logic_italic_bold_underline_smallcaps_are_full (marker_data.type, marker_data.subtype))
        last_value = ooitToggle;
      for (int i = 0; i <= last_value; i++) {
        dialog_list.add_row (styles_logic_off_on_inherit_toggle_text (i), "italic", convert_to_string (i));
      }
      page += dialog_list.run ();
      return page;
    } else {
      italic = convert_to_int (s);
      if (write) database_styles.updateItalic (sheet, style, italic);
    }
  }
  view.set_variable ("italic", styles_logic_off_on_inherit_toggle_text (italic));
  

  // Bold.
  int bold = marker_data.bold;
  if (request->query.count ("bold")) {
    string s = request->query["bold"];
    if (s == "") {
      Dialog_List dialog_list = Dialog_List ("view", translate("Would you like to change whether this style is in bold?"), "", "");
      dialog_list.add_query ("sheet", sheet);
      dialog_list.add_query ("style", style);
      Database_Styles_Item marker_data = database_styles.getMarkerData (sheet, style);
      int last_value = ooitOn;
      if (styles_logic_italic_bold_underline_smallcaps_are_full (marker_data.type, marker_data.subtype))
        last_value = ooitToggle;
      for (int i = 0; i <= last_value; i++) {
        dialog_list.add_row (styles_logic_off_on_inherit_toggle_text (i), "bold", convert_to_string (i));
      }
      page += dialog_list.run ();
      return page;
    } else {
      bold = convert_to_int (s);
      if (write) database_styles.updateBold (sheet, style, bold);
    }
  }
  view.set_variable ("bold", styles_logic_off_on_inherit_toggle_text (bold));
  

  // Underline.
  int underline = marker_data.underline;
  if (request->query.count ("underline")) {
    string s = request->query["underline"];
    if (s == "") {
      Dialog_List dialog_list = Dialog_List ("view", translate("Would you like to change whether this style is underlined?"), "", "");
      dialog_list.add_query ("sheet", sheet);
      dialog_list.add_query ("style", style);
      Database_Styles_Item marker_data = database_styles.getMarkerData (sheet, style);
      int last_value = ooitOn;
      if (styles_logic_italic_bold_underline_smallcaps_are_full (type, subtype))
        last_value = ooitToggle;
      for (int i = 0; i <= last_value; i++) {
        dialog_list.add_row (styles_logic_off_on_inherit_toggle_text (i), "underline", convert_to_string (i));
      }
      page += dialog_list.run ();
      return page;
    } else {
      underline = convert_to_int (s);
      if (write) database_styles.updateUnderline (sheet, style, underline);
    }
  }
  view.set_variable ("underline", styles_logic_off_on_inherit_toggle_text (underline));

  
  // Small caps.
  int smallcaps = marker_data.smallcaps;
  if (request->query.count ("smallcaps")) {
    string s = request->query["smallcaps"];
    if (s == "") {
      Dialog_List dialog_list = Dialog_List ("view", translate("Would you like to change whether this style is in small caps?"), "", "");
      dialog_list.add_query ("sheet", sheet);
      dialog_list.add_query ("style", style);
      Database_Styles_Item marker_data = database_styles.getMarkerData (sheet, style);
      int last_value = ooitOn;
      if (styles_logic_italic_bold_underline_smallcaps_are_full (marker_data.type, marker_data.subtype))
        last_value = ooitToggle;
      for (int i = 0; i <= last_value; i++) {
        dialog_list.add_row (styles_logic_off_on_inherit_toggle_text (i), "smallcaps", convert_to_string (i));
      }
      page += dialog_list.run ();
      return page;
    } else {
      smallcaps = convert_to_int (s);
      if (write) database_styles.updateSmallcaps (sheet, style, smallcaps);
    }
  }
  view.set_variable ("smallcaps", styles_logic_off_on_inherit_toggle_text (smallcaps));
  
  
  // Superscript.
  if (styles_logic_superscript_is_relevant (type, subtype)) view.enable_zone ("superscript_relevant");
  int superscript = marker_data.superscript;
  if (request->query.count ("superscript")) {
    superscript = convert_to_int (request->query["superscript"]);
    if (write) database_styles.updateSuperscript (sheet, style, superscript);
  }
  view.set_variable ("superscript_value", styles_logic_off_on_inherit_toggle_text (superscript));
  view.set_variable ("superscript_toggle", convert_to_string (!(bool) superscript));
  

  // Whether a list of the following paragraph treats are relevant.
  if (styles_logic_paragraph_treats_are_relevant (type, subtype)) view.enable_zone ("paragraph_treats_relevant");

  
  // Text alignment.
  int justification = marker_data.justification;
  if (request->query.count ("alignment")) {
    Dialog_List dialog_list = Dialog_List ("view", translate("Would you like to change the text alignment of this style?"), "", "");
    dialog_list.add_query ("sheet", sheet);
    dialog_list.add_query ("style", style);
    for (int i = AlignmentLeft; i <= AlignmentJustify; i++) {
      dialog_list.add_row (styles_logic_alignment_text (i), "justification", convert_to_string (i));
    }
    page += dialog_list.run ();
    return page;
  }
  if (request->query.count ("justification")) {
    justification = convert_to_int (request->query["justification"]);
    if (write) database_styles.updateJustification (sheet, style, justification);
  }
  view.set_variable ("justification", styles_logic_alignment_text (justification));
  

  // Space before paragraph.
  float spacebefore = marker_data.spacebefore;
  if (request->query.count ("spacebefore")) {
    Dialog_Entry dialog_entry = Dialog_Entry ("view", translate("Please enter a space of between 0 and 100 mm before the paragraph"), convert_to_string (spacebefore), "spacebefore", translate ("This is the space before, or in other words, above the paragraph. The value to enter is just a number, e.g. 0."));
    dialog_entry.add_query ("sheet", sheet);
    dialog_entry.add_query ("style", style);
    page += dialog_entry.run ();
    return page;
  }
  if (request->post.count ("spacebefore")) {
    spacebefore = convert_to_float (request->post["entry"]);
    if (spacebefore < 0) spacebefore = 0;
    if (spacebefore > 100) spacebefore = 100;
    if (write) database_styles.updateSpaceBefore (sheet, style, spacebefore);
  }
  view.set_variable ("spacebefore", convert_to_string (spacebefore));
  

  // Space after paragraph.
  float spaceafter = marker_data.spaceafter;
  if (request->query.count ("spaceafter")) {
    Dialog_Entry dialog_entry = Dialog_Entry ("view", translate("Please enter a space of between 0 and 100 mm after the paragraph"), convert_to_string (spaceafter), "spaceafter", translate ("This is the space after, or in other words, below the paragraph. The value to enter is just a number, e.g. 0."));
    dialog_entry.add_query ("sheet", sheet);
    dialog_entry.add_query ("style", style);
    page += dialog_entry.run ();
    return page;
  }
  if (request->post.count("spaceafter")) {
    spaceafter = convert_to_float (request->post["entry"]);
    if (spaceafter < 0) spaceafter = 0;
    if (spaceafter > 100) spaceafter = 100;
    if (write) database_styles.updateSpaceAfter (sheet, style, spaceafter);
  }
  view.set_variable ("spaceafter", convert_to_string (spaceafter));
  

  // Left margin.
  float leftmargin = marker_data.leftmargin;
  if (request->query.count ("leftmargin")) {
    Dialog_Entry dialog_entry = Dialog_Entry ("view", translate("Please enter a left margin of between -100 and 100 mm"), convert_to_string (leftmargin), "leftmargin", translate ("This is the left margin of the paragraph. The value to enter is just a number, e.g. 0."));
    dialog_entry.add_query ("sheet", sheet);
    dialog_entry.add_query ("style", style);
    page += dialog_entry.run ();
    return page;
  }
  if (request->post.count("leftmargin")) {
    leftmargin = convert_to_float (request->post ["entry"]);
    if (leftmargin < 0) leftmargin = 0;
    if (leftmargin > 100) leftmargin = 100;
    if (write) database_styles.updateLeftMargin (sheet, style, leftmargin);
  }
  view.set_variable ("leftmargin", convert_to_string (leftmargin));

  
  // Right margin.
  float rightmargin = marker_data.rightmargin;
  if (request->query.count ("rightmargin")) {
    Dialog_Entry dialog_entry = Dialog_Entry ("view", translate("Please enter a right margin of between -100 and 100 mm"), convert_to_string (rightmargin), "rightmargin", translate ("This is the right margin of the paragraph. The value to enter is just a number, e.g. 0."));
    dialog_entry.add_query ("sheet", sheet);
    dialog_entry.add_query ("style", style);
    page += dialog_entry.run ();
    return page;
  }
  if (request->post.count("rightmargin")) {
    rightmargin = convert_to_float (request->post["entry"]);
    if (rightmargin < -100) rightmargin = -100;
    if (rightmargin > 100) rightmargin = 100;
    if (write) database_styles.updateRightMargin (sheet, style, rightmargin);
  }
  view.set_variable ("rightmargin", convert_to_string (rightmargin));
  
  
  // First line indent.
  float firstlineindent = marker_data.firstlineindent;
  if (request->query.count ("firstlineindent")) {
    Dialog_Entry dialog_entry = Dialog_Entry ("view", translate("Please enter a first line indent of between -100 and 100 mm"), convert_to_string (firstlineindent), "firstlineindent", translate ("This is the indent of the first line of the the paragraph. The value to enter is just a number, e.g. 0."));
    dialog_entry.add_query ("sheet", sheet);
    dialog_entry.add_query ("style", style);
    page += dialog_entry.run ();
    return page;
  }
  if (request->post.count ("firstlineindent")) {
    firstlineindent = convert_to_float (request->post["entry"]);
    if (firstlineindent < -100) firstlineindent = -100;
    if (firstlineindent > 100) firstlineindent = 100;
    if (write) database_styles.updateFirstLineIndent (sheet, style, firstlineindent);
  }
  view.set_variable ("firstlineindent", convert_to_string (firstlineindent));

  
  // Columns spanning.
  if (styles_logic_columns_are_relevant (type, subtype)) view.enable_zone ("columns_relevant");
  bool spancolumns = marker_data.spancolumns;
  if (request->query.count ("spancolumns")) {
    spancolumns = convert_to_bool (request->query["spancolumns"]);
    if (write) database_styles.updateSpanColumns (sheet, style, spancolumns);
  }
  view.set_variable ("spancolumns", styles_logic_off_on_inherit_toggle_text (spancolumns));
  view.set_variable ("spancolumns_toggle", convert_to_string (!spancolumns));

  
  // Color.
  if (styles_logic_color_is_relevant (type, subtype)) view.enable_zone ("color_relevant");
  
  string color = marker_data.color;
  if (request->query.count ("textcolor")) {
    color = request->query["color"];
    if (color == "") {
      Dialog_Color dialog_color = Dialog_Color ("view", translate("Please specify a new color"));
      dialog_color.add_query ("textcolor", "true");
      dialog_color.add_query ("sheet", sheet);
      dialog_color.add_query ("style", style);
      page += dialog_color.run ();
      return page;
    } else {
      if (color.find ("#") == string::npos) color.insert (0, "#");
      if (color.length () != 7) color = "#000000";
      if (write) database_styles.updateColor (sheet, style, color);
    }
  }
  view.set_variable ("color", color);

  string backgroundcolor = marker_data.backgroundcolor;
  if (request->query.count ("backgroundcolor")) {
    backgroundcolor = request->query["color"];
    if (backgroundcolor == "") {
      Dialog_Color dialog_color = Dialog_Color ("view", translate("Please specify a new color"));
      dialog_color.add_query ("backgroundcolor", "true");
      dialog_color.add_query ("sheet", sheet);
      dialog_color.add_query ("style", style);
      page += dialog_color.run ();
      return page;
    } else {
      if (backgroundcolor.find ("#") == string::npos) backgroundcolor.insert (0, "#");
      if (backgroundcolor.length () != 7) backgroundcolor = "#FFFFFF";
      if (write) {
        database_styles.updateBackgroundColor (sheet, style, backgroundcolor);
      }
    }
  }
  view.set_variable ("backgroundcolor", backgroundcolor);


  // Whether to print this style.
  if (styles_logic_print_is_relevant (type, subtype)) view.enable_zone ("print_relevant");
  bool print = marker_data.print;
  if (request->query.count ("print")) {
    print = convert_to_bool (request->query["print"]);
    if (write) database_styles.updatePrint (sheet, style, print);
  }
  view.set_variable ("print", styles_logic_off_on_inherit_toggle_text (print));
  view.set_variable ("print_toggle", convert_to_string (!print));
  

  // Userbool1
  string userbool1_function = styles_logic_get_userbool1_text (styles_logic_get_userbool1_function (type, subtype));
  if (userbool1_function.length () > 2) view.enable_zone ("userbool1_relevant");
  view.set_variable ("userbool1_function", userbool1_function);
  bool userbool1 = marker_data.userbool1;
  if (request->query.count ("userbool1")) {
    userbool1 = convert_to_bool (request->query["userbool1"]);
    if (write) database_styles.updateUserbool1 (sheet, style, userbool1);
  }
  view.set_variable ("userbool1_value", styles_logic_off_on_inherit_toggle_text (userbool1));
  view.set_variable ("userbool1_toggle", convert_to_string (!userbool1));

  
  // Userbool2
  string userbool2_function = styles_logic_get_userbool2_text (styles_logic_get_userbool2_function (type, subtype));
  if (userbool2_function.length () > 2) view.enable_zone ("userbool2_relevant");
  view.set_variable ("userbool2_function", userbool2_function);
  bool userbool2 = marker_data.userbool2;
  if (request->query.count ("userbool2")) {
    userbool2 = convert_to_bool (request->query["userbool2"]);
    if (write) database_styles.updateUserbool2 (sheet, style, userbool2);
  }
  view.set_variable ("userbool2_value", styles_logic_off_on_inherit_toggle_text (userbool2));
  view.set_variable ("userbool2_toggle", convert_to_string (!userbool2));

  
  // Userbool3
  string userbool3_function = styles_logic_get_userbool3_text (styles_logic_get_userbool3_function (type, subtype));
  if (userbool3_function.length () > 2) view.enable_zone ("userbool3_relevant");
  view.set_variable ("userbool3_function", userbool3_function);
  bool userbool3 = marker_data.userbool3;
  if (request->query.count ("userbool3")) {
    userbool3 = convert_to_bool (request->query["userbool3"]);
    if (write) database_styles.updateUserbool3 (sheet, style, userbool3);
  }
  view.set_variable ("userbool3_value", styles_logic_off_on_inherit_toggle_text (userbool3));
  view.set_variable ("userbool3_toggle", convert_to_string (!userbool3));

  
  // Userint1.
  int userint1 = marker_data.userint1;
  switch (styles_logic_get_userint1_function (type, subtype)) {
    case UserInt1None :
      break;
    case UserInt1NoteNumbering :
      view.enable_zone ("userint1_notenumbering");
      if (request->query.count ("notenumbering")) {
        Dialog_List dialog_list = Dialog_List ("view", translate("Would you like to change the numbering of the note?"), "", "");
        dialog_list.add_query ("sheet", sheet);
        dialog_list.add_query ("style", style);
        for (int i = NoteNumbering123; i <= NoteNumberingUser; i++) {
          dialog_list.add_row (styles_logic_note_numbering_text (i), "userint1", convert_to_string (i));
        }
        page += dialog_list.run ();
        return page;
      }
      if (request->query.count ("userint1")) {
        userint1 = convert_to_int (request->query["userint1"]);
        if (write) database_styles.updateUserint1 (sheet, style, userint1);
      }
      view.set_variable ("userint1", styles_logic_note_numbering_text (userint1));
      break;
    case UserInt1TableColumnNumber :
      view.enable_zone ("userint1_columnnumber");
      if (request->query.count ("userint1")) {
        Dialog_Entry dialog_entry = Dialog_Entry ("view", translate("Please enter a column number between 1 and 4"), convert_to_string (userint1), "userint1", translate ("This is the column number for the style. The first columm is number 1."));
        dialog_entry.add_query ("sheet", sheet);
        dialog_entry.add_query ("style", style);
        page += dialog_entry.run ();
        return page;
      }
      if (request->post.count ("userint1")) {
        int value = convert_to_int (request->post["entry"]);
        if ((value >= 1) && (value <= 4)) {
          userint1 = value;
          if (write) database_styles.updateUserint1 (sheet, style, userint1);
        }
      }
      view.set_variable ("userint1", convert_to_string (userint1));
      break;
  }
  
  
  // Userint2.
  int userint2 = marker_data.userint2;
  switch (styles_logic_get_userint2_function (type, subtype)) {
    case UserInt2None :
      break;
    case UserInt2NoteNumberingRestart :
      view.enable_zone ("userint2_notenumberingrestart");
      if (request->query.count ("notenumberingrestart")) {
        Dialog_List dialog_list = Dialog_List ("view", translate("Would you like to change when the note numbering restarts?"), "", "");
        dialog_list.add_query ("sheet", sheet);
        dialog_list.add_query ("style", style);
        for (int i = NoteRestartNumberingNever; i <= NoteRestartNumberingEveryChapter; i++) {
          dialog_list.add_row (styles_logic_note_restart_numbering_text (i), "userint2", convert_to_string (i));
        }
        page += dialog_list.run ();
        return page;
      }
      if (request->query.count ("userint2")) {
        userint2 = convert_to_int (request->query["userint2"]);
        if (write) database_styles.updateUserint2 (sheet, style, userint2);
      }
      view.set_variable ("userint2", styles_logic_note_restart_numbering_text (userint2));
      break;
    case UserInt2EndnotePosition :
      view.enable_zone ("userint2_endnoteposition");
      if (request->query.count ("endnoteposition")) {
        Dialog_List dialog_list = Dialog_List ("view", translate("Would you like to change the position where to dump the endnotes?"), "", "");
        dialog_list.add_query ("sheet", sheet);
        dialog_list.add_query ("style", style);
        for (int i = EndNotePositionAfterBook; i <= EndNotePositionAtMarker; i++) {
          dialog_list.add_row (styles_logic_end_note_position_text (i), "userint2", convert_to_string(i));
        }
        page += dialog_list.run ();
        return page;
      }
      if (request->query.count ("userint2")) {
        userint2 = convert_to_int (request->query["userint2"]);
        if (write) database_styles.updateUserint2 (sheet, style, userint2);
      }
      view.set_variable ("userint2", styles_logic_end_note_position_text (userint2));
      break;
  }

  
  // Userint3 not yet used.
  

  // Userstring1.
  string userstring1 = marker_data.userstring1;
  string userstring1_question;
  string userstring1_help;
  switch (styles_logic_get_userstring1_function (type, subtype)) {
    case UserString1None :
      break;
    case UserString1NoteNumberingSequence :
      if (userint1 == NoteNumberingUser) {
        view.enable_zone ("userstring1_numberingsequence");
        userstring1_question = translate("Please enter a new note numbering sequence");
        userstring1_help = translate("This gives a sequence for numbering the notes. When for example § † * is entered, the numbering goes like §, †, *, §, †, *, and so forth. Any sequence of characters can be used. Spaces should separate the characters");
      }
      break;
    case UserString1WordListEntryAddition :
      view.enable_zone ("userstring1_wordlistaddition");
      userstring1_question = translate("Please enter a new addition to the word list entry");
      userstring1_help = translate("This given an optional string to be added after each definition in the body of text. In some Bibles the unusual words are marked with an asterisk and then explained in a glossary. If you would enter the asterisk here, or indeed any string, Bibledit would include this in the exported documents.");
      break;
  }
  if (request->query.count ("userstring1")) {
    Dialog_Entry dialog_entry = Dialog_Entry ("view", userstring1_question, userstring1, "userstring1", userstring1_help);
    dialog_entry.add_query ("sheet", sheet);
    dialog_entry.add_query ("style", style);
    page += dialog_entry.run ();
    return page;
  }
  if (request->post.count ("userstring1")) {
    userstring1 = request->post["entry"];
    if (write) database_styles.updateUserstring1 (sheet, style, userstring1);
  }
  if (userstring1 == "") userstring1 = "--";
  view.set_variable ("userstring1", filter_string_sanitize_html (userstring1));
  

  // Userstring2
  string userstring2 = marker_data.userstring2;
  string userstring2_question;
  string userstring2_info;
  switch (styles_logic_get_userstring2_function (type, subtype)) {
    case UserString2None :
      break;
    case UserString2DumpEndnotesHere :
      if (userint2 == EndNotePositionAtMarker) {
        view.enable_zone ("userstring2_dumpendnotes");
        userstring2_question = translate("Please enter a marker at which the endnotes should be dumped");
        userstring2_info = translate("The marker is to be given without the backslash, e.g. \"zendnotes\".");
      }
      break;
  }
  if (request->query.count ("userstring2")) {
    Dialog_Entry dialog_entry = Dialog_Entry ("view", userstring2_question, userstring2, "userstring2", userstring2_info);
    dialog_entry.add_query ("sheet", sheet);
    dialog_entry.add_query ("style", style);
    page += dialog_entry.run ();
    return page;
  }
  if (request->post.count("userstring2")) {
    userstring2 = request->post["entry"];
    if (write) database_styles.updateUserstring2 (sheet, style, userstring2);
  }
  if (userstring2 == "") userstring2 = "--";
  view.set_variable ("userstring2", filter_string_sanitize_html (userstring2));
  
  // Recreate stylesheets after editing a style.
  if ((request->query.size () != 2) || (request->post.size () != 0)) {
    styles_sheets_create_all ();
  }

  
  // Userstring3 not yet used.
  
  
  page += view.render ("styles", "view");
  
  page += Assets_Page::footer ();
  
  return page;
}
Пример #7
0
//--------------------------------------------------------------------
// EXTERNAL FUNCTIONS
//--------------------------------------------------------------------
int8_t execute(dvm_state_t* dvm_st, DvmState *eventState)
{
    DVMBasiclib_state_t *s = (&dvm_st->basiclib_st);
    DvmContext *context = &(eventState->context);

    while ((context->state == DVM_STATE_RUN) && (context->num_executed < DVM_CPU_SLICE)) {
        DvmOpcode instr = getOpcode(dvm_st, context->which, context->pc);
        DEBUG("-----------------------------------------------\n");
        DEBUG("[BASIC_LIB] execute: (%d) PC: %d. INSTR: %d\n",context->which, context->pc, instr);
        if(instr & LIB_ID_BIT)
        {   //Extension Library opcode encountered
            return SOS_OK;
        }
        context->num_executed++;
        switch(instr)
        {
        case OP_START:
        {
            __asm __volatile("__sleep_measure_start:");
            context->pc += 1;
            break;
        }
        case OP_STOP:
        {
            context->pc += 1;
            break;
        }
        case OP_HALT:
        {
            DEBUG("<<<<<<<<<<<=====================>>>>>>>>>>>\n");
            DEBUG("[BASIC_LIB] execute: (%d): HALT executed.\n", (int)context->which);
            haltContext(dvm_st, context);
            context->state = DVM_STATE_HALT;
            context->pc = 0;
            break;
        }
        case OP_LED:
        {
            DvmStackVariable* arg = popOperand( eventState);
            led_op(arg->value.var);
            context->pc += 1;
            break;
        }

        case OP_GETVAR + 0:
        case OP_GETVAR + 1:
        case OP_GETVAR + 2:
        case OP_GETVAR + 3:
        case OP_GETVAR + 4:
        case OP_GETVAR + 5:
        case OP_GETVAR + 6:
        case OP_GETVAR + 7:
        {
            uint8_t arg = instr - OP_GETVAR;
            DEBUG("[BASIC_LIB] execute: OPGETVAR (%d):: Pushing value %d.\n", (int)arg,(int)s->shared_vars[arg].value.var);
            pushOperand( eventState, &s->shared_vars[arg]);
            context->pc += 1;
            break;
        }
        case OP_SETVAR + 0:
        case OP_SETVAR + 1:
        case OP_SETVAR + 2:
        case OP_SETVAR + 3:
        case OP_SETVAR + 4:
        case OP_SETVAR + 5:
        case OP_SETVAR + 6:
        case OP_SETVAR + 7:
        {
            uint8_t arg = instr - OP_SETVAR;
            DvmStackVariable* var = popOperand( eventState);
            DEBUG("[BASIC_LIB] execute: OPSETVAR (%d):: Setting value to %d.\n",(int)arg,(int)var->value.var);
            s->shared_vars[arg] = *var;
            context->pc += 1;
            break;
        }
        case OP_GETVARF + 0:
        case OP_GETVARF + 1:
        case OP_GETVARF + 2:
        case OP_GETVARF + 3:
        case OP_GETVARF + 4:
        case OP_GETVARF + 5:
        case OP_GETVARF + 6:
        case OP_GETVARF + 7:
        {   // Use for type casting an integer shared var to float
            uint8_t arg = instr - OP_GETVARF;
            int32_t res = 0;
            uint16_t res_part = 0;
            DEBUG("[BASIC_LIB] execute: OPGETVARF (%d):: Pushing value %d.\n", (int)arg,(int)s->shared_vars[arg].value.var);
            res = (int32_t)(s->shared_vars[arg].value.var * FLOAT_PRECISION);
            res_part = res & 0xFFFF;
            pushValue( eventState, res_part, DVM_TYPE_FLOAT_DEC);
            res_part = res >> 16;
            pushValue( eventState, res_part, DVM_TYPE_FLOAT);
            context->pc += 1;
            break;
        }
        case OP_SETVARF + 0:
        case OP_SETVARF + 1:
        case OP_SETVARF + 2:
        case OP_SETVARF + 3:
        case OP_SETVARF + 4:
        case OP_SETVARF + 5:
        case OP_SETVARF + 6:
        {   // Type-casting an integer to float and saving it in shared var
            uint8_t arg = instr - OP_SETVARF;
            DvmStackVariable* var = popOperand( eventState);
            int32_t res = 0;
            uint16_t res_part;
            DEBUG("[BASIC_LIB] execute: OPSETVARF (%d):: Setting value to %d.\n",(int)arg,(int)var->value.var);
            res = (int32_t)(var->value.var * FLOAT_PRECISION);
            res_part = res & 0xFFFF;
            s->shared_vars[arg+1].type = DVM_TYPE_FLOAT_DEC;
            s->shared_vars[arg+1].value.var = res_part;
            res_part = res >> 16;
            s->shared_vars[arg].type = DVM_TYPE_FLOAT;
            s->shared_vars[arg].value.var = res_part;
            context->pc += 1;
            break;
        }
        case OP_SETTIMER + 0:
        case OP_SETTIMER + 1:
        case OP_SETTIMER + 2:
        case OP_SETTIMER + 3:
        case OP_SETTIMER + 4:
        case OP_SETTIMER + 5:
        case OP_SETTIMER + 6:
        case OP_SETTIMER + 7:
        {
            uint32_t msec;
            uint8_t timerID = instr - OP_SETTIMER;
            DvmStackVariable* arg = popOperand( eventState);
            DEBUG("[BASIC_LIB] execute: Setting Timer %d period to %d.\n", timerID, arg->value.var);
            //msec = 102 * arg->value.var + (4 * arg->value.var) / 10;
            // Set the timer timeout argument in seconds
            msec = arg->value.var * 4;// * 1000;
            DEBUG("[BASIC_LIB] execute: <<<<< WARNING - Timer %d not being stopped >>>>\n", timerID);
            //	  sys_timer_stop(timerID);
            if (msec > 0) {
                // Ram - Where is the init ??
                sys_timer_start(timerID, msec, TIMER_REPEAT);
                DEBUG("[BASIC_LIB] execute: Timer ID: %d started. Period: %d msec.\n", timerID, msec);
            }
            context->pc += 1;
            break;
        }
        case OP_RAND:
        {
            DvmStackVariable* arg = popOperand( eventState);
            uint16_t rnd;
            rnd = sys_rand() % arg->value.var;
            pushValue( eventState, rnd, DVM_TYPE_INTEGER);
            context->pc += 1;
            break;
        }
        /*
          case OP_JMP: case OP_JNZ: case OP_JZ: case OP_JG:
          case OP_JGE: case OP_JL: case OP_JLE: case OP_JE:
          case OP_JNE:
          case OP_ADD: case OP_SUB: case OP_DIV: case OP_MUL:
          case OP_ABS: case OP_MOD: case OP_INCR: case OP_DECR:
          {
          mathlib_executeDL(s->mathlib_execute, eventState, instr);
          break;
          }
        */
        // Math Lib
        case OP_ADD:
        case OP_SUB:
        case OP_DIV:
        case OP_MUL:
        {
            DvmStackVariable* arg1 = popOperand( eventState);
            DvmStackVariable* arg2 = popOperand( eventState);
            DvmStackVariable* arg3 = NULL, *arg4 = NULL;
            int32_t fl_arg1, fl_arg2;
            int32_t res = 0;
            uint16_t res_part;
            int16_t int_res = 0;

            if (arg1->type == DVM_TYPE_FLOAT) {
                fl_arg1 = convert_to_float(arg1, arg2);
                arg3 = popOperand( eventState);
                if (arg3->type == DVM_TYPE_FLOAT) {
                    // FLOAT <op> FLOAT
                    arg4 = popOperand( eventState);
                    fl_arg2 = convert_to_float(arg3, arg4);
                    if(instr == OP_ADD) {
                        res = (int32_t)(fl_arg1 + fl_arg2);
                        DEBUG("[BASIC_LIB] execute: FLOAT ADD FLOAT %d\n", res);
                    } else if(instr == OP_SUB) {
                        res = (int32_t)(fl_arg1 - fl_arg2);
                        DEBUG("[BASIC_LIB] execute: FLOAT SUB FLOAT %d\n", res);
                    } else if(instr == OP_DIV) {
                        res = (int32_t)((fl_arg1 * FLOAT_PRECISION) / fl_arg2);
                        DEBUG("[BASIC_LIB] execute: FLOAT DIV FLOAT: %d\n", res);
                    } else if(instr == OP_MUL) {
                        res = (int32_t)((fl_arg1 * fl_arg2) / FLOAT_PRECISION);
                        DEBUG("[BASIC_LIB] execute: FLOAT MULT FLOAT %d\n", res);
                    }
                } else {
                    // FLOAT <OP> INTEGER
                    if(instr == OP_ADD) {
                        res = (int32_t)(fl_arg1 + (arg3->value.var * FLOAT_PRECISION));
                        DEBUG("[BASIC_LIB] execute: FLOAT ADD INT: %d\n", res);
                    } else if(instr == OP_SUB) {
                        res = (int32_t)(fl_arg1 - (arg3->value.var * FLOAT_PRECISION));
                        DEBUG("[BASIC_LIB] execute: FLOAT SUB INT: %d\n", res);
                    } else if(instr == OP_DIV) {
                        res = (int32_t)(fl_arg1 / arg3->value.var);
                        DEBUG("[BASIC_LIB] execute: FLOAT DIV INT: %d\n", res);
                        sys_led(LED_RED_TOGGLE);
#ifdef OUTLIER_SCRIPT_DBG
                        int32_t* post_avg;
                        post_avg = (int32_t*)sys_malloc(sizeof(int32_t));
                        *post_avg = res;
                        sys_post_uart(OUTLIER_DETECTION_PID, MSG_AVERAGE, sizeof(int32_t),
                                      post_avg, SOS_MSG_RELEASE, UART_ADDRESS);
#endif
                    } else if(instr == OP_MUL) {
                        res = (int32_t)(fl_arg1 * arg3->value.var);
                        DEBUG("[BASIC_LIB] execute: FLOAT MULT INT %d\n", res);
                    }
                }
                res_part = res & 0xFFFF;
                pushValue( eventState, res_part, DVM_TYPE_FLOAT_DEC);
                res_part = res >> 16;
                pushValue( eventState, res_part, DVM_TYPE_FLOAT);
                context->pc += 1;
                break;
            } else if (arg2->type == DVM_TYPE_FLOAT) {
                arg3 = popOperand( eventState);
                fl_arg2 = convert_to_float(arg2, arg3);
                if(instr == OP_ADD) {
                    res = (int32_t)((arg1->value.var * FLOAT_PRECISION) + fl_arg2) ;
                    DEBUG("[BASIC_LIB] execute: INT ADD FLOAT: %d\n", res);
                } else if(instr == OP_SUB) {
                    res = (int32_t)((arg1->value.var * FLOAT_PRECISION) - fl_arg2);
                    DEBUG("[BASIC_LIB] execute: INT SUB FLOAT: %d\n", res);
                } else if(instr == OP_DIV) {
                    res = (int32_t)((arg1->value.var * FLOAT_PRECISION) / fl_arg2);
                    DEBUG("[BASIC_LIB] execute: INT DIV FLOAT: %d\n", res);
                } else if(instr == OP_MUL) {
                    res = (int32_t)((arg1->value.var * FLOAT_PRECISION) * fl_arg2);
                    DEBUG("[BASIC_LIB] execute: INT MULT FLOAT: %d\n", res);
                }
                res_part = res & 0xFFFF;
                pushValue( eventState, res_part, DVM_TYPE_FLOAT_DEC);
                res_part = res >> 16;
                pushValue( eventState, res_part, DVM_TYPE_FLOAT);
                context->pc += 1;
                break;
            }
            if(instr == OP_ADD) {
                int_res = arg1->value.var + arg2->value.var;
                DEBUG("[BASIC_LIB] execute: INT ADD INT: %d\n", int_res);
            } else if(instr == OP_SUB) {
                int_res = arg1->value.var - arg2->value.var;
                DEBUG("[BASIC_LIB] execute: INT SUB INT: %d\n", int_res);
            } else if(instr == OP_DIV) {
                int_res = (int16_t)(arg1->value.var / arg2->value.var);
                DEBUG("[BASIC_LIB] execute: INT DIV INT: %d\n", int_res);
            } else if(instr == OP_MUL) {
                int_res = (int16_t)(arg1->value.var * arg2->value.var);
                DEBUG("[BASIC_LIB] execute: INT MULT INT: %d\n", int_res);
            }
            pushValue( eventState, int_res, DVM_TYPE_INTEGER);
            context->pc += 1;
            break;
        }
Пример #8
0
const void *
ImageOutput::to_native_rectangle (int xbegin, int xend, int ybegin, int yend,
                                  int zbegin, int zend,
                                  TypeDesc format, const void *data,
                                  stride_t xstride, stride_t ystride, stride_t zstride,
                                  std::vector<unsigned char> &scratch)
{
    // native_pixel_bytes is the size of a pixel in the FILE, including
    // the per-channel format, if specified when the file was opened.
    stride_t native_pixel_bytes = (stride_t) m_spec.pixel_bytes (true);
    // perchanfile is true if the file has different per-channel formats
    bool perchanfile = m_spec.channelformats.size() && supports("channelformats");
    // It's an error to pass per-channel data formats to a writer that
    // doesn't support it.
    if (m_spec.channelformats.size() && !perchanfile)
        return NULL;
    // native_data is true if the user is passing data in the native format
    bool native_data = (format == TypeDesc::UNKNOWN ||
                        (format == m_spec.format && !perchanfile));
    // If the user is passing native data and they've left xstride set
    // to Auto, then we know it's the native pixel size.
    if (native_data && xstride == AutoStride)
        xstride = native_pixel_bytes;
    // Fill in the rest of the strides that haven't been set.
    m_spec.auto_stride (xstride, ystride, zstride, format,
                        m_spec.nchannels, xend-xbegin, yend-ybegin);

    // Compute width and height from the rectangle extents
    int width = xend - xbegin;
    int height = yend - ybegin;
    int depth = zend - zbegin;

    // Do the strides indicate that the data area is contiguous?
    bool contiguous = (xstride == (stride_t)m_spec.pixel_bytes(native_data));
    contiguous &= ((ystride == xstride*width || height == 1) &&
                   (zstride == ystride*height || depth == 1));

    if (native_data && contiguous) {
        // Data are already in the native format and contiguous
        // just return a ptr to the original data.
        return data;
    }

    imagesize_t rectangle_pixels = width * height * depth;
    imagesize_t rectangle_values = rectangle_pixels * m_spec.nchannels;
    imagesize_t rectangle_bytes = rectangle_pixels * native_pixel_bytes;

    // Cases to handle:
    // 1. File has per-channel data, user passes native data -- this has
    //    already returned above, since the data didn't need munging.
    // 2. File has per-channel data, user passes some other data type
    // 3. File has uniform data, user passes some other data type
    // 4. File has uniform data, user passes the right data -- note that
    //    this case already returned if the user data was contiguous

    // Handle the per-channel format case (#2) where the user is passing
    // a non-native buffer.
    if (perchanfile) {
        if (native_data) {
            ASSERT (contiguous && "Per-channel native output requires contiguous strides");
        }
        ASSERT (format != TypeDesc::UNKNOWN);
        ASSERT (m_spec.channelformats.size() == (size_t)m_spec.nchannels);
        scratch.resize (rectangle_bytes);
        size_t offset = 0;
        for (int c = 0;  c < m_spec.nchannels;  ++c) {
            TypeDesc chanformat = m_spec.channelformats[c];
            convert_image (1 /* channels */, width, height, depth,
                           (char *)data + c*format.size(), format,
                           xstride, ystride, zstride, 
                           &scratch[offset], chanformat,
                           native_pixel_bytes, AutoStride, AutoStride, NULL,
                           c == m_spec.alpha_channel ? 0 : -1,
                           c == m_spec.z_channel ? 0 : -1);
            offset += chanformat.size ();
        }
        return &scratch[0];
    }

    // The remaining code is where all channels in the file have the
    // same data type, which may or may not be what the user passed in
    // (cases #3 and #4 above).
    imagesize_t contiguoussize = contiguous ? 0 : rectangle_values * native_pixel_bytes;
    contiguoussize = (contiguoussize+3) & (~3); // Round up to 4-byte boundary
    DASSERT ((contiguoussize & 3) == 0);
    imagesize_t floatsize = rectangle_values * sizeof(float);
    scratch.resize (contiguoussize + floatsize + rectangle_bytes);

    // Force contiguity if not already present
    if (! contiguous) {
        data = contiguize (data, m_spec.nchannels, xstride, ystride, zstride,
                           (void *)&scratch[0], width, height, depth, format);
    }

    // Rather than implement the entire cross-product of possible
    // conversions, use float as an intermediate format, which generally
    // will always preserve enough precision.
    const float *buf;
    if (format == TypeDesc::FLOAT) {
        // Already in float format -- leave it as-is.
        buf = (float *)data;
    } else {
        // Convert to from 'format' to float.
        buf = convert_to_float (data, (float *)&scratch[contiguoussize],
                                rectangle_values, format);
    }
    
    // Convert from float to native format.
    return convert_from_float (buf, &scratch[contiguoussize+floatsize], 
                       rectangle_values, m_spec.quant_black, m_spec.quant_white,
                       m_spec.quant_min, m_spec.quant_max,
                       m_spec.format);
}
Пример #9
0
static int read_tng_timestep(void *v, int natoms, molfile_timestep_t *ts)
{
    /* The pointers that will be allocated by the TNG must be NULL before allocation. */
    void *values = 0;
    char datatype;
    float box_shape[9], vmd_box[6];
    float fact = 1;
    int64_t frame, n, temp, temp2;
    double temp_time;
    tng_function_status stat;
    tngdata *tng = (tngdata *)v;

    if(!ts)
    {
        return MOLFILE_ERROR;
    }

//     fprintf(stderr, "Reading framestep from TNG\n");

    stat = tng_util_particle_data_next_frame_read(tng->tng_traj, TNG_TRAJ_POSITIONS, &values,
                                                  &datatype, &frame, &temp_time);
    ts->physical_time = temp_time / PICO;
    if(stat != TNG_SUCCESS)
    {
        if(values)
        {
            free(values);
        }
        return MOLFILE_ERROR;
    }
//     fprintf(stderr, "tngplugin) Timestep %d (%f), frame %d (%d), %d atoms\n",
//             tng->step, ts->physical_time, (int)frame, (int)tng->n_frames, natoms);

    /* TODO: Here it would be possible to add reading of the energy and pressure
     * measurements supported in VMD if they are present in the TNG file */
    tng_num_particles_get(tng->tng_traj, &n);
    if(n != natoms)
    {
        fprintf(stderr, "tngplugin) Timestep in file contains wrong number of atoms\n");
        fprintf(stderr, "tngplugin) Found %d, expected %d\n", (int)n, natoms);
        return MOLFILE_ERROR;
    }

    if(tng->coord_exponential != -10)
    {
        fact = pow(10.0, tng->coord_exponential + 10);
    }

    convert_to_float(values, ts->coords, fact, natoms, 3, datatype);

    if(ts->velocities)
    {
//         fprintf(stderr, "tngplugin) Reading velocities\n");
        stat = tng_particle_data_vector_interval_get(tng->tng_traj, TNG_TRAJ_VELOCITIES, frame,
                                                     frame, TNG_USE_HASH, &values,
                                                     &n, &temp, &temp2, &datatype);
        if(stat == TNG_CRITICAL)
        {
            if(values)
            {
                free(values);
            }
            return MOLFILE_ERROR;
        }
        if(stat == TNG_SUCCESS)
        {
            convert_to_float(values, ts->velocities, fact, natoms, 3, datatype);
        }
    }

    stat = tng_data_vector_interval_get(tng->tng_traj, TNG_TRAJ_BOX_SHAPE,
                                        frame, frame, TNG_USE_HASH, &values,
                                        &temp, &temp2, &datatype);
    if(stat == TNG_CRITICAL)
    {
        if(values)
        {
            free(values);
        }
        return MOLFILE_ERROR;
    }
    if(stat == TNG_SUCCESS)
    {
        convert_to_float(values, box_shape, fact, 1, 9, datatype);

        convert_tng_box_shape_to_vmd(box_shape, vmd_box);
        if(ts)
        {
            ts->A = vmd_box[0];
            ts->B = vmd_box[1];
            ts->C = vmd_box[2];
            ts->alpha = vmd_box[3];
            ts->beta = vmd_box[4];
            ts->gamma = vmd_box[5];
        }
    }

    ++tng->step;
    if(values)
    {
        free(values);
    }

    return MOLFILE_SUCCESS;
}
Пример #10
0
void 
uncouple_channel(stream_coeffs_t *coeffs,audblk_t *audblk, uint_32 ch, 
	bsi_t *pbsi )
{
	uint_32 bnd = 0;
	uint_32 i;
	float cpl_coord;
	uint_32 cpl_exp_tmp;
	uint_32 cpl_mant_tmp;

	for(i=audblk->cplstrtmant;i<audblk->cplendmant;i+=12)
	{
		if(!audblk->cplbndstrc[bnd])
		{
			cpl_exp_tmp = audblk->cplcoexp[ch][bnd] + 3 * audblk->mstrcplco[ch];
			if(audblk->cplcoexp[ch][bnd] == 15)
				cpl_mant_tmp = (audblk->cplcomant[ch][bnd]) << 12;
			else
				cpl_mant_tmp = ((0x10) | audblk->cplcomant[ch][bnd]) << 11;
			
			convert_to_float(cpl_exp_tmp,cpl_mant_tmp,(uint_32*)&cpl_coord);
		}


		/* If in 2.0 (stereo) mode, check phase-invert flags */
		if ( pbsi->acmod == 0x02 && ch == 1 && audblk->phsflginu && 
			audblk->phsflg[ bnd ] )
		{	/* phsflginu?  phsflg[bnd] ? is this *RIGHT* channel? */
			/* invert phase */
			coeffs->fbw[ch][i]   = - cpl_coord * cpl_tmp[i];
			coeffs->fbw[ch][i+1] = - cpl_coord * cpl_tmp[i+1];
			coeffs->fbw[ch][i+2] = - cpl_coord * cpl_tmp[i+2];
			coeffs->fbw[ch][i+3] = - cpl_coord * cpl_tmp[i+3];
			coeffs->fbw[ch][i+4] = - cpl_coord * cpl_tmp[i+4];
			coeffs->fbw[ch][i+5] = - cpl_coord * cpl_tmp[i+5];
			coeffs->fbw[ch][i+6] = - cpl_coord * cpl_tmp[i+6];
			coeffs->fbw[ch][i+7] = - cpl_coord * cpl_tmp[i+7];
			coeffs->fbw[ch][i+8] = - cpl_coord * cpl_tmp[i+8];
			coeffs->fbw[ch][i+9] = - cpl_coord * cpl_tmp[i+9];
			coeffs->fbw[ch][i+10]= - cpl_coord * cpl_tmp[i+10];
			coeffs->fbw[ch][i+11]= - cpl_coord * cpl_tmp[i+11];
		}
		else
		{	/* normal phase, phaseinvert not in use */
			coeffs->fbw[ch][i]   = cpl_coord * cpl_tmp[i];
			coeffs->fbw[ch][i+1] = cpl_coord * cpl_tmp[i+1];
			coeffs->fbw[ch][i+2] = cpl_coord * cpl_tmp[i+2];
			coeffs->fbw[ch][i+3] = cpl_coord * cpl_tmp[i+3];
			coeffs->fbw[ch][i+4] = cpl_coord * cpl_tmp[i+4];
			coeffs->fbw[ch][i+5] = cpl_coord * cpl_tmp[i+5];
			coeffs->fbw[ch][i+6] = cpl_coord * cpl_tmp[i+6];
			coeffs->fbw[ch][i+7] = cpl_coord * cpl_tmp[i+7];
			coeffs->fbw[ch][i+8] = cpl_coord * cpl_tmp[i+8];
			coeffs->fbw[ch][i+9] = cpl_coord * cpl_tmp[i+9];
			coeffs->fbw[ch][i+10]= cpl_coord * cpl_tmp[i+10];
			coeffs->fbw[ch][i+11]= cpl_coord * cpl_tmp[i+11];
		}


		bnd++;
	}
}
Пример #11
0
const void *
ImageOutput::to_native_rectangle (int xmin, int xmax, int ymin, int ymax,
                                  int zmin, int zmax, 
                                  TypeDesc format, const void *data,
                                  stride_t xstride, stride_t ystride, stride_t zstride,
                                  std::vector<unsigned char> &scratch)
{
    stride_t native_pixel_bytes = (stride_t) m_spec.pixel_bytes (true);
    if (format == TypeDesc::UNKNOWN && xstride == AutoStride)
        xstride = native_pixel_bytes;
    m_spec.auto_stride (xstride, ystride, zstride, format,
                        m_spec.nchannels, xmax-xmin+1, ymax-ymin+1);

    // Compute width and height from the rectangle extents
    int width = xmax - xmin + 1;
    int height = ymax - ymin + 1;
    int depth = zmax - zmin + 1;

    // Do the strides indicate that the data are already contiguous?
    bool contiguous = (xstride == native_pixel_bytes &&
                       (ystride == xstride*width || height == 1) &&
                       (zstride == ystride*height || depth == 1));
    // Does the user already have the data in the right format?
    bool rightformat = (format == TypeDesc::UNKNOWN) ||
        (format == m_spec.format && m_spec.channelformats.empty());
    if (rightformat && contiguous) {
        // Data are already in the native format and contiguous
        // just return a ptr to the original data.
        return data;
    }

    imagesize_t rectangle_pixels = width * height * depth;
    imagesize_t rectangle_values = rectangle_pixels * m_spec.nchannels;
    imagesize_t rectangle_bytes = rectangle_pixels * native_pixel_bytes;

    // Handle the per-channel format case
    if (m_spec.channelformats.size() && supports("channelformats")) {
        ASSERT (contiguous && "Per-channel output requires contiguous strides");
        ASSERT (format != TypeDesc::UNKNOWN);
        scratch.resize (rectangle_bytes);
        size_t offset = 0;
        for (int c = 0;  c < (int)m_spec.channelformats.size();  ++c) {
            TypeDesc chanformat = m_spec.channelformats[c];
            convert_image (1 /* channels */, width, height, depth,
                           (char *)data + c*m_spec.format.size(), format,
                           xstride, ystride, zstride, 
                           &scratch[offset], chanformat,
                           native_pixel_bytes, AutoStride, AutoStride, NULL,
                           c == m_spec.alpha_channel ? 0 : -1,
                           c == m_spec.z_channel ? 0 : -1);
            offset = chanformat.size ();
        }
        return &scratch[0];
    }

    imagesize_t contiguoussize = contiguous ? 0 : rectangle_values * native_pixel_bytes;
    contiguoussize = (contiguoussize+3) & (~3); // Round up to 4-byte boundary
    DASSERT ((contiguoussize & 3) == 0);
    imagesize_t floatsize = rectangle_values * sizeof(float);
    scratch.resize (contiguoussize + floatsize + rectangle_bytes);

    // Force contiguity if not already present
    if (! contiguous) {
        data = contiguize (data, m_spec.nchannels, xstride, ystride, zstride,
                           (void *)&scratch[0], width, height, depth, format);
    }

    // Rather than implement the entire cross-product of possible
    // conversions, use float as an intermediate format, which generally
    // will always preserve enough precision.
    const float *buf;
    if (format == TypeDesc::FLOAT) {
        // Already in float format -- leave it as-is.
        buf = (float *)data;
    } else {
        // Convert to from 'format' to float.
        buf = convert_to_float (data, (float *)&scratch[contiguoussize],
                                rectangle_values, format);
    }
    
    // Convert from float to native format.
    return convert_from_float (buf, &scratch[contiguoussize+floatsize], 
                       rectangle_values, m_spec.quant_black, m_spec.quant_white,
                       m_spec.quant_min, m_spec.quant_max,
                       m_spec.format);
}