mirror of
https://github.com/switchbrew/libnx.git
synced 2025-06-21 12:32:40 +02:00
capssc: Add CaptureJpegScreenShot (#407)
This commit is contained in:
parent
20fd5bb9a2
commit
8cbac97466
@ -7,6 +7,9 @@
|
||||
#pragma once
|
||||
#include "../types.h"
|
||||
#include "../sf/service.h"
|
||||
#include "vi.h"
|
||||
|
||||
#define CAPSSC_JPEG_BUFFER_SIZE 0x80000
|
||||
|
||||
/// Initialize caps:sc. Only available on [2.0.0+].
|
||||
Result capsscInitialize(void);
|
||||
@ -23,12 +26,22 @@ Service* capsscGetServiceSession(void);
|
||||
* @note buffer_index and buffer_count correspond to buffers with size 0x384000(1280*720*4). These must not be negative.
|
||||
* @param buf Output buffer containing the RGBA8 image.
|
||||
* @param size Size of buf, should be 0x384000(1280*720*4) * buffer_count.
|
||||
* @param layer_stack Value 0 can be used for this.
|
||||
* @param layer_stack \ref ViLayerStack
|
||||
* @param width Image width, must be 1280.
|
||||
* @param height Image height, must be 720.
|
||||
* @param buffer_count Total number of output image buffers.
|
||||
* @param buffer_index Starting image buffer index. Must be < buffer_count.
|
||||
* @param timeout Timeout in nanoseconds. A default value of 100000000 can be used.
|
||||
*/
|
||||
Result capsscCaptureRawImageWithTimeout(void* buf, size_t size, u32 layer_stack, u64 width, u64 height, s64 buffer_count, s64 buffer_index, u64 timeout);
|
||||
Result capsscCaptureRawImageWithTimeout(void* buf, size_t size, ViLayerStack layer_stack, u64 width, u64 height, s64 buffer_count, s64 buffer_index, s64 timeout);
|
||||
|
||||
/**
|
||||
* @brief This takes a screenshot, with the screenshot being written as jpeg into the output buffer.
|
||||
* @note Only available on [9.0.0+]. Requires debug mode before [10.0.0].
|
||||
* @param out_jpeg_size Pointer to write the size of the captured jpeg to.
|
||||
* @param jpeg_buf Output buffer containing the JPEG image.
|
||||
* @param jpeg_buf_size Size of jpeg_buf, official software uses 0x80000.
|
||||
* @param layer_stack \ref ViLayerStack
|
||||
* @param timeout Timeout in nanoseconds.
|
||||
*/
|
||||
Result capsscCaptureJpegScreenShot(u64* out_jpeg_size, void* jpeg_buf, size_t jpeg_buf_size, ViLayerStack layer_stack, s64 timeout);
|
@ -56,6 +56,18 @@ typedef enum {
|
||||
ViPowerState_On_Deprecated = 1, ///< [1.0.0 - 2.3.0] Screen is on.
|
||||
} ViPowerState;
|
||||
|
||||
/// Used as argument to many capture functions.
|
||||
typedef enum {
|
||||
ViLayerStack_Default = 0, ///< Default layer stack, includes all layers.
|
||||
ViLayerStack_Lcd = 1, ///< Includes only layers for the LCD.
|
||||
ViLayerStack_Screenshot = 2, ///< Includes only layers for user screenshots.
|
||||
ViLayerStack_Recording = 3, ///< Includes only layers for recording videos.
|
||||
ViLayerStack_LastFrame = 4, ///< Includes only layers for the last applet-transition frame.
|
||||
ViLayerStack_Arbitrary = 5, ///< Captures some arbitrary layer. This is normally only for am.
|
||||
ViLayerStack_ApplicationForDebug = 6, ///< Captures layers for the current application. This is normally used by creport/debugging tools.
|
||||
ViLayerStack_Null = 10, ///< Layer stack for the empty display.
|
||||
} ViLayerStack;
|
||||
|
||||
Result viInitialize(ViServiceType service_type);
|
||||
void viExit(void);
|
||||
|
||||
|
@ -26,15 +26,15 @@ Service* capsscGetServiceSession(void) {
|
||||
return &g_capsscSrv;
|
||||
}
|
||||
|
||||
Result capsscCaptureRawImageWithTimeout(void* buf, size_t size, u32 layer_stack, u64 width, u64 height, s64 buffer_count, s64 buffer_index, u64 timeout) {
|
||||
Result capsscCaptureRawImageWithTimeout(void* buf, size_t size, ViLayerStack layer_stack, u64 width, u64 height, s64 buffer_count, s64 buffer_index, s64 timeout) {
|
||||
const struct {
|
||||
u32 layer_stack;
|
||||
s32 layer_stack;
|
||||
u32 pad;
|
||||
u64 width;
|
||||
u64 height;
|
||||
s64 buffer_count;
|
||||
s64 buffer_index;
|
||||
u64 timeout;
|
||||
s64 timeout;
|
||||
} in = { layer_stack, 0, width, height, buffer_count, buffer_index, timeout };
|
||||
|
||||
return serviceDispatchIn(&g_capsscSrv, 2, in,
|
||||
@ -43,3 +43,18 @@ Result capsscCaptureRawImageWithTimeout(void* buf, size_t size, u32 layer_stack,
|
||||
);
|
||||
}
|
||||
|
||||
Result capsscCaptureJpegScreenShot(u64* out_jpeg_size, void* jpeg_buf, size_t jpeg_buf_size, ViLayerStack layer_stack, s64 timeout) {
|
||||
if (hosversionBefore(9,0,0))
|
||||
return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
|
||||
|
||||
const struct {
|
||||
s32 layer_stack;
|
||||
u32 pad;
|
||||
s64 timeout;
|
||||
} in = { layer_stack, 0, timeout };
|
||||
|
||||
return serviceDispatchInOut(&g_capsscSrv, 1204, in, *out_jpeg_size,
|
||||
.buffer_attrs = { SfBufferAttr_HipcMapTransferAllowsNonSecure | SfBufferAttr_HipcMapAlias | SfBufferAttr_Out },
|
||||
.buffers = { { jpeg_buf, jpeg_buf_size } },
|
||||
);
|
||||
}
|
Loading…
Reference in New Issue
Block a user