示例#1
0
void PNGHandler::handle() {
	const ScrapeData::Data *data = getPayload();

	// std::cout << "Item[" << getId() << "] handler [png]" << std::endl;

	lodepng::State state;
	std::vector<unsigned char> image;
	std::vector<unsigned char> buffer(data->payload().begin(), data->payload().end());
	unsigned width, height;

	unsigned error = lodepng::decode(image, width, height, state, reinterpret_cast<const unsigned char *>(data->payload().c_str()), data->payload().size());
	if (error) {
		std::cout << "decoder error " << error << ": " << lodepng_error_text(error) << std::endl;
		return;
	}

	std::cout << "Filesize: " << buffer.size() << " (" << buffer.size() / 1024 << "K)" << std::endl;
	addMeta("image_width", reinterpret_cast<unsigned int>(width));
	std::cout << "Width: " << width << std::endl;
	addMeta("image_height", reinterpret_cast<unsigned int>(height));
	std::cout << "Height: " << height << std::endl;
	addMeta("image_pixels", reinterpret_cast<unsigned int>(width * height));
	std::cout << "Num pixels: " << width * height << std::endl;

	displayPNGInfo(state.info_png);
}
示例#2
0
CModInfo::CModInfo(std::string identifier,const JsonNode & local, const JsonNode & config):
	identifier(identifier),
	name(config["name"].String()),
	description(config["description"].String()),
	dependencies(config["depends"].convertTo<std::set<std::string> >()),
	conflicts(config["conflicts"].convertTo<std::set<std::string> >()),
	validation(PENDING),
	config(addMeta(config, identifier))
{
	loadLocalData(local);
}
示例#3
0
/// Attempts to parse a packet from the given Socket::Buffer.
/// Returns true if successful, removing the parsed part from the buffer.
/// Returns false if invalid or not enough data is in the buffer.
/// \arg buffer The Socket::Buffer to attempt to parse.
bool DTSC::Stream::parsePacket(Socket::Buffer & buffer) {
  uint32_t len;
  static bool syncing = false;
  if (buffer.available(8)) {
    std::string header_bytes = buffer.copy(8);
    if (memcmp(header_bytes.c_str(), DTSC::Magic_Header, 4) == 0) {
      len = ntohl(((uint32_t *)header_bytes.c_str())[1]);
      if (!buffer.available(len + 8)) {
        return false;
      }
      unsigned int i = 0;
      std::string wholepacket = buffer.remove(len + 8);
      JSON::Value meta;
      JSON::fromDTMI((unsigned char *)wholepacket.c_str() + 8, len, i, meta);
      addMeta(meta);
      //recursively calls itself until failure or data packet instead of header
      return parsePacket(buffer);
    }
    int version = 0;
    if (memcmp(header_bytes.c_str(), DTSC::Magic_Packet, 4) == 0) {
      version = 1;
    }
    if (memcmp(header_bytes.c_str(), DTSC::Magic_Packet2, 4) == 0) {
      version = 2;
    }
    if (version) {
      len = ntohl(((uint32_t *)header_bytes.c_str())[1]);
      if (!buffer.available(len + 8)) {
        return false;
      }
      JSON::Value newPack;
      unsigned int i = 0;
      std::string wholepacket = buffer.remove(len + 8);
      if (version == 1) {
        JSON::fromDTMI((unsigned char *)wholepacket.c_str() + 8, len, i, newPack);
      }
      if (version == 2) {
        JSON::fromDTMI2((unsigned char *)wholepacket.c_str() + 8, len, i, newPack);
      }
      addPacket(newPack);
      syncing = false;
      return true;
    }
#if DEBUG >= DLVL_WARN
    if (!syncing) {
      DEBUG_MSG(DLVL_WARN, "Invalid DTMI data detected - syncing");
      syncing = true;
    }
#endif
    buffer.get().clear();
  }
  return false;
}
示例#4
0
/* Display general info about the PNG */
void PNGHandler::displayPNGInfo(const LodePNGInfo& info) {
	const LodePNGColorMode& color = info.color;

	if (info.compression_method) {
		addMeta("image_compression_method", info.compression_method);
		std::cout << "Compression method: " << info.compression_method << std::endl;
	}

	if (info.filter_method) {
		addMeta("image_filter_method", info.filter_method);
		std::cout << "Filter method: " << info.filter_method << std::endl;
	}

	if (info.interlace_method) {
		addMeta("image_interlace_method", info.interlace_method);
		std::cout << "Interlace method: " << info.interlace_method << std::endl;
	}

	if (color.colortype) {
		addMeta("image_colortype", static_cast<unsigned int>(color.colortype));
		std::cout << "Color type: " << color.colortype << std::endl;
	}

	if (color.bitdepth) {
		addMeta("image_bitdepth", color.bitdepth);
		std::cout << "Bit depth: " << color.bitdepth << std::endl;
	}

	if (lodepng_get_bpp(&color)) {
		addMeta("image_bpp", lodepng_get_bpp(&color));
		std::cout << "Bits per pixel: " << lodepng_get_bpp(&color) << std::endl;
	}

	if (lodepng_get_channels(&color)) {
		addMeta("image_channels", lodepng_get_channels(&color));
		std::cout << "Channels per pixel: " << lodepng_get_channels(&color) << std::endl;
	}

	if (lodepng_is_greyscale_type(&color)) {
		addMeta("image_greyscale", lodepng_is_greyscale_type(&color));
		std::cout << "Is greyscale type: " << lodepng_is_greyscale_type(&color) << std::endl;
	}

	if (lodepng_can_have_alpha(&color)) {
		addMeta("image_allow_alpha", lodepng_can_have_alpha(&color));
		std::cout << "Can have alpha: " << lodepng_can_have_alpha(&color) << std::endl;
	}

	if (color.palettesize) {
		addMeta("image_palette_size", color.palettesize);
		std::cout << "Palette size: " << color.palettesize << std::endl;
	}

	if (color.key_defined) {
		addMeta("image_color_key", color.key_defined);
		addMeta("image_color_key_r", color.key_r);
		addMeta("image_color_key_g", color.key_g);
		addMeta("image_color_key_b", color.key_b);
		std::cout << "Has color key: " << color.key_defined << std::endl;
		std::cout << "Color key r: " << color.key_r << std::endl;
		std::cout << "Color key g: " << color.key_g << std::endl;
		std::cout << "Color key b: " << color.key_b << std::endl;
	}

	std::cout << "Texts: " << info.text_num << std::endl;
	for (size_t i = 0; i < info.text_num; i++) {
		addMeta("image_" + std::string(info.text_keys[i]), info.text_strings[i]);
		std::cout << "Text: " << info.text_keys[i] << ": " << info.text_strings[i] << std::endl << std::endl;
	}

	std::cout << "International texts: " << info.itext_num << std::endl;
	for (size_t i = 0; i < info.itext_num; i++) {
		addMeta("image_" + std::string(info.text_keys[i]), info.text_strings[i]);
		std::cout << "Text: "
		          << info.itext_keys[i] << ", "
		          << info.itext_langtags[i] << ", "
		          << info.itext_transkeys[i] << ": "
		          << info.itext_strings[i] << std::endl << std::endl;
	}

	std::cout << "Time defined: " << info.time_defined << std::endl;
	if (info.time_defined) {
		const LodePNGTime& time = info.time;
		std::stringstream ss;
		ss << time.year << "-" << time.month << "-" << time.day << " " << time.hour << ":" << time.minute << ":" << time.second;
		addMeta("image_timestamp", ss.str());
		std::cout << "year: " << time.year << std::endl;
		std::cout << "month: " << time.month << std::endl;
		std::cout << "day: " << time.day << std::endl;
		std::cout << "hour: " << time.hour << std::endl;
		std::cout << "minute: " << time.minute << std::endl;
		std::cout << "second: " << time.second << std::endl;
	}

	std::cout << "Physics defined: " << info.phys_defined << std::endl;
	if (info.phys_defined) {
		addMeta("image_physics_x", info.phys_x);
		addMeta("image_physics_y", info.phys_y);
		addMeta("image_physics_unit", info.phys_unit);
		std::cout << "physics X: " << info.phys_x << std::endl;
		std::cout << "physics Y: " << info.phys_y << std::endl;
		std::cout << "physics unit: " << info.phys_unit << std::endl;
	}
}