DECLSPEC pbitmap Resource::interpret_as() { if (_type != "RT_BITMAP") { return pbitmap(); } auto res = boost::make_shared<bitmap>(); unsigned int header_size = 14; res->Magic[0] = 'B'; res->Magic[1] = 'M'; res->Reserved1 = 0; res->Reserved2 = 0; res->data = *get_raw_data(); res->Size = res->data.size() + header_size; // Calculate the offset to the raw data. if (res->data.size() < 36) { // Not enough bytes to make a valid BMP return pbitmap(); } boost::uint32_t dib_header_size = 0; boost::uint32_t colors_used = 0; memcpy(&dib_header_size, &(res->data[0]), sizeof(boost::uint32_t)); // DIB header size is located at offset 0. memcpy(&colors_used, &(res->data[32]), sizeof(boost::uint32_t)); res->OffsetToData = header_size + dib_header_size + 4*colors_used; return res; }
int getValue(unsigned char* in, int side, double longitude, double latitude, double scale) { double x = side/2+scale*(side/2)*cos(latitude)*sin(longitude); double y = side/2-scale*(side/2)*sin(latitude); int row0 = (int)floor(y); double drow = y - row0; int column0 = (int)floor(x); double dcolumn = x - column0; double v00 = get_raw_data(in,side,column0,row0); double v10 = get_raw_data(in,side,column0+1,row0); double v01 = get_raw_data(in,side,column0,row0+1); double v11 = get_raw_data(in,side,column0+1,row0+1); double v0 = v00 * (1-dcolumn) + v10 * dcolumn; double v1 = v01 * (1-dcolumn) + v11 * dcolumn; return v0 * (1-drow) + v1 * drow; }
// (virtual) int PcmDecoder::decode( int dst_count, int16_t* dst_data) { if (dst_count <= 0) return 0; if (dst_data == NULL) return 0; if (offset_ >= dst_count_) return 0; int actual_count = 0; const uint8_t* src_samples = static_cast<const uint8_t*>(get_raw_data()); int64_t offset = offset_; int cached_index = -1; int16_t cached_sample = 0; for (int i = 0; i < dst_count && offset < dst_count_; ++i) { int src_index = static_cast<int>((offset * dst_ratio_) >> 16); if (src_index != cached_index) { cached_index = src_index; cached_sample = pcm8_to_pcm16(src_samples[src_index]); } dst_data[i] = cached_sample; ++offset; ++actual_count; } offset = offset_; for (int i = 0; i < actual_count; ++i) { if (!(i == 0 && offset == 0)) { int16_t prev_sample; if (i > 0) prev_sample = dst_data[i - 1]; else prev_sample = last_sample_; dst_data[i] = static_cast<int16_t>( (alpha_ * dst_data[i]) + (one_minus_alpha_ * prev_sample)); } ++offset; } offset_ = offset; last_sample_ = dst_data[actual_count - 1]; return actual_count; }
static ssize_t touchkey_back_raw_show(struct device *dev, struct device_attribute *attr, char *buf) { struct abov_tk_info *info = dev_get_drvdata(dev); get_raw_data(info); return sprintf(buf, "%d\n", info->back_raw); }
DECLSPEC pString Resource::interpret_as() { if (_type != "RT_MANIFEST") { PRINT_WARNING << "Resources of type " << _type << "cannot be interpreted as std::strings." << DEBUG_INFO << std::endl; return boost::make_shared<std::string>(); } shared_bytes manifest_bytes = get_raw_data(); return boost::make_shared<std::string>(manifest_bytes->begin(), manifest_bytes->end()); }
yara::const_matches Resource::detect_filetype() const { if (_yara->load_rules("yara_rules/magic.yara")) { shared_bytes bytes = get_raw_data(); return _yara->scan_bytes(*bytes); } else { return yara::matches(); } }
float myAhrs::get_data(Did id) { double sf; switch(id) { case ACCEL_X: case ACCEL_Y: case ACCEL_Z: sf = acc_scale_factor; break; case GYRO_X: case GYRO_Y: case GYRO_Z: sf = gyro_scale_factor; break; case MAG_X: case MAG_Y: case MAG_Z: sf = magnet_scale_factor; break; case ATTI_ROLL : case ATTI_PITCH: case ATTI_YAW : sf = attitude_scale_factor; break; case TEMP: sf = temp_scale_factor; break; default: return 0; } return (float)(sf * get_raw_data(id)); }
DECLSPEC shared_bytes Resource::interpret_as() { return get_raw_data(); }
static uint16_t get_co2(void) { return get_raw_data(CODE_CO2); }
static double get_temperature(void) { return decode_temperature(get_raw_data(CODE_TEMP)); }
int PcmDecoder::decode( const int dst_count, std::int16_t* const dst_data) { if (dst_count <= 0) { return 0; } if (!dst_data) { return 0; } if (offset_ >= dst_count_) { return 0; } auto actual_count = 0; const auto src_samples = static_cast<const std::uint8_t*>(get_raw_data()); auto offset = offset_; auto cached_index = -1; auto cached_sample = std::int16_t{}; for (int i = 0; i < dst_count && offset < dst_count_; ++i) { const auto src_index = static_cast<int>((offset * dst_ratio_) >> 16); if (src_index != cached_index) { cached_index = src_index; cached_sample = pcm8_to_pcm16(src_samples[src_index]); } dst_data[i] = cached_sample; ++offset; ++actual_count; } offset = offset_; for (int i = 0; i < actual_count; ++i) { if (!(i == 0 && offset == 0)) { auto prev_sample = std::int16_t{}; if (i > 0) { prev_sample = dst_data[i - 1]; } else { prev_sample = last_sample_; } dst_data[i] = static_cast<std::int16_t>((alpha_ * dst_data[i]) + (one_minus_alpha_ * prev_sample)); } ++offset; } offset_ = offset; last_sample_ = dst_data[actual_count - 1]; return actual_count; }