USB: restore formatting of standalone third party code

This commit is contained in:
GovanifY 2020-11-04 15:19:01 +01:00 committed by refractionpcsx2
parent 9da3d9a5bf
commit ede7fa86fa
5 changed files with 512 additions and 1344 deletions

View File

@ -38,160 +38,35 @@
static const unsigned char s_jo_HTDC_Y[9][2] = {{4,3}, {0,2}, {1,2}, {5,3}, {6,3}, {14,4}, {30,5}, {62,6}, {126,7}};
static const unsigned char s_jo_HTDC_C[9][2] = {{0,2}, {1,2}, {2,2}, {6,3}, {14,4}, {30,5}, {62,6}, {126,7}, {254,8}};
static const unsigned char s_jo_HTAC[32][40][2] = {
{
{6, 3},
{8, 5},
{10, 6},
{12, 8},
{76, 9},
{66, 9},
{20, 11},
{58, 13},
{48, 13},
{38, 13},
{32, 13},
{52, 14},
{50, 14},
{48, 14},
{46, 14},
{62, 15},
{62, 15},
{58, 15},
{56, 15},
{54, 15},
{52, 15},
{50, 15},
{48, 15},
{46, 15},
{44, 15},
{42, 15},
{40, 15},
{38, 15},
{36, 15},
{34, 15},
{32, 15},
{48, 16},
{46, 16},
{44, 16},
{42, 16},
{40, 16},
{38, 16},
{36, 16},
{34, 16},
{32, 16},
},
{{6,3},{8,5},{10,6},{12,8},{76,9},{66,9},{20,11},{58,13},{48,13},{38,13},{32,13},{52,14},{50,14},{48,14},{46,14},{62,15},{62,15},{58,15},{56,15},{54,15},{52,15},{50,15},{48,15},{46,15},{44,15},{42,15},{40,15},{38,15},{36,15},{34,15},{32,15},{48,16},{46,16},{44,16},{42,16},{40,16},{38,16},{36,16},{34,16},{32,16},},
{{6,4},{12,7},{74,9},{24,11},{54,13},{44,14},{42,14},{62,16},{60,16},{58,16},{56,16},{54,16},{52,16},{50,16},{38,17},{36,17},{34,17},{32,17}},
{{10,5},{8,8},{22,11},{40,13},{40,14}},
{{14,6},{72,9},{56,13},{38,14}},
{{12, 6}, {30, 11}, {36, 13}},
{{14, 7}, {18, 11}, {36, 14}},
{{10, 7}, {60, 13}, {40, 17}},
{{8, 7}, {42, 13}},
{{14, 8}, {34, 13}},
{{10, 8}, {34, 14}},
{{78, 9}, {32, 14}},
{{70, 9}, {52, 17}},
{{68, 9}, {50, 17}},
{{64, 9}, {48, 17}},
{{28, 11}, {46, 17}},
{{26, 11}, {44, 17}},
{{16, 11}, {42, 17}},
{{62, 13}},
{{52, 13}},
{{50, 13}},
{{46, 13}},
{{44, 13}},
{{62, 14}},
{{60, 14}},
{{58, 14}},
{{56, 14}},
{{54, 14}},
{{62, 17}},
{{60, 17}},
{{58, 17}},
{{56, 17}},
{{54, 17}},
{{12,6},{30,11},{36,13}}, {{14,7},{18,11},{36,14}}, {{10,7},{60,13},{40,17}},
{{8,7},{42,13}}, {{14,8},{34,13}}, {{10,8},{34,14}}, {{78,9},{32,14}}, {{70,9},{52,17}}, {{68,9},{50,17}}, {{64,9},{48,17}}, {{28,11},{46,17}}, {{26,11},{44,17}}, {{16,11},{42,17}},
{{62,13}}, {{52,13}}, {{50,13}}, {{46,13}}, {{44,13}}, {{62,14}}, {{60,14}}, {{58,14}}, {{56,14}}, {{54,14}}, {{62,17}}, {{60,17}}, {{58,17}}, {{56,17}}, {{54,17}},
};
static const float s_jo_quantTbl[64] = {
0.015625f,
0.005632f,
0.005035f,
0.004832f,
0.004808f,
0.005892f,
0.007964f,
0.013325f,
0.005632f,
0.004061f,
0.003135f,
0.003193f,
0.003338f,
0.003955f,
0.004898f,
0.008828f,
0.005035f,
0.003135f,
0.002816f,
0.003013f,
0.003299f,
0.003581f,
0.005199f,
0.009125f,
0.004832f,
0.003484f,
0.003129f,
0.003348f,
0.003666f,
0.003979f,
0.005309f,
0.009632f,
0.005682f,
0.003466f,
0.003543f,
0.003666f,
0.003906f,
0.004546f,
0.005774f,
0.009439f,
0.006119f,
0.004248f,
0.004199f,
0.004228f,
0.004546f,
0.005062f,
0.006124f,
0.009942f,
0.008883f,
0.006167f,
0.006096f,
0.005777f,
0.006078f,
0.006391f,
0.007621f,
0.012133f,
0.016780f,
0.011263f,
0.009907f,
0.010139f,
0.009849f,
0.010297f,
0.012133f,
0.019785f,
0.015625f,0.005632f,0.005035f,0.004832f,0.004808f,0.005892f,0.007964f,0.013325f,
0.005632f,0.004061f,0.003135f,0.003193f,0.003338f,0.003955f,0.004898f,0.008828f,
0.005035f,0.003135f,0.002816f,0.003013f,0.003299f,0.003581f,0.005199f,0.009125f,
0.004832f,0.003484f,0.003129f,0.003348f,0.003666f,0.003979f,0.005309f,0.009632f,
0.005682f,0.003466f,0.003543f,0.003666f,0.003906f,0.004546f,0.005774f,0.009439f,
0.006119f,0.004248f,0.004199f,0.004228f,0.004546f,0.005062f,0.006124f,0.009942f,
0.008883f,0.006167f,0.006096f,0.005777f,0.006078f,0.006391f,0.007621f,0.012133f,
0.016780f,0.011263f,0.009907f,0.010139f,0.009849f,0.010297f,0.012133f,0.019785f,
};
static const unsigned char s_jo_ZigZag[] = { 0,1,5,6,14,15,27,28,2,4,7,13,16,26,29,42,3,8,12,17,25,30,41,43,9,11,18,24,31,40,44,53,10,19,23,32,39,45,52,54,20,22,33,38,46,51,55,60,21,34,37,47,50,56,59,61,35,36,48,49,57,58,62,63 };
typedef struct
{
typedef struct {
unsigned char *buf_ptr;
int buf, cnt;
} jo_bits_t;
static void jo_writeBits(jo_bits_t* b, int value, int count)
{
static void jo_writeBits(jo_bits_t *b, int value, int count) {
b->cnt += count;
b->buf |= value << (24 - b->cnt);
while (b->cnt >= 8)
{
while(b->cnt >= 8) {
unsigned char c = (b->buf >> 16) & 255;
//putc(c, b->fp);
*(b->buf_ptr) = c & 0xff;
@ -201,8 +76,7 @@ static void jo_writeBits(jo_bits_t* b, int value, int count)
}
}
static void jo_DCT(float* d0, float* d1, float* d2, float* d3, float* d4, float* d5, float* d6, float* d7)
{
static void jo_DCT(float *d0, float *d1, float *d2, float *d3, float *d4, float *d5, float *d6, float *d7) {
float tmp0 = *d0 + *d7;
float tmp7 = *d0 - *d7;
float tmp1 = *d1 + *d6;
@ -245,19 +119,15 @@ static void jo_DCT(float* d0, float* d1, float* d2, float* d3, float* d4, float*
*d7 = z11 - z4;
}
static int jo_processDU(jo_bits_t* bits, float A[64], const unsigned char htdc[9][2], int DC)
{
for (int dataOff = 0; dataOff < 64; dataOff += 8)
{
static int jo_processDU(jo_bits_t *bits, float A[64], const unsigned char htdc[9][2], int DC) {
for(int dataOff=0; dataOff<64; dataOff+=8) {
jo_DCT(&A[dataOff], &A[dataOff+1], &A[dataOff+2], &A[dataOff+3], &A[dataOff+4], &A[dataOff+5], &A[dataOff+6], &A[dataOff+7]);
}
for (int dataOff = 0; dataOff < 8; ++dataOff)
{
for(int dataOff=0; dataOff<8; ++dataOff) {
jo_DCT(&A[dataOff], &A[dataOff+8], &A[dataOff+16], &A[dataOff+24], &A[dataOff+32], &A[dataOff+40], &A[dataOff+48], &A[dataOff+56]);
}
int Q[64];
for (int i = 0; i < 64; ++i)
{
for(int i=0; i<64; ++i) {
float v = A[i]*s_jo_quantTbl[i];
Q[s_jo_ZigZag[i]] = (int)(v < 0 ? ceilf(v - 0.5f) : floorf(v + 0.5f));
}
@ -266,48 +136,36 @@ static int jo_processDU(jo_bits_t* bits, float A[64], const unsigned char htdc[9
int aDC = DC < 0 ? -DC : DC;
int size = 0;
int tempval = aDC;
while (tempval)
{
while(tempval) {
size++;
tempval >>= 1;
}
jo_writeBits(bits, htdc[size][0], htdc[size][1]);
if (DC < 0)
aDC ^= (1 << size) - 1;
if(DC < 0) aDC ^= (1 << size) - 1;
jo_writeBits(bits, aDC, size);
int endpos = 63;
for (; (endpos > 0) && (Q[endpos] == 0); --endpos)
{ /* do nothing */
}
for (int i = 1; i <= endpos;)
{
for(; (endpos>0)&&(Q[endpos]==0); --endpos) { /* do nothing */ }
for(int i = 1; i <= endpos;) {
int run = 0;
while (Q[i] == 0 && i < endpos)
{
while (Q[i]==0 && i<endpos) {
++run;
++i;
}
int AC = Q[i++];
int aAC = AC < 0 ? -AC : AC;
int code = 0, size = 0;
if (run < 32 && aAC <= 40)
{
if (run<32 && aAC<=40) {
code = s_jo_HTAC[run][aAC-1][0];
size = s_jo_HTAC[run][aAC-1][1];
if (AC < 0)
code += 1;
if (AC < 0) code += 1;
}
if (!size)
{
if(!size) {
jo_writeBits(bits, 1, 6);
jo_writeBits(bits, run, 6);
if (AC < -127)
{
if (AC < -127) {
jo_writeBits(bits, 128, 12);
}
else if (AC > 127)
{
} else if(AC > 127) {
jo_writeBits(bits, 0, 12);
}
code = AC & 0xFFF;
@ -320,23 +178,17 @@ static int jo_processDU(jo_bits_t* bits, float A[64], const unsigned char htdc[9
return Q[0];
}
unsigned long jo_write_mpeg(unsigned char* mpeg_buf, const unsigned char* raw, int width, int height, int format, int flipx, int flipy)
{
unsigned long jo_write_mpeg(unsigned char *mpeg_buf, const unsigned char *raw, int width, int height, int format, int flipx, int flipy) {
int lastDCY = 128, lastDCCR = 128, lastDCCB = 128;
unsigned char *head = mpeg_buf;
jo_bits_t bits = {mpeg_buf};
for (int vblock = 0; vblock < (height + 15) / 16; vblock++)
{
for (int hblock = 0; hblock < (width + 15) / 16; hblock++)
{
if (vblock == 0 && hblock == 0)
{
for (int vblock = 0; vblock < (height+15)/16; vblock++) {
for (int hblock = 0; hblock < (width+15)/16; hblock++) {
if (vblock == 0 && hblock == 0) {
jo_writeBits(&bits, 0b01, 2); // macroblock_type = intra+quant
jo_writeBits(&bits, 8, 5); // quantiser_scale_code = 8
}
else
{
} else {
jo_writeBits(&bits, 0b1, 1); // macroblock_address_increment
jo_writeBits(&bits, 0b1, 1); // macroblock_type = intra
}
@ -344,26 +196,19 @@ unsigned long jo_write_mpeg(unsigned char* mpeg_buf, const unsigned char* raw, i
float Y[256], CBx[256], CRx[256];
float CB[64], CR[64];
if (format == JO_RGBX)
{
for (int i = 0; i < 256; ++i)
{
if (format == JO_RGBX) {
for (int i=0; i<256; ++i) {
int y = vblock*16+(i/16);
int x = hblock*16+(i&15);
x = x >= width ? width-1 : x;
y = y >= height ? height-1 : y;
if (flipx)
x = width - 1 - x;
if (flipy)
y = height - 1 - y;
if (flipx) x = width - 1 - x;
if (flipy) y = height - 1 - y;
const unsigned char *c = raw + y*width*4+x*4;
float r, g, b;
if (flipx && flipy)
{
if (flipx && flipy) {
r = c[2], g = c[1], b = c[0];
}
else
{
} else {
r = c[0], g = c[1], b = c[2];
}
Y[i] = (0.299f*r + 0.587f*g + 0.114f*b) * (219.f/255) + 16;
@ -371,33 +216,25 @@ unsigned long jo_write_mpeg(unsigned char* mpeg_buf, const unsigned char* raw, i
CRx[i] = (0.701f*r - 0.587f*g - 0.114f*b) * (224.f/255) + 128;
}
// Downsample Cb,Cr (420 format)
for (int i = 0; i < 64; ++i)
{
for (int i=0; i<64; ++i) {
int j =(i&7)*2 + (i&56)*4;
CB[i] = (CBx[j] + CBx[j+1] + CBx[j+16] + CBx[j+17]) * 0.25f;
CR[i] = (CRx[j] + CRx[j+1] + CRx[j+16] + CRx[j+17]) * 0.25f;
}
}
else if (format == JO_RGB24)
{
for (int i = 0; i < 256; ++i)
{
} else
if (format == JO_RGB24) {
for (int i=0; i<256; ++i) {
int y = vblock*16+(i/16);
int x = hblock*16+(i&15);
x = x >= width ? width-1 : x;
y = y >= height ? height-1 : y;
if (flipx)
x = width - 1 - x;
if (flipy)
y = height - 1 - y;
if (flipx) x = width - 1 - x;
if (flipy) y = height - 1 - y;
const unsigned char *c = raw + y*width*3+x*3;
float r, g, b;
if (flipx && flipy)
{
if (flipx && flipy) {
r = c[2], g = c[1], b = c[0];
}
else
{
} else {
r = c[0], g = c[1], b = c[2];
}
Y[i] = (0.299f*r + 0.587f*g + 0.114f*b) * (219.f/255) + 16;
@ -405,35 +242,27 @@ unsigned long jo_write_mpeg(unsigned char* mpeg_buf, const unsigned char* raw, i
CRx[i] = (0.701f*r - 0.587f*g - 0.114f*b) * (224.f/255) + 128;
}
// Downsample Cb,Cr (420 format)
for (int i = 0; i < 64; ++i)
{
for (int i=0; i<64; ++i) {
int j =(i&7)*2 + (i&56)*4;
CB[i] = (CBx[j] + CBx[j+1] + CBx[j+16] + CBx[j+17]) * 0.25f;
CR[i] = (CRx[j] + CRx[j+1] + CRx[j+16] + CRx[j+17]) * 0.25f;
}
}
else if (format == JO_YUYV)
{
for (int i = 0; i < 256; i += 2)
{
} else
if (format == JO_YUYV) {
for (int i=0; i<256; i+=2) {
int y = vblock*16+(i/16);
int x = hblock*16+(i&15);
x = x >= width ? width-1 : x;
y = y >= height ? height-1 : y;
if (flipx)
x = width - 1 - x;
if (flipy)
y = height - 1 - y;
if (flipx) x = width - 1 - x;
if (flipy) y = height - 1 - y;
const unsigned char *c = raw + y*width*2+x*2-2;
if (flipx)
{
if (flipx) {
Y[i+1] = c[0];
CB[i/4] = c[1];
Y[i] = c[2];
CR[i/4] = c[3];
}
else
{
} else {
Y[i] = c[2];
CB[i/4] = c[3];
Y[i+1] = c[4];
@ -442,13 +271,10 @@ unsigned long jo_write_mpeg(unsigned char* mpeg_buf, const unsigned char* raw, i
}
}
for (int k1 = 0; k1 < 2; ++k1)
{
for (int k2 = 0; k2 < 2; ++k2)
{
for (int k1=0; k1<2; ++k1) {
for (int k2=0; k2<2; ++k2) {
float block[64];
for (int i = 0; i < 64; i += 8)
{
for (int i=0; i<64; i+=8) {
int j = (i&7)+(i&56)*2 + k1*8*16 + k2*8;
memcpy(block+i, Y+j, 8*sizeof(Y[0]));
}

View File

@ -1,31 +1,14 @@
/* PCSX2 - PS2 Emulator for PCs
* Copyright (C) 2002-2020 PCSX2 Dev Team
*
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with PCSX2.
* If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef __cplusplus
extern "C" {
#endif
typedef enum
{
typedef enum {
JO_RGBX,
JO_RGB24,
JO_YUYV,
} jo_mpeg_format_t;
typedef enum
{
typedef enum {
JO_NONE,
JO_FLIP_X,
JO_FLIP_Y,

View File

@ -57,8 +57,7 @@
#define JPGD_MAX(a,b) (((a)>(b)) ? (a) : (b))
#define JPGD_MIN(a,b) (((a)<(b)) ? (a) : (b))
namespace jpgd
{
namespace jpgd {
static inline void* jpgd_malloc(size_t nSize) { return malloc(nSize); }
static inline void jpgd_free(void* p) { free(p); }
@ -68,56 +67,14 @@ namespace jpgd
enum JPEG_MARKER
{
M_SOF0 = 0xC0,
M_SOF1 = 0xC1,
M_SOF2 = 0xC2,
M_SOF3 = 0xC3,
M_SOF5 = 0xC5,
M_SOF6 = 0xC6,
M_SOF7 = 0xC7,
M_JPG = 0xC8,
M_SOF9 = 0xC9,
M_SOF10 = 0xCA,
M_SOF11 = 0xCB,
M_SOF13 = 0xCD,
M_SOF14 = 0xCE,
M_SOF15 = 0xCF,
M_DHT = 0xC4,
M_DAC = 0xCC,
M_RST0 = 0xD0,
M_RST1 = 0xD1,
M_RST2 = 0xD2,
M_RST3 = 0xD3,
M_RST4 = 0xD4,
M_RST5 = 0xD5,
M_RST6 = 0xD6,
M_RST7 = 0xD7,
M_SOI = 0xD8,
M_EOI = 0xD9,
M_SOS = 0xDA,
M_DQT = 0xDB,
M_DNL = 0xDC,
M_DRI = 0xDD,
M_DHP = 0xDE,
M_EXP = 0xDF,
M_APP0 = 0xE0,
M_APP15 = 0xEF,
M_JPG0 = 0xF0,
M_JPG13 = 0xFD,
M_COM = 0xFE,
M_TEM = 0x01,
M_ERROR = 0x100,
RST0 = 0xD0
M_SOF0 = 0xC0, M_SOF1 = 0xC1, M_SOF2 = 0xC2, M_SOF3 = 0xC3, M_SOF5 = 0xC5, M_SOF6 = 0xC6, M_SOF7 = 0xC7, M_JPG = 0xC8,
M_SOF9 = 0xC9, M_SOF10 = 0xCA, M_SOF11 = 0xCB, M_SOF13 = 0xCD, M_SOF14 = 0xCE, M_SOF15 = 0xCF, M_DHT = 0xC4, M_DAC = 0xCC,
M_RST0 = 0xD0, M_RST1 = 0xD1, M_RST2 = 0xD2, M_RST3 = 0xD3, M_RST4 = 0xD4, M_RST5 = 0xD5, M_RST6 = 0xD6, M_RST7 = 0xD7,
M_SOI = 0xD8, M_EOI = 0xD9, M_SOS = 0xDA, M_DQT = 0xDB, M_DNL = 0xDC, M_DRI = 0xDD, M_DHP = 0xDE, M_EXP = 0xDF,
M_APP0 = 0xE0, M_APP15 = 0xEF, M_JPG0 = 0xF0, M_JPG13 = 0xFD, M_COM = 0xFE, M_TEM = 0x01, M_ERROR = 0x100, RST0 = 0xD0
};
enum JPEG_SUBSAMPLING
{
JPGD_GRAYSCALE = 0,
JPGD_YH1V1,
JPGD_YH2V1,
JPGD_YH1V2,
JPGD_YH2V2
};
enum JPEG_SUBSAMPLING { JPGD_GRAYSCALE = 0, JPGD_YH1V1, JPGD_YH2V1, JPGD_YH1V2, JPGD_YH2V2 };
#if JPGD_USE_SSE2
#include "jpgd_idct.h"
@ -308,524 +265,21 @@ namespace jpgd
static const uint8 s_idct_row_table[] =
{
1,
0,
0,
0,
0,
0,
0,
0,
2,
0,
0,
0,
0,
0,
0,
0,
2,
1,
0,
0,
0,
0,
0,
0,
2,
1,
1,
0,
0,
0,
0,
0,
2,
2,
1,
0,
0,
0,
0,
0,
3,
2,
1,
0,
0,
0,
0,
0,
4,
2,
1,
0,
0,
0,
0,
0,
4,
3,
1,
0,
0,
0,
0,
0,
4,
3,
2,
0,
0,
0,
0,
0,
4,
3,
2,
1,
0,
0,
0,
0,
4,
3,
2,
1,
1,
0,
0,
0,
4,
3,
2,
2,
1,
0,
0,
0,
4,
3,
3,
2,
1,
0,
0,
0,
4,
4,
3,
2,
1,
0,
0,
0,
5,
4,
3,
2,
1,
0,
0,
0,
6,
4,
3,
2,
1,
0,
0,
0,
6,
5,
3,
2,
1,
0,
0,
0,
6,
5,
4,
2,
1,
0,
0,
0,
6,
5,
4,
3,
1,
0,
0,
0,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, 8,8,8,8,8,7,6,5, 8,8,8,8,8,7,6,6, 8,8,8,8,8,7,7,6, 8,8,8,8,8,8,7,6, 8,8,8,8,8,8,8,6, 8,8,8,8,8,8,8,7, 8,8,8,8,8,8,8,8,
};
static const uint8 s_idct_col_table[] =
{
1, 1, 2, 3, 3, 3, 3, 3, 3, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8};
7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8
};
// Scalar "fast pathing" IDCT.
static void idct(const jpgd_block_coeff_t* pSrc_ptr, uint8* pDst_ptr, int block_max_zag, bool use_simd)
@ -872,33 +326,15 @@ namespace jpgd
{
switch (*pRow_tab)
{
case 0:
Row<0>::idct(pTemp, pSrc);
break;
case 1:
Row<1>::idct(pTemp, pSrc);
break;
case 2:
Row<2>::idct(pTemp, pSrc);
break;
case 3:
Row<3>::idct(pTemp, pSrc);
break;
case 4:
Row<4>::idct(pTemp, pSrc);
break;
case 5:
Row<5>::idct(pTemp, pSrc);
break;
case 6:
Row<6>::idct(pTemp, pSrc);
break;
case 7:
Row<7>::idct(pTemp, pSrc);
break;
case 8:
Row<8>::idct(pTemp, pSrc);
break;
case 0: Row<0>::idct(pTemp, pSrc); break;
case 1: Row<1>::idct(pTemp, pSrc); break;
case 2: Row<2>::idct(pTemp, pSrc); break;
case 3: Row<3>::idct(pTemp, pSrc); break;
case 4: Row<4>::idct(pTemp, pSrc); break;
case 5: Row<5>::idct(pTemp, pSrc); break;
case 6: Row<6>::idct(pTemp, pSrc); break;
case 7: Row<7>::idct(pTemp, pSrc); break;
case 8: Row<8>::idct(pTemp, pSrc); break;
}
pSrc += 8;
@ -912,30 +348,14 @@ namespace jpgd
{
switch (nonzero_rows)
{
case 1:
Col<1>::idct(pDst_ptr, pTemp);
break;
case 2:
Col<2>::idct(pDst_ptr, pTemp);
break;
case 3:
Col<3>::idct(pDst_ptr, pTemp);
break;
case 4:
Col<4>::idct(pDst_ptr, pTemp);
break;
case 5:
Col<5>::idct(pDst_ptr, pTemp);
break;
case 6:
Col<6>::idct(pDst_ptr, pTemp);
break;
case 7:
Col<7>::idct(pDst_ptr, pTemp);
break;
case 8:
Col<8>::idct(pDst_ptr, pTemp);
break;
case 1: Col<1>::idct(pDst_ptr, pTemp); break;
case 2: Col<2>::idct(pDst_ptr, pTemp); break;
case 3: Col<3>::idct(pDst_ptr, pTemp); break;
case 4: Col<4>::idct(pDst_ptr, pTemp); break;
case 5: Col<5>::idct(pDst_ptr, pTemp); break;
case 6: Col<6>::idct(pDst_ptr, pTemp); break;
case 7: Col<7>::idct(pDst_ptr, pTemp); break;
case 8: Col<8>::idct(pDst_ptr, pTemp); break;
}
pTemp++;
@ -1253,8 +673,7 @@ namespace jpgd
b->m_size = capacity;
rv = b->m_data;
}
if (zero)
memset(rv, 0, nSize);
if (zero) memset(rv, 0, nSize);
return rv;
}
@ -2056,11 +1475,7 @@ namespace jpgd
get_bits_no_markers(16);
}
static inline int dequantize_ac(int c, int q)
{
c *= q;
return c;
}
static inline int dequantize_ac(int c, int q) { c *= q; return c; }
// Decodes and dequantizes the next row of coefficients.
void jpeg_decoder::decode_next_row()
@ -2506,11 +1921,9 @@ namespace jpgd
static const uint8_t s_muls[2][2][4] =
{
{
{1, 3, 3, 9},
{3, 9, 1, 3},
},
{{3, 1, 9, 3}, {9, 3, 3, 1}}};
{ { 1, 3, 3, 9 }, { 3, 9, 1, 3 }, },
{ { 3, 1, 9, 3 }, { 9, 3, 3, 1 } }
};
if (((row & 15) >= 1) && ((row & 15) <= 14))
{

View File

@ -40,42 +40,15 @@ namespace jpgd
// Success/failure error codes.
enum jpgd_status
{
JPGD_SUCCESS = 0,
JPGD_FAILED = -1,
JPGD_DONE = 1,
JPGD_BAD_DHT_COUNTS = -256,
JPGD_BAD_DHT_INDEX,
JPGD_BAD_DHT_MARKER,
JPGD_BAD_DQT_MARKER,
JPGD_BAD_DQT_TABLE,
JPGD_BAD_PRECISION,
JPGD_BAD_HEIGHT,
JPGD_BAD_WIDTH,
JPGD_TOO_MANY_COMPONENTS,
JPGD_BAD_SOF_LENGTH,
JPGD_BAD_VARIABLE_MARKER,
JPGD_BAD_DRI_LENGTH,
JPGD_BAD_SOS_LENGTH,
JPGD_BAD_SOS_COMP_ID,
JPGD_W_EXTRA_BYTES_BEFORE_MARKER,
JPGD_NO_ARITHMITIC_SUPPORT,
JPGD_UNEXPECTED_MARKER,
JPGD_NOT_JPEG,
JPGD_UNSUPPORTED_MARKER,
JPGD_BAD_DQT_LENGTH,
JPGD_TOO_MANY_BLOCKS,
JPGD_UNDEFINED_QUANT_TABLE,
JPGD_UNDEFINED_HUFF_TABLE,
JPGD_NOT_SINGLE_SCAN,
JPGD_UNSUPPORTED_COLORSPACE,
JPGD_UNSUPPORTED_SAMP_FACTORS,
JPGD_DECODE_ERROR,
JPGD_BAD_RESTART_MARKER,
JPGD_BAD_SOS_SPECTRAL,
JPGD_BAD_SOS_SUCCESSIVE,
JPGD_STREAM_READ,
JPGD_NOTENOUGHMEM,
JPGD_TOO_MANY_SCANS
JPGD_SUCCESS = 0, JPGD_FAILED = -1, JPGD_DONE = 1,
JPGD_BAD_DHT_COUNTS = -256, JPGD_BAD_DHT_INDEX, JPGD_BAD_DHT_MARKER, JPGD_BAD_DQT_MARKER, JPGD_BAD_DQT_TABLE,
JPGD_BAD_PRECISION, JPGD_BAD_HEIGHT, JPGD_BAD_WIDTH, JPGD_TOO_MANY_COMPONENTS,
JPGD_BAD_SOF_LENGTH, JPGD_BAD_VARIABLE_MARKER, JPGD_BAD_DRI_LENGTH, JPGD_BAD_SOS_LENGTH,
JPGD_BAD_SOS_COMP_ID, JPGD_W_EXTRA_BYTES_BEFORE_MARKER, JPGD_NO_ARITHMITIC_SUPPORT, JPGD_UNEXPECTED_MARKER,
JPGD_NOT_JPEG, JPGD_UNSUPPORTED_MARKER, JPGD_BAD_DQT_LENGTH, JPGD_TOO_MANY_BLOCKS,
JPGD_UNDEFINED_QUANT_TABLE, JPGD_UNDEFINED_HUFF_TABLE, JPGD_NOT_SINGLE_SCAN, JPGD_UNSUPPORTED_COLORSPACE,
JPGD_UNSUPPORTED_SAMP_FACTORS, JPGD_DECODE_ERROR, JPGD_BAD_RESTART_MARKER,
JPGD_BAD_SOS_SPECTRAL, JPGD_BAD_SOS_SUCCESSIVE, JPGD_STREAM_READ, JPGD_NOTENOUGHMEM, JPGD_TOO_MANY_SCANS
};
// Input stream interface.
@ -125,28 +98,13 @@ namespace jpgd
uint m_ofs, m_size;
public:
jpeg_decoder_mem_stream()
: m_pSrc_data(NULL)
, m_ofs(0)
, m_size(0)
{
}
jpeg_decoder_mem_stream(const uint8* pSrc_data, uint size)
: m_pSrc_data(pSrc_data)
, m_ofs(0)
, m_size(size)
{
}
jpeg_decoder_mem_stream() : m_pSrc_data(NULL), m_ofs(0), m_size(0) { }
jpeg_decoder_mem_stream(const uint8* pSrc_data, uint size) : m_pSrc_data(pSrc_data), m_ofs(0), m_size(size) { }
virtual ~jpeg_decoder_mem_stream() { }
bool open(const uint8* pSrc_data, uint size);
void close()
{
m_pSrc_data = NULL;
m_ofs = 0;
m_size = 0;
}
void close() { m_pSrc_data = NULL; m_ofs = 0; m_size = 0; }
virtual int read(uint8* pBuf, int max_bytes_to_read, bool* pEOF_flag);
};
@ -156,15 +114,8 @@ namespace jpgd
enum
{
JPGD_IN_BUF_SIZE = 8192,
JPGD_MAX_BLOCKS_PER_MCU = 10,
JPGD_MAX_HUFF_TABLES = 8,
JPGD_MAX_QUANT_TABLES = 4,
JPGD_MAX_COMPONENTS = 4,
JPGD_MAX_COMPS_IN_SCAN = 4,
JPGD_MAX_BLOCKS_PER_ROW = 16384,
JPGD_MAX_HEIGHT = 32768,
JPGD_MAX_WIDTH = 32768
JPGD_IN_BUF_SIZE = 8192, JPGD_MAX_BLOCKS_PER_MCU = 10, JPGD_MAX_HUFF_TABLES = 8, JPGD_MAX_QUANT_TABLES = 4,
JPGD_MAX_COMPONENTS = 4, JPGD_MAX_COMPS_IN_SCAN = 4, JPGD_MAX_BLOCKS_PER_ROW = 16384, JPGD_MAX_HEIGHT = 32768, JPGD_MAX_WIDTH = 32768
};
typedef int16 jpgd_quant_t;
@ -324,12 +275,7 @@ namespace jpgd
bool m_sample_buf_prev_valid;
bool m_has_sse2;
inline int check_sample_buf_ofs(int ofs) const
{
assert(ofs >= 0);
assert(ofs < m_max_blocks_per_row * 64);
return ofs;
}
inline int check_sample_buf_ofs(int ofs) const { assert(ofs >= 0); assert(ofs < m_max_blocks_per_row * 64); return ofs; }
void free_all_blocks();
JPGD_NORETURN void stop_decoding(jpgd_status status);
void* alloc(size_t n, bool zero = false);