mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-09-25 07:05:48 +00:00
Add functionality to return raw thumbnail bytes, not encoded
* This is useful if you want to retrieve the thumbnail for in-memory processing instead of writing it to disk immediately.
This commit is contained in:
@@ -1180,3 +1180,21 @@ pixel.
|
||||
};
|
||||
|
||||
DECLARE_REFLECTION_STRUCT(PixelModification);
|
||||
|
||||
DOCUMENT("Contains the bytes and metadata describing a thumbnail.");
|
||||
struct Thumbnail
|
||||
{
|
||||
DOCUMENT("The :class:`FileType` of the data in the thumbnail.");
|
||||
FileType type;
|
||||
|
||||
DOCUMENT("The ``bytes`` byte array containing the raw data.");
|
||||
bytebuf bytes;
|
||||
|
||||
DOCUMENT("The width of the thumbnail image.");
|
||||
uint32_t width;
|
||||
|
||||
DOCUMENT("The height of the thumbnail image.");
|
||||
uint32_t height;
|
||||
};
|
||||
|
||||
DECLARE_REFLECTION_STRUCT(Thumbnail);
|
||||
|
||||
@@ -1515,9 +1515,9 @@ The data is copied internally so it can be destroyed after calling this function
|
||||
:param int maxsize: The largest width or height allowed. If the thumbnail is larger, it's resized.
|
||||
:return: The raw contents of the thumbnail, converted to the desired type at the desired max
|
||||
resolution.
|
||||
:rtype: ``bytes``.
|
||||
:rtype: Thumbnail.
|
||||
)");
|
||||
virtual bytebuf GetThumbnail(FileType type, uint32_t maxsize) = 0;
|
||||
virtual Thumbnail GetThumbnail(FileType type, uint32_t maxsize) = 0;
|
||||
|
||||
protected:
|
||||
ICaptureFile() = default;
|
||||
|
||||
@@ -947,6 +947,10 @@ DOCUMENT(R"(The format of an image file
|
||||
.. data:: EXR
|
||||
|
||||
An EXR file
|
||||
|
||||
.. data:: RAW
|
||||
|
||||
Raw data, just the bytes of the image tightly packed with no metadata or compression/encoding
|
||||
)");
|
||||
enum class FileType : uint32_t
|
||||
{
|
||||
@@ -958,6 +962,7 @@ enum class FileType : uint32_t
|
||||
TGA,
|
||||
HDR,
|
||||
EXR,
|
||||
Raw,
|
||||
Count,
|
||||
};
|
||||
|
||||
|
||||
@@ -153,7 +153,7 @@ void RenderDoc::TargetControlClientThread(Network::Socket *client)
|
||||
ICaptureFile *file = RENDERDOC_OpenCaptureFile();
|
||||
if(file->OpenFile(captures.back().path.c_str(), "rdc") == ReplayStatus::Succeeded)
|
||||
{
|
||||
buf = file->GetThumbnail(FileType::JPG, 0);
|
||||
buf = file->GetThumbnail(FileType::JPG, 0).bytes;
|
||||
}
|
||||
file->Shutdown();
|
||||
|
||||
|
||||
@@ -161,7 +161,7 @@ public:
|
||||
m_StructuredData.buffers.push_back(new bytebuf(*buf));
|
||||
}
|
||||
|
||||
bytebuf GetThumbnail(FileType type, uint32_t maxsize);
|
||||
Thumbnail GetThumbnail(FileType type, uint32_t maxsize);
|
||||
|
||||
// ICaptureAccess
|
||||
|
||||
@@ -481,12 +481,13 @@ ReplayStatus CaptureFile::Convert(const char *filename, const char *filetype, fl
|
||||
return ReplayStatus::Succeeded;
|
||||
}
|
||||
|
||||
bytebuf CaptureFile::GetThumbnail(FileType type, uint32_t maxsize)
|
||||
Thumbnail CaptureFile::GetThumbnail(FileType type, uint32_t maxsize)
|
||||
{
|
||||
bytebuf buf;
|
||||
Thumbnail ret;
|
||||
ret.type = type;
|
||||
|
||||
if(m_RDC == NULL)
|
||||
return buf;
|
||||
return ret;
|
||||
|
||||
const RDCThumb &thumb = m_RDC->GetThumbnail();
|
||||
|
||||
@@ -495,7 +496,9 @@ bytebuf CaptureFile::GetThumbnail(FileType type, uint32_t maxsize)
|
||||
uint32_t thumbwidth = thumb.width, thumbheight = thumb.height;
|
||||
|
||||
if(jpgbuf == NULL)
|
||||
return buf;
|
||||
return ret;
|
||||
|
||||
bytebuf buf;
|
||||
|
||||
// if the desired output is jpg and either there's no max size or it's already satisfied,
|
||||
// return the data directly
|
||||
@@ -546,6 +549,11 @@ bytebuf CaptureFile::GetThumbnail(FileType type, uint32_t maxsize)
|
||||
|
||||
switch(type)
|
||||
{
|
||||
case FileType::Raw:
|
||||
{
|
||||
encodedBytes.assign(thumbpixels, thumbpixels + (thumbwidth * thumbheight * 3));
|
||||
break;
|
||||
}
|
||||
case FileType::JPG:
|
||||
{
|
||||
int len = thumbwidth * thumbheight * 3;
|
||||
@@ -579,7 +587,7 @@ bytebuf CaptureFile::GetThumbnail(FileType type, uint32_t maxsize)
|
||||
{
|
||||
RDCERR("Unsupported file type %d in thumbnail fetch", type);
|
||||
free(thumbpixels);
|
||||
return buf;
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -588,7 +596,11 @@ bytebuf CaptureFile::GetThumbnail(FileType type, uint32_t maxsize)
|
||||
free(thumbpixels);
|
||||
}
|
||||
|
||||
return buf;
|
||||
ret.bytes.swap(buf);
|
||||
ret.width = thumbwidth;
|
||||
ret.height = thumbheight;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int CaptureFile::FindSectionByName(const char *name)
|
||||
|
||||
@@ -296,7 +296,7 @@ struct ThumbCommand : public Command
|
||||
ReplayStatus st = file->OpenFile(filename.c_str(), "rdc");
|
||||
if(st == ReplayStatus::Succeeded)
|
||||
{
|
||||
buf = file->GetThumbnail(type, maxsize);
|
||||
buf = file->GetThumbnail(type, maxsize).bytes;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user