Exemplo n.º 1
0
	Size ImageFormat_JPEG::getSize(const IReader& reader) const
	{
		uint8 buf[24];

		if (!reader.lookahead(buf))
		{
			return{ 0, 0 };
		}

		const auto len = reader.size();

		//
		//	http://www.wischik.com/lu/programmer/get-image-size.html
		//
		if ((buf[0] == 0xFF && buf[1] == 0xD8 && buf[2] == 0xFF && buf[3] == 0xE0 && buf[6] == 'J' && buf[7] == 'F' && buf[8] == 'I' && buf[9] == 'F')
			|| (buf[0] == 0xFF && buf[1] == 0xD8 && buf[2] == 0xFF && buf[3] == 0xE1 && buf[6] == 'E' && buf[7] == 'x' && buf[8] == 'i' && buf[9] == 'f'))
		{
			int64 pos = 2;

			while (buf[2] == 0xFF)
			{
				if (buf[3] == 0xC0
					|| buf[3] == 0xC1
					|| buf[3] == 0xC2
					|| buf[3] == 0xC3
					|| buf[3] == 0xC5
					|| buf[3] == 0xC6
					|| buf[3] == 0xC7
					|| buf[3] == 0xC9
					|| buf[3] == 0xCA
					|| buf[3] == 0xCB
					|| buf[3] == 0xCD
					|| buf[3] == 0xCE
					|| buf[3] == 0xCF)
				{
					break;
				}

				pos += 2 + (buf[4] << 8) + buf[5];

				if (pos + 12 > len)
				{
					break;
				}

				reader.lookahead(buf + 2, pos, 12);
			}
		}

		// JPEG: (first two bytes of buf are first two bytes of the jpeg file; rest of buf is the DCT frame
		if (buf[0] == 0xFF && buf[1] == 0xD8 && buf[2] == 0xFF)
		{
			const int32 width = (buf[9] << 8) + buf[10];
			const int32 height = (buf[7] << 8) + buf[8];

			return{ width, height };
		}

		return{ 0, 0 };
	}
Exemplo n.º 2
0
			TemporaryFile(const IReader& reader)
				: m_path(FileSystem::UniqueFilePath())
			{
				WritableMemoryMapping file(m_path);

				const size_t size = static_cast<size_t>(reader.size());

				file.map(0, size);

				reader.lookahead(file.data(), size);

				file.unmap();
			}
Exemplo n.º 3
0
	Array<std::unique_ptr<IAudioFormat>>::const_iterator CAudioFormat::findFormat(const IReader& reader, const FilePath& pathHint) const
	{
		if (!reader.isOpened())
		{
			return m_audioFormats.end();
		}

		if (!reader.supportsLookahead())
		{
			return m_audioFormats.end();
		}

		uint8 header[16] = {};

		if (!reader.lookahead(header))
		{
			return m_audioFormats.end();
		}

		for (auto it = m_audioFormats.begin(); it != m_audioFormats.end(); ++it)
		{
			if ((*it)->isHeader(header))
			{
				return it;
			}
		}

		if (!pathHint.isEmpty())
		{
			const String extension = FileSystem::Extension(pathHint);

			for (auto it = m_audioFormats.begin(); it != m_audioFormats.end(); ++it)
			{
				if ((*it)->possibleExtexsions().includes(extension))
				{
					return it;
				}
			}
		}

		return m_audioFormats.end();
	}