Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for sceJpeg functions #229

Merged
merged 4 commits into from
Oct 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions tests/jpeg/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
TARGETS = create csc decode decodes decodeycbcr decodeycbcrs delete finish getoutputinfo init mjpegcsc
EXTRA_LIBS = -lpsputility -lpspjpeg

COMMON_DIR = ../../common
include $(COMMON_DIR)/common.mk
Binary file added tests/jpeg/background.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/jpeg/background2x1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/jpeg/backgroundgray.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions tests/jpeg/create.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include <common.h>
#include <pspjpeg.h>
#include <psputility.h>

extern "C" int main(int argc, char *argv[]) {
sceUtilityLoadModule(PSP_MODULE_AV_AVCODEC);

checkpointNext("Basic:");
checkpoint(" Before init: %08x", sceJpegCreateMJpeg(480, 272));
checkpoint(" Init: %08x", sceJpegInitMJpeg());
checkpoint(" After init: %08x", sceJpegCreateMJpeg(480, 272));
checkpoint(" Twice: %08x", sceJpegCreateMJpeg(480, 272));
checkpoint(" Delete: %08x", sceJpegDeleteMJpeg());
checkpoint(" After delete: %08x", sceJpegCreateMJpeg(480, 272));
sceJpegDeleteMJpeg();

checkpointNext("Widths:");
static const int sizes[] = { 0x80000000, 0xFFFF0000, 0xFFFF8000, -1, 0, 1, 2, 3, 4, 5, 480, 512, 1023, 1024, 1025, 2048, 0x8000, 0x7FFFFFFF};
for (size_t i = 0; i < ARRAY_SIZE(sizes); ++i) {
char temp[256];
checkpoint(" Width %d: %08x", sizes[i], sceJpegCreateMJpeg(sizes[i], 272));
sceJpegDeleteMJpeg();
}

checkpointNext("Heights:");
for (size_t i = 0; i < ARRAY_SIZE(sizes); ++i) {
char temp[256];
checkpoint(" Height %d: %08x", sizes[i], sceJpegCreateMJpeg(480, sizes[i]));
sceJpegDeleteMJpeg();
}

checkpointNext("Total:");
checkpoint(" Size 1024x1024: %08x", sceJpegCreateMJpeg(1024, 1024));
sceJpegDeleteMJpeg();

sceUtilityUnloadModule(PSP_MODULE_AV_AVCODEC);
return 0;
}
50 changes: 50 additions & 0 deletions tests/jpeg/create.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
[x] Basic:
[x] Before init: 80650039
[r] Init: 00000000
[x] After init: 00000000
[x] Twice: 80650039
[x] Delete: 00000000
[x] After delete: 00000000

[x] Widths:
[x] Width -2147483648: 00000000
[x] Width -65536: 00000000
[x] Width -32768: 00000000
[x] Width -1: 00000000
[x] Width 0: 00000000
[x] Width 1: 00000000
[x] Width 2: 00000000
[x] Width 3: 00000000
[x] Width 4: 00000000
[x] Width 5: 00000000
[x] Width 480: 00000000
[x] Width 512: 00000000
[x] Width 1023: 00000000
[x] Width 1024: 00000000
[x] Width 1025: 80650020
[x] Width 2048: 80650020
[x] Width 32768: 80650020
[x] Width 2147483647: 80650020

[x] Heights:
[x] Height -2147483648: 00000000
[x] Height -65536: 00000000
[x] Height -32768: 00000000
[x] Height -1: 00000000
[x] Height 0: 00000000
[x] Height 1: 00000000
[x] Height 2: 00000000
[x] Height 3: 00000000
[x] Height 4: 00000000
[x] Height 5: 00000000
[x] Height 480: 00000000
[x] Height 512: 00000000
[x] Height 1023: 00000000
[x] Height 1024: 00000000
[x] Height 1025: 00000000
[x] Height 2048: 00000000
[x] Height 32768: 00000000
[x] Height 2147483647: 00000000

[x] Total:
[x] Size 1024x1024: 00000000
Binary file added tests/jpeg/create.prx
Binary file not shown.
178 changes: 178 additions & 0 deletions tests/jpeg/csc.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
#include "shared.h"
#include <malloc.h>
#include <psputility.h>
#include <psputils.h>

// sceJpegCsc
extern "C" int sceJpeg_67F0ED84(void *dest, const void *srcYCbCr, uint32_t widthHeight, int stride, uint32_t chroma);

static uint8_t ycbcr[786432];
static uint32_t *frame;
static const uint32_t FRAME_SIZE = 1024 * 1024 * 4;

static void testJpegCsc(const char *title, bool useDest, bool useSrc, uint32_t widthHeight, int stride, uint32_t chroma) {
memset(frame, 0xCC, FRAME_SIZE + 4);
sceKernelDcacheWritebackInvalidateRange(frame, FRAME_SIZE + 4);

uint32_t result = sceJpeg_67F0ED84(useDest ? frame : NULL, useSrc ? ycbcr : NULL, widthHeight, stride, chroma);
size_t len = 0;
for (int i = 1024 * 1024; i >= 0; --i) {
if (frame[i] != 0xCCCCCCCC) {
len = (i + 1) * sizeof(uint32_t);
break;
}
}
size_t rowLen = 0;
for (int i = 0; i < (int)len; ++i) {
if (frame[i] == 0xCCCCCCCC) {
rowLen = i * sizeof(uint32_t);
break;
}
}
checkpoint("%s: %08x (wrote %d bytes, %d per row)", title, result, len, rowLen);
}

static void testJpegCscPattern(const char *title, int chroma, int y, int cb, int cr) {
sceKernelDcacheWritebackInvalidateRange(frame, 256);
memset(frame, 0xCC, 256);
sceKernelDcacheWritebackInvalidateRange(frame, 256);

int cbcrSize = chroma == 0x00020101 ? 256 : (chroma == 0x00020201 ? 128 : 64);

sceKernelDcacheWritebackInvalidateRange(ycbcr, sizeof(ycbcr));
memset(ycbcr, 0, 768);
memset(ycbcr, 0xFF, y);
memset(ycbcr + 256, 0xFF, cb);
memset(ycbcr + 256 + cbcrSize, 0xFF, cr);
sceKernelDcacheWritebackInvalidateRange(ycbcr, 768);

int result = sceJpeg_67F0ED84(frame, ycbcr, 0x00100010, 0x0010, chroma);
checkpoint(NULL);
schedf("%s: %08x =", title, result);
uint32_t last = frame[0];
int lasti = 0;
for (int i = 1; i < 256; ++i) {
if (frame[i] != last) {
schedf(" %d-%d %08x", lasti, i - 1, last);
last = frame[i];
lasti = i;
}
}
schedf(" %d-255 %08x\n", lasti, last);
}

static void testJpegCscValue(const char *title, int chroma, uint8_t yy, uint8_t cb, uint8_t cr) {
sceKernelDcacheWritebackInvalidateRange(frame, 4);
memset(frame, 0xCC, 4);
sceKernelDcacheWritebackInvalidateRange(frame, 4);

sceKernelDcacheWritebackInvalidateRange(ycbcr, sizeof(ycbcr));
memset(ycbcr, 0, 768);
ycbcr[0] = yy;
ycbcr[256] = cb;
if (chroma == 0x00020202) {
ycbcr[256 + 64] = cr;
} else if (chroma == 0x00020201) {
ycbcr[256 + 128] = cr;
} else if (chroma == 0x00020101) {
ycbcr[256 + 256] = cr;
}
sceKernelDcacheWritebackInvalidateRange(ycbcr, sizeof(ycbcr));

int result = sceJpeg_67F0ED84(frame, ycbcr, 0x00100010, 0x0010, chroma);
checkpoint("%s: %08x (%08x)", title, result, frame[0]);
}

extern "C" int main(int argc, char *argv[]) {
sceUtilityLoadModule(PSP_MODULE_AV_AVCODEC);

frame = (uint32_t *)malloc(FRAME_SIZE + 4);

checkpointNext("Basic:");
testJpegCsc(" Before init", true, true, 0x00100010, 0x0010, 0x00020202);
checkpoint(" Init: %08x", sceJpegInitMJpeg());
testJpegCsc(" After init", true, true, 0x00100010, 0x0010, 0x00020202);

checkpointNext("Buffers:");
testJpegCsc(" Output NULL", false, true, 0x00100010, 0x0010, 0x00020202);
testJpegCsc(" input NULL", true, false, 0x00100010, 0x0010, 0x00020202);

checkpointNext("Sizes:");
testJpegCsc(" Wider than stride", true, true, 0x00200020, 0x0010, 0x00020202);
testJpegCsc(" Thinner than stride", true, true, 0x00100020, 0x0020, 0x00020202);
testJpegCsc(" Odd size", true, true, 0x05550555, 0x0010, 0x00020202);
testJpegCsc(" Large width", true, true, 0xFFFF0001, 0x0010, 0x00020202);
// Seems like values below 7 (but 7 DOES work) hang.
//testJpegCsc(" Zero width", true, true, 0x00000010, 0x0010, 0x00020202);
testJpegCsc(" Small width", true, true, 0x00070010, 0x0010, 0x00020202);
testJpegCsc(" Large height", true, true, 0x0008FFFF, 0x0008, 0x00020202);
testJpegCsc(" Zero height", true, true, 0x00080000, 0x0008, 0x00020202);
testJpegCsc(" One height", true, true, 0x00080001, 0x0008, 0x00020202);

checkpointNext("Strides:");
testJpegCsc(" Zero stride", true, true, 0x00100010, 0, 0x00020202);
testJpegCsc(" One stride", true, true, 0x00100010, 1, 0x00020202);
testJpegCsc(" Large stride", true, true, 0x00100002, 0x7FFFF, 0x00020202);
// Hangs, maybe corrupts memory?
//testJpegCsc(" Very large stride", true, true, 0x00100002, 0x7FFFFFFF, 0x00020202);
testJpegCsc(" Very negative stride", true, true, 0x00100002, 0x80000000, 0x00020202);

checkpointNext("Choma Sampling:");
testJpegCsc(" Grayscale", true, true, 0x00100010, 0x0010, 0x00010101);
testJpegCsc(" 1x1", true, true, 0x00100010, 0x0010, 0x00020101);
testJpegCsc(" 2x1", true, true, 0x00100010, 0x0010, 0x00020201);
testJpegCsc(" 2x1", true, true, 0x00100010, 0x0010, 0x00020102);
testJpegCsc(" 3x3", true, true, 0x00100010, 0x0010, 0x00020303);
testJpegCsc(" 4x4", true, true, 0x00100010, 0x0010, 0x00020404);
testJpegCsc(" Extra bits (top 12)", true, true, 0x00100010, 0x0010, 0xFFF20202);
testJpegCsc(" Extra bits (top 13)", true, true, 0x00100010, 0x0010, 0xFFFA0202);

checkpointNext("X/Y Pattern:");
testJpegCscPattern(" 2x2 short y", 0x00020202, 255, 64, 64);
testJpegCscPattern(" 2x2 short cb", 0x00020202, 256, 63, 64);
testJpegCscPattern(" 2x2 short cr", 0x00020202, 256, 64, 63);
testJpegCscPattern(" 2x1 short y", 0x00020201, 255, 128, 128);
testJpegCscPattern(" 2x1 short cb", 0x00020201, 256, 127, 128);
testJpegCscPattern(" 2x1 short cr", 0x00020201, 256, 128, 127);
testJpegCscPattern(" 1x1 short y", 0x00020101, 255, 256, 256);
testJpegCscPattern(" 1x1 short cb", 0x00020101, 256, 255, 256);
testJpegCscPattern(" 1x1 short cr", 0x00020101, 256, 256, 255);

checkpointNext("Bits:");
testJpegCscValue(" 2x2 Black", 0x00020202, 0, 128, 128);
testJpegCscValue(" 2x2 White", 0x00020202, 255, 128, 128);
testJpegCscValue(" 2x2 0 Cb", 0x00020202, 255, 0, 128);
testJpegCscValue(" 2x2 1 Cb", 0x00020202, 255, 1, 128);
testJpegCscValue(" 2x2 254 Cb", 0x00020202, 255, 254, 128);
testJpegCscValue(" 2x2 255 Cb", 0x00020202, 255, 255, 128);
testJpegCscValue(" 2x2 0 Cr", 0x00020202, 255, 128, 0);
testJpegCscValue(" 2x2 1 Cr", 0x00020202, 255, 128, 1);
testJpegCscValue(" 2x2 254 Cr", 0x00020202, 255, 128, 254);
testJpegCscValue(" 2x2 255 Cr", 0x00020202, 255, 128, 255);

testJpegCscValue(" 2x1 Black", 0x00020201, 0, 128, 128);
testJpegCscValue(" 2x1 White", 0x00020201, 255, 128, 128);
testJpegCscValue(" 2x1 0 Cb", 0x00020201, 255, 0, 128);
testJpegCscValue(" 2x1 1 Cb", 0x00020201, 255, 1, 128);
testJpegCscValue(" 2x1 254 Cb", 0x00020201, 255, 254, 128);
testJpegCscValue(" 2x1 255 Cb", 0x00020201, 255, 255, 128);
testJpegCscValue(" 2x1 0 Cr", 0x00020201, 255, 128, 0);
testJpegCscValue(" 2x1 1 Cr", 0x00020201, 255, 128, 1);
testJpegCscValue(" 2x1 254 Cr", 0x00020201, 255, 128, 254);
testJpegCscValue(" 2x1 255 Cr", 0x00020201, 255, 128, 255);

testJpegCscValue(" 1x1 Black", 0x00020101, 0, 128, 128);
testJpegCscValue(" 1x1 White", 0x00020101, 255, 128, 128);
testJpegCscValue(" 1x1 0 Cb", 0x00020101, 255, 0, 128);
testJpegCscValue(" 1x1 1 Cb", 0x00020101, 255, 1, 128);
testJpegCscValue(" 1x1 254 Cb", 0x00020101, 255, 254, 128);
testJpegCscValue(" 1x1 255 Cb", 0x00020101, 255, 255, 128);
testJpegCscValue(" 1x1 0 Cr", 0x00020101, 255, 128, 0);
testJpegCscValue(" 1x1 1 Cr", 0x00020101, 255, 128, 1);
testJpegCscValue(" 1x1 254 Cr", 0x00020101, 255, 128, 254);
testJpegCscValue(" 1x1 255 Cr", 0x00020101, 255, 128, 255);

free(frame);
sceUtilityUnloadModule(PSP_MODULE_AV_AVCODEC);
return 0;
}
77 changes: 77 additions & 0 deletions tests/jpeg/csc.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
[x] Basic:
[r] Before init: 00000000 (wrote 1024 bytes, 1024 per row)
[x] Init: 00000000
[r] After init: 00000000 (wrote 1024 bytes, 1024 per row)

[x] Buffers:
[x] Output NULL: 80650051 (wrote 0 bytes, 0 per row)
[x] input NULL: 80650051 (wrote 0 bytes, 0 per row)

[x] Sizes:
[r] Wider than stride: 00000000 (wrote 2112 bytes, 2112 per row)
[r] Thinner than stride: 00000000 (wrote 4032 bytes, 64 per row)
[r] Odd size: 00000000 (wrote 92756 bytes, 92756 per row)
[r] Large width: 00000000 (wrote 262140 bytes, 262140 per row)
[r] Small width: 00000000 (wrote 988 bytes, 28 per row)
[r] Large height: 00000000 (wrote 2097120 bytes, 2097120 per row)
[r] Zero height: ffffffff (wrote 32 bytes, 32 per row)
[r] One height: 00000000 (wrote 32 bytes, 32 per row)

[x] Strides:
[r] Zero stride: 00000000 (wrote 64 bytes, 64 per row)
[r] One stride: 00000000 (wrote 124 bytes, 124 per row)
[r] Large stride: 00000000 (wrote 2097212 bytes, 64 per row)
[r] Very negative stride: 00000000 (wrote 64 bytes, 64 per row)

[x] Choma Sampling:
[x] Grayscale: 80650013 (wrote 0 bytes, 0 per row)
[r] 1x1: 00000000 (wrote 1024 bytes, 1024 per row)
[r] 2x1: 00000000 (wrote 1024 bytes, 1024 per row)
[x] 2x1: 80650013 (wrote 0 bytes, 0 per row)
[x] 3x3: 80650013 (wrote 0 bytes, 0 per row)
[x] 4x4: 80650013 (wrote 0 bytes, 0 per row)
[r] Extra bits (top 12): 00000000 (wrote 2000 bytes, 1024 per row)
[x] Extra bits (top 13): 80650013 (wrote 0 bytes, 0 per row)

[x] X/Y Pattern:
[r] 2x2 short y: 00000000 = 0-254 00ff79ff 255-255 00e100b2
[r] 2x2 short cb: 00000000 = 0-237 00ff79ff 238-239 001cd0ff 240-253 00ff79ff 254-255 001cd0ff
[r] 2x2 short cr: 00000000 = 0-237 00ff79ff 238-239 00ffff4c 240-253 00ff79ff 254-255 00ffff4c
[r] 2x1 short y: 00000000 = 0-254 00ff79ff 255-255 00e100b2
[r] 2x1 short cb: 00000000 = 0-253 00ff79ff 254-255 001cd0ff
[r] 2x1 short cr: 00000000 = 0-253 00ff79ff 254-255 00ffff4c
[r] 1x1 short y: 00000000 = 0-254 00ff79ff 255-255 00e100b2
[r] 1x1 short cb: 00000000 = 0-254 00ff79ff 255-255 001cd0ff
[r] 1x1 short cr: 00000000 = 0-254 00ff79ff 255-255 00ffff4c

[x] Bits:
[r] 2x2 Black: 00000000 (00000000)
[r] 2x2 White: 00000000 (00ffffff)
[r] 2x2 0 Cb: 00000000 (001cffff)
[r] 2x2 1 Cb: 00000000 (001effff)
[r] 2x2 254 Cb: 00000000 (00ffd4ff)
[r] 2x2 255 Cb: 00000000 (00ffd3ff)
[r] 2x2 0 Cr: 00000000 (00ffff4c)
[r] 2x2 1 Cr: 00000000 (00ffff4d)
[r] 2x2 254 Cr: 00000000 (00ffa5ff)
[r] 2x2 255 Cr: 00000000 (00ffa4ff)
[r] 2x1 Black: 00000000 (00000000)
[r] 2x1 White: 00000000 (00ffffff)
[r] 2x1 0 Cb: 00000000 (001cffff)
[r] 2x1 1 Cb: 00000000 (001effff)
[r] 2x1 254 Cb: 00000000 (00ffd4ff)
[r] 2x1 255 Cb: 00000000 (00ffd3ff)
[r] 2x1 0 Cr: 00000000 (00ffff4c)
[r] 2x1 1 Cr: 00000000 (00ffff4d)
[r] 2x1 254 Cr: 00000000 (00ffa5ff)
[r] 2x1 255 Cr: 00000000 (00ffa4ff)
[r] 1x1 Black: 00000000 (00000000)
[r] 1x1 White: 00000000 (00ffffff)
[r] 1x1 0 Cb: 00000000 (001cffff)
[r] 1x1 1 Cb: 00000000 (001effff)
[r] 1x1 254 Cb: 00000000 (00ffd4ff)
[r] 1x1 255 Cb: 00000000 (00ffd3ff)
[r] 1x1 0 Cr: 00000000 (00ffff4c)
[r] 1x1 1 Cr: 00000000 (00ffff4d)
[r] 1x1 254 Cr: 00000000 (00ffa5ff)
[r] 1x1 255 Cr: 00000000 (00ffa4ff)
Binary file added tests/jpeg/csc.prx
Binary file not shown.
Loading