mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
Optimized grayscale and binary for SW encoder
This commit is contained in:
parent
f561bd686d
commit
8aa56c7ebf
@ -22,6 +22,11 @@
|
|||||||
|
|
||||||
#define TIME_JPEG (0)
|
#define TIME_JPEG (0)
|
||||||
|
|
||||||
|
// Expand 4 bits to 32 for binary to grayscale; process 4 pixels at a time
|
||||||
|
const uint32_t u32Expand[16] = {0x0, 0xff, 0xff00, 0xffff, 0xff0000,
|
||||||
|
0xff00ff, 0xffff00, 0xffffff, 0xff000000, 0xff0000ff, 0xff00ff00,
|
||||||
|
0xff00ffff, 0xffff0000, 0xffff00ff, 0xffffff00, 0xffffffff};
|
||||||
|
|
||||||
#if (OMV_HARDWARE_JPEG == 1)
|
#if (OMV_HARDWARE_JPEG == 1)
|
||||||
|
|
||||||
#define MCU_W (8)
|
#define MCU_W (8)
|
||||||
@ -58,10 +63,6 @@ static uint8_t *get_mcu()
|
|||||||
uint8_t *CR = mcubuf + 128;
|
uint8_t *CR = mcubuf + 128;
|
||||||
int r, g, b; // to separate RGB565 into R8,G8,B8
|
int r, g, b; // to separate RGB565 into R8,G8,B8
|
||||||
int dx=MCU_W, dy=MCU_H; // width and height of MCU can be truncated if we're at bottom or right edge
|
int dx=MCU_W, dy=MCU_H; // width and height of MCU can be truncated if we're at bottom or right edge
|
||||||
// Expand 4 bits to 32 for binary to grayscale; process 4 pixels at a time
|
|
||||||
const uint32_t u32Expand[16] = {0x0, 0xff, 0xff00, 0xffff, 0xff0000,
|
|
||||||
0xff00ff, 0xffff00, 0xffffff, 0xff000000, 0xff0000ff, 0xff00ff00,
|
|
||||||
0xff00ffff, 0xffff0000, 0xffff00ff, 0xffffff00, 0xffffffff};
|
|
||||||
|
|
||||||
// Copy 8x8 MCUs
|
// Copy 8x8 MCUs
|
||||||
switch (jpeg_enc.img_bpp) {
|
switch (jpeg_enc.img_bpp) {
|
||||||
@ -805,6 +806,7 @@ void jpeg_get_mcu(image_t *img, int mcu_w, int mcu_h, int x_offs, int y_offs, in
|
|||||||
switch (bpp) {
|
switch (bpp) {
|
||||||
case 0: {
|
case 0: {
|
||||||
uint8_t *mcu = (uint8_t*) buf;
|
uint8_t *mcu = (uint8_t*) buf;
|
||||||
|
if (y_offs+mcu_h > img->h || x_offs+mcu_w > img->w) { // clipped
|
||||||
for (int y=y_offs; y<y_offs+mcu_h; y++) {
|
for (int y=y_offs; y<y_offs+mcu_h; y++) {
|
||||||
for (int x=x_offs; x<x_offs+mcu_w; x++) {
|
for (int x=x_offs; x<x_offs+mcu_w; x++) {
|
||||||
if (x >= img->w || y >= img->h) {
|
if (x >= img->w || y >= img->h) {
|
||||||
@ -814,11 +816,26 @@ void jpeg_get_mcu(image_t *img, int mcu_w, int mcu_h, int x_offs, int y_offs, in
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} // clipped
|
||||||
|
else {
|
||||||
|
int iPitch = ((img->w + 31) >> 3) & 0xfffc; // dword align
|
||||||
|
uint8_t u8Pixels;
|
||||||
|
uint32_t *d32 = (uint32_t *)mcu;
|
||||||
|
for (int y=y_offs; y<(y_offs + 8); y++) {
|
||||||
|
// read 8 binary pixels in one shot
|
||||||
|
int index = (y * iPitch) + (x_offs>>3); // get byte offset
|
||||||
|
uint8_t *s = &img->data[index];
|
||||||
|
u8Pixels = s[0]; // get 8 binary pixels (1 byte)
|
||||||
|
*d32++ = u32Expand[u8Pixels & 0xf]; // first 4 pixels
|
||||||
|
*d32++ = u32Expand[u8Pixels >> 4]; // second 4 pixels
|
||||||
|
} // for y
|
||||||
|
} // not clipped
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 1: {
|
case 1: {
|
||||||
uint8_t *mcu = (uint8_t*) buf;
|
uint8_t *mcu = (uint8_t*) buf;
|
||||||
//memset(mcu, 0, 64);
|
//memset(mcu, 0, 64);
|
||||||
|
if (y_offs+mcu_h > img->h || x_offs+mcu_w > img->w) { // truncated MCU
|
||||||
for (int y=y_offs; y<y_offs+mcu_h; y++) {
|
for (int y=y_offs; y<y_offs+mcu_h; y++) {
|
||||||
for (int x=x_offs; x<x_offs+mcu_w; x++) {
|
for (int x=x_offs; x<x_offs+mcu_w; x++) {
|
||||||
if (x >= img->w || y >= img->h) {
|
if (x >= img->w || y >= img->h) {
|
||||||
@ -828,6 +845,16 @@ void jpeg_get_mcu(image_t *img, int mcu_w, int mcu_h, int x_offs, int y_offs, in
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} // needs to be clipped
|
||||||
|
else // no need to check bounds per pixel
|
||||||
|
{
|
||||||
|
for (int y=y_offs; y<y_offs+mcu_h; y++) {
|
||||||
|
uint8_t *pRow = &img->data[(y * img->w) + x_offs];
|
||||||
|
for (int x=x_offs; x<x_offs+mcu_w; x++) {
|
||||||
|
*mcu++ = *pRow++ - 128;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 2: {
|
case 2: {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user