mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-08-04 16:32:39 +00:00
jpegenc: Clean up parameter validations.
This commit is contained in:
parent
d3128d3068
commit
e87f17fe8c
@ -5,5 +5,5 @@
|
|||||||
|
|
||||||
constexpr int ORBIS_JPEG_ENC_ERROR_INVALID_ADDR = 0x80650101;
|
constexpr int ORBIS_JPEG_ENC_ERROR_INVALID_ADDR = 0x80650101;
|
||||||
constexpr int ORBIS_JPEG_ENC_ERROR_INVALID_SIZE = 0x80650102;
|
constexpr int ORBIS_JPEG_ENC_ERROR_INVALID_SIZE = 0x80650102;
|
||||||
constexpr int ORBIS_JPEG_ENC_ERROR_INVALID_ATTR = 0x80650103;
|
constexpr int ORBIS_JPEG_ENC_ERROR_INVALID_PARAM = 0x80650103;
|
||||||
constexpr int ORBIS_JPEG_ENC_ERROR_INVALID_HANDLE = 0x80650104;
|
constexpr int ORBIS_JPEG_ENC_ERROR_INVALID_HANDLE = 0x80650104;
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
#include <magic_enum.hpp>
|
||||||
#include "common/alignment.h"
|
#include "common/alignment.h"
|
||||||
#include "common/assert.h"
|
#include "common/assert.h"
|
||||||
#include "common/logging/log.h"
|
#include "common/logging/log.h"
|
||||||
@ -24,7 +25,7 @@ static s32 ValidateJpegEncCreateParam(const OrbisJpegEncCreateParam* param) {
|
|||||||
return ORBIS_JPEG_ENC_ERROR_INVALID_SIZE;
|
return ORBIS_JPEG_ENC_ERROR_INVALID_SIZE;
|
||||||
}
|
}
|
||||||
if (param->attr != ORBIS_JPEG_ENC_ATTRIBUTE_NONE) {
|
if (param->attr != ORBIS_JPEG_ENC_ATTRIBUTE_NONE) {
|
||||||
return ORBIS_JPEG_ENC_ERROR_INVALID_ATTR;
|
return ORBIS_JPEG_ENC_ERROR_INVALID_PARAM;
|
||||||
}
|
}
|
||||||
return ORBIS_OK;
|
return ORBIS_OK;
|
||||||
}
|
}
|
||||||
@ -61,47 +62,58 @@ static s32 ValidateJpegEncEncodeParam(const OrbisJpegEncEncodeParam* param) {
|
|||||||
// Validate parameters
|
// Validate parameters
|
||||||
if (param->image_width > ORBIS_JPEG_ENC_MAX_IMAGE_DIMENSION ||
|
if (param->image_width > ORBIS_JPEG_ENC_MAX_IMAGE_DIMENSION ||
|
||||||
param->image_height > ORBIS_JPEG_ENC_MAX_IMAGE_DIMENSION) {
|
param->image_height > ORBIS_JPEG_ENC_MAX_IMAGE_DIMENSION) {
|
||||||
return ORBIS_JPEG_ENC_ERROR_INVALID_ATTR;
|
return ORBIS_JPEG_ENC_ERROR_INVALID_PARAM;
|
||||||
}
|
}
|
||||||
if (param->image_pitch == 0 || param->image_pitch > ORBIS_JPEG_ENC_MAX_IMAGE_PITCH ||
|
if (param->image_pitch == 0 || param->image_pitch > ORBIS_JPEG_ENC_MAX_IMAGE_PITCH ||
|
||||||
(param->pixel_format != ORBIS_JPEG_ENC_PIXEL_FORMAT_Y8 &&
|
(param->pixel_format != ORBIS_JPEG_ENC_PIXEL_FORMAT_Y8 &&
|
||||||
!Common::IsAligned(param->image_pitch, 4))) {
|
!Common::IsAligned(param->image_pitch, 4))) {
|
||||||
return ORBIS_JPEG_ENC_ERROR_INVALID_ATTR;
|
return ORBIS_JPEG_ENC_ERROR_INVALID_PARAM;
|
||||||
}
|
}
|
||||||
const auto calculated_size = param->image_height * param->image_pitch;
|
const auto calculated_size = param->image_height * param->image_pitch;
|
||||||
if (calculated_size > ORBIS_JPEG_ENC_MAX_IMAGE_SIZE || calculated_size > param->image_size) {
|
if (calculated_size > ORBIS_JPEG_ENC_MAX_IMAGE_SIZE || calculated_size > param->image_size) {
|
||||||
return ORBIS_JPEG_ENC_ERROR_INVALID_ATTR;
|
return ORBIS_JPEG_ENC_ERROR_INVALID_PARAM;
|
||||||
}
|
}
|
||||||
if (param->pixel_format != ORBIS_JPEG_ENC_PIXEL_FORMAT_R8G8B8A8 &&
|
if (param->encode_mode != ORBIS_JPEG_ENC_ENCODE_MODE_NORMAL &&
|
||||||
param->pixel_format != ORBIS_JPEG_ENC_PIXEL_FORMAT_B8G8R8A8 &&
|
param->encode_mode != ORBIS_JPEG_ENC_ENCODE_MODE_MJPEG) {
|
||||||
param->pixel_format != ORBIS_JPEG_ENC_PIXEL_FORMAT_Y8U8Y8V8 &&
|
return ORBIS_JPEG_ENC_ERROR_INVALID_PARAM;
|
||||||
param->pixel_format != ORBIS_JPEG_ENC_PIXEL_FORMAT_Y8) {
|
|
||||||
return ORBIS_JPEG_ENC_ERROR_INVALID_ATTR;
|
|
||||||
}
|
}
|
||||||
if (param->encode_mode > 1 || param->color_space > 2 || param->sampling_type > 2 ||
|
if (param->color_space != ORBIS_JPEG_ENC_COLOR_SPACE_YCC &&
|
||||||
param->restart_interval > ORBIS_JPEG_ENC_MAX_IMAGE_DIMENSION) {
|
param->color_space != ORBIS_JPEG_ENC_COLOR_SPACE_GRAYSCALE) {
|
||||||
return ORBIS_JPEG_ENC_ERROR_INVALID_ATTR;
|
return ORBIS_JPEG_ENC_ERROR_INVALID_PARAM;
|
||||||
}
|
}
|
||||||
if (param->pixel_format < 2) {
|
if (param->sampling_type != ORBIS_JPEG_ENC_SAMPLING_TYPE_FULL &&
|
||||||
|
param->sampling_type != ORBIS_JPEG_ENC_SAMPLING_TYPE_422 &&
|
||||||
|
param->sampling_type != ORBIS_JPEG_ENC_SAMPLING_TYPE_420) {
|
||||||
|
return ORBIS_JPEG_ENC_ERROR_INVALID_PARAM;
|
||||||
|
}
|
||||||
|
if (param->restart_interval > ORBIS_JPEG_ENC_MAX_IMAGE_DIMENSION) {
|
||||||
|
return ORBIS_JPEG_ENC_ERROR_INVALID_PARAM;
|
||||||
|
}
|
||||||
|
switch (param->pixel_format) {
|
||||||
|
case ORBIS_JPEG_ENC_PIXEL_FORMAT_R8G8B8A8:
|
||||||
|
case ORBIS_JPEG_ENC_PIXEL_FORMAT_B8G8R8A8:
|
||||||
if (param->image_pitch >> 2 < param->image_width ||
|
if (param->image_pitch >> 2 < param->image_width ||
|
||||||
(param->color_space != ORBIS_JPEG_ENC_COLOR_SPACE_YCC &&
|
param->color_space != ORBIS_JPEG_ENC_COLOR_SPACE_YCC ||
|
||||||
param->sampling_type != ORBIS_JPEG_ENC_SAMPLING_TYPE_FULL) ||
|
|
||||||
param->sampling_type == ORBIS_JPEG_ENC_SAMPLING_TYPE_FULL) {
|
param->sampling_type == ORBIS_JPEG_ENC_SAMPLING_TYPE_FULL) {
|
||||||
return ORBIS_JPEG_ENC_ERROR_INVALID_ATTR;
|
return ORBIS_JPEG_ENC_ERROR_INVALID_PARAM;
|
||||||
}
|
}
|
||||||
} else if (param->pixel_format == ORBIS_JPEG_ENC_PIXEL_FORMAT_Y8U8Y8V8) {
|
break;
|
||||||
|
case ORBIS_JPEG_ENC_PIXEL_FORMAT_Y8U8Y8V8:
|
||||||
if (param->image_pitch >> 1 < Common::AlignUp(param->image_width, 2) ||
|
if (param->image_pitch >> 1 < Common::AlignUp(param->image_width, 2) ||
|
||||||
(param->color_space != ORBIS_JPEG_ENC_COLOR_SPACE_YCC &&
|
param->color_space != ORBIS_JPEG_ENC_COLOR_SPACE_YCC ||
|
||||||
param->sampling_type != ORBIS_JPEG_ENC_SAMPLING_TYPE_FULL) ||
|
|
||||||
param->sampling_type == ORBIS_JPEG_ENC_SAMPLING_TYPE_FULL) {
|
param->sampling_type == ORBIS_JPEG_ENC_SAMPLING_TYPE_FULL) {
|
||||||
return ORBIS_JPEG_ENC_ERROR_INVALID_ATTR;
|
return ORBIS_JPEG_ENC_ERROR_INVALID_PARAM;
|
||||||
}
|
}
|
||||||
} else if (param->pixel_format == ORBIS_JPEG_ENC_PIXEL_FORMAT_Y8) {
|
break;
|
||||||
if (param->color_space != ORBIS_JPEG_ENC_COLOR_SPACE_GRAYSCALE ||
|
case ORBIS_JPEG_ENC_PIXEL_FORMAT_Y8:
|
||||||
param->image_pitch < param->image_width ||
|
if (param->image_pitch < param->image_width ||
|
||||||
|
param->color_space != ORBIS_JPEG_ENC_COLOR_SPACE_GRAYSCALE ||
|
||||||
param->sampling_type != ORBIS_JPEG_ENC_SAMPLING_TYPE_FULL) {
|
param->sampling_type != ORBIS_JPEG_ENC_SAMPLING_TYPE_FULL) {
|
||||||
return ORBIS_JPEG_ENC_ERROR_INVALID_ATTR;
|
return ORBIS_JPEG_ENC_ERROR_INVALID_PARAM;
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return ORBIS_JPEG_ENC_ERROR_INVALID_PARAM;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ORBIS_OK;
|
return ORBIS_OK;
|
||||||
@ -164,8 +176,10 @@ s32 PS4_SYSV_ABI sceJpegEncEncode(OrbisJpegEncHandle handle, const OrbisJpegEncE
|
|||||||
"image_pitch = {} , pixel_format = {} , encode_mode = {} , sampling_type = {} , "
|
"image_pitch = {} , pixel_format = {} , encode_mode = {} , sampling_type = {} , "
|
||||||
"compression_ratio = {} , restart_interval = {}",
|
"compression_ratio = {} , restart_interval = {}",
|
||||||
param->image_size, param->jpeg_size, param->image_width, param->image_height,
|
param->image_size, param->jpeg_size, param->image_width, param->image_height,
|
||||||
param->image_pitch, param->pixel_format, param->encode_mode, param->color_space,
|
param->image_pitch, magic_enum::enum_name(param->pixel_format),
|
||||||
param->sampling_type, param->compression_ratio, param->restart_interval);
|
magic_enum::enum_name(param->encode_mode), magic_enum::enum_name(param->color_space),
|
||||||
|
magic_enum::enum_name(param->sampling_type), param->compression_ratio,
|
||||||
|
param->restart_interval);
|
||||||
|
|
||||||
if (output_info) {
|
if (output_info) {
|
||||||
output_info->size = param->jpeg_size;
|
output_info->size = param->jpeg_size;
|
||||||
|
@ -11,26 +11,26 @@ class SymbolsResolver;
|
|||||||
|
|
||||||
namespace Libraries::JpegEnc {
|
namespace Libraries::JpegEnc {
|
||||||
|
|
||||||
enum OrbisJpegEncCreateParamAttributes { ORBIS_JPEG_ENC_ATTRIBUTE_NONE = 0 };
|
enum OrbisJpegEncCreateParamAttributes : u32 { ORBIS_JPEG_ENC_ATTRIBUTE_NONE = 0 };
|
||||||
|
|
||||||
enum OrbisJpegEncEncodeParamPixelFormat {
|
enum OrbisJpegEncEncodeParamPixelFormat : u16 {
|
||||||
ORBIS_JPEG_ENC_PIXEL_FORMAT_R8G8B8A8 = 0,
|
ORBIS_JPEG_ENC_PIXEL_FORMAT_R8G8B8A8 = 0,
|
||||||
ORBIS_JPEG_ENC_PIXEL_FORMAT_B8G8R8A8 = 1,
|
ORBIS_JPEG_ENC_PIXEL_FORMAT_B8G8R8A8 = 1,
|
||||||
ORBIS_JPEG_ENC_PIXEL_FORMAT_Y8U8Y8V8 = 10,
|
ORBIS_JPEG_ENC_PIXEL_FORMAT_Y8U8Y8V8 = 10,
|
||||||
ORBIS_JPEG_ENC_PIXEL_FORMAT_Y8 = 11
|
ORBIS_JPEG_ENC_PIXEL_FORMAT_Y8 = 11
|
||||||
};
|
};
|
||||||
|
|
||||||
enum OrbisJpengEncEncodeParamEncodeMode {
|
enum OrbisJpengEncEncodeParamEncodeMode : u16 {
|
||||||
ORBIS_JPEG_ENC_ENCODE_MODE_NORMAL = 0,
|
ORBIS_JPEG_ENC_ENCODE_MODE_NORMAL = 0,
|
||||||
ORBIS_JPEG_ENC_ENCODE_MODE_MJPEG = 1
|
ORBIS_JPEG_ENC_ENCODE_MODE_MJPEG = 1
|
||||||
};
|
};
|
||||||
|
|
||||||
enum OrbisJpengEncEncodeParamColorSpace {
|
enum OrbisJpengEncEncodeParamColorSpace : u16 {
|
||||||
ORBIS_JPEG_ENC_COLOR_SPACE_YCC = 1,
|
ORBIS_JPEG_ENC_COLOR_SPACE_YCC = 1,
|
||||||
ORBIS_JPEG_ENC_COLOR_SPACE_GRAYSCALE = 2
|
ORBIS_JPEG_ENC_COLOR_SPACE_GRAYSCALE = 2
|
||||||
};
|
};
|
||||||
|
|
||||||
enum OrbisJpengEncEncodeParamSamplingType {
|
enum OrbisJpengEncEncodeParamSamplingType : u8 {
|
||||||
ORBIS_JPEG_ENC_SAMPLING_TYPE_FULL = 0,
|
ORBIS_JPEG_ENC_SAMPLING_TYPE_FULL = 0,
|
||||||
ORBIS_JPEG_ENC_SAMPLING_TYPE_422 = 1,
|
ORBIS_JPEG_ENC_SAMPLING_TYPE_422 = 1,
|
||||||
ORBIS_JPEG_ENC_SAMPLING_TYPE_420 = 2
|
ORBIS_JPEG_ENC_SAMPLING_TYPE_420 = 2
|
||||||
@ -46,7 +46,7 @@ typedef OrbisJpegEncHandleInternal* OrbisJpegEncHandle;
|
|||||||
|
|
||||||
struct OrbisJpegEncCreateParam {
|
struct OrbisJpegEncCreateParam {
|
||||||
u32 size;
|
u32 size;
|
||||||
u32 attr;
|
OrbisJpegEncCreateParamAttributes attr;
|
||||||
};
|
};
|
||||||
static_assert(sizeof(OrbisJpegEncCreateParam) == 0x8);
|
static_assert(sizeof(OrbisJpegEncCreateParam) == 0x8);
|
||||||
|
|
||||||
@ -58,10 +58,10 @@ struct OrbisJpegEncEncodeParam {
|
|||||||
u32 image_width;
|
u32 image_width;
|
||||||
u32 image_height;
|
u32 image_height;
|
||||||
u32 image_pitch;
|
u32 image_pitch;
|
||||||
u16 pixel_format;
|
OrbisJpegEncEncodeParamPixelFormat pixel_format;
|
||||||
u16 encode_mode;
|
OrbisJpengEncEncodeParamEncodeMode encode_mode;
|
||||||
u16 color_space;
|
OrbisJpengEncEncodeParamColorSpace color_space;
|
||||||
u8 sampling_type;
|
OrbisJpengEncEncodeParamSamplingType sampling_type;
|
||||||
u8 compression_ratio;
|
u8 compression_ratio;
|
||||||
s32 restart_interval;
|
s32 restart_interval;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user