Jpeg: Cleanup Init/Finish error checks.

This commit is contained in:
Unknown W. Brackets 2022-10-06 22:45:18 -07:00
parent 591a748ae2
commit 62fe178608
2 changed files with 44 additions and 15 deletions

View file

@ -24,7 +24,6 @@
#include "Core/HLE/HLE.h"
#include "Core/HLE/FunctionWrappers.h"
#include "Core/HLE/sceJpeg.h"
#include "Core/HLE/sceMpeg.h"
#include "GPU/GPUCommon.h"
#include "Core/MemMap.h"
#include "Core/Reporting.h"
@ -43,20 +42,33 @@ struct u24_be {
}
};
static int mjpegInited = 0;
static int mjpegWidth, mjpegHeight;
void __JpegInit() {
mjpegInited = 0;
mjpegWidth = 0;
mjpegHeight = 0;
}
enum : uint32_t {
ERROR_JPEG_CANNOT_FINISH = 0x80650039,
ERROR_JPEG_ALREADY_INIT = 0x80650042,
ERROR_JPEG_INVALID_VALUE = 0x80650051,
};
void __JpegDoState(PointerWrap &p) {
auto s = p.Section("sceJpeg", 1);
auto s = p.Section("sceJpeg", 1, 2);
if (!s)
return;
Do(p, mjpegWidth);
Do(p, mjpegHeight);
if (s >= 2) {
Do(p, mjpegInited);
} else {
mjpegInited = -1;
}
}
static int getWidthHeight(int width, int height) {
@ -181,11 +193,6 @@ static int sceJpegDecodeMJpeg(u32 jpegAddr, int jpegSize, u32 imageAddr, int dht
return __DecodeJpeg(jpegAddr, jpegSize, imageAddr);
}
static int sceJpegDeleteMJpeg() {
WARN_LOG(ME, "sceJpegDeleteMJpeg()");
return 0;
}
static int sceJpegDecodeMJpegSuccessively(u32 jpegAddr, int jpegSize, u32 imageAddr, int dhtMode) {
if (!Memory::IsValidAddress(jpegAddr)) {
ERROR_LOG(ME, "sceJpegDecodeMJpegSuccessively: Bad JPEG address 0x%08x", jpegAddr);
@ -208,11 +215,6 @@ static int sceJpegCsc(u32 imageAddr, u32 yCbCrAddr, int widthHeight, int bufferW
return 0;
}
static int sceJpegFinishMJpeg() {
WARN_LOG(ME, "sceJpegFinishMJpeg()");
return 0;
}
static int getYCbCrBufferSize(int w, int h) {
// Return necessary buffer size for conversion: 12 bits per pixel
return ((w * h) >> 1) * 3;
@ -378,6 +380,9 @@ static int sceJpeg_9B36444C() {
}
static int sceJpegCreateMJpeg(int width, int height) {
// Assume valid usage in an old save state.
if (mjpegInited == -1)
mjpegInited = 1;
mjpegWidth = width;
mjpegHeight = height;
@ -385,11 +390,36 @@ static int sceJpegCreateMJpeg(int width, int height) {
return 0;
}
static int sceJpegInitMJpeg() {
WARN_LOG(ME, "sceJpegInitMJpeg()");
static int sceJpegDeleteMJpeg() {
WARN_LOG(ME, "sceJpegDeleteMJpeg()");
if (mjpegInited == -1)
mjpegInited = 1;
mjpegWidth = 0;
mjpegHeight = 0;
return 0;
}
static int sceJpegInitMJpeg() {
if (mjpegInited == 1)
return hleLogError(ME, ERROR_JPEG_ALREADY_INIT, "already inited");
// If it was -1, it's from an old save state, avoid double init error but assume inited.
if (mjpegInited == 0)
mjpegInited = 1;
return hleLogDebug(ME, hleDelayResult(0, "mjpeg init", 130));
}
static int sceJpegFinishMJpeg() {
if (mjpegInited == 0)
return hleLogError(ME, ERROR_JPEG_CANNOT_FINISH, "already inited");
if (mjpegInited != -1 && (mjpegWidth != 0 || mjpegHeight != 0))
return hleLogError(ME, ERROR_JPEG_CANNOT_FINISH, "mjpeg not deleted");
// Even from an old save state, if we see this we leave compat mode.
mjpegInited = 0;
return hleLogDebug(ME, hleDelayResult(0, "mjpeg finish", 120));
}
static int sceJpegMJpegCscWithColorOption() {
ERROR_LOG_REPORT(ME, "UNIMPL sceJpegMJpegCscWithColorOption()");
return 0;

View file

@ -32,7 +32,6 @@ enum {
ERROR_MPEG_NOT_YET_INIT = 0x80618009,
ERROR_MPEG_AVC_INVALID_VALUE = 0x806201fe,
ERROR_MPEG_AVC_DECODE_FATAL = 0x80628002,
ERROR_JPEG_INVALID_VALUE = 0x80650051,
};
// MPEG statics.