JPEGDEC: Use 4-bit dither.
This commit is contained in:
parent
62818a5f49
commit
d2b065d2da
|
@ -188,11 +188,14 @@ int JPEGDEC::decode(int x, int y, int iOptions)
|
||||||
_jpeg.iXOffset = x;
|
_jpeg.iXOffset = x;
|
||||||
_jpeg.iYOffset = y;
|
_jpeg.iYOffset = y;
|
||||||
_jpeg.iOptions = iOptions;
|
_jpeg.iOptions = iOptions;
|
||||||
|
_jpeg.pDitherBuffer = nullptr;
|
||||||
return DecodeJPEG(&_jpeg);
|
return DecodeJPEG(&_jpeg);
|
||||||
} /* decode() */
|
} /* decode() */
|
||||||
|
|
||||||
int JPEGDEC::decodeDither(uint8_t *pDither, int iOptions)
|
int JPEGDEC::decodeDither(int x, int y, uint8_t *pDither, int iOptions)
|
||||||
{
|
{
|
||||||
|
_jpeg.iXOffset = x;
|
||||||
|
_jpeg.iYOffset = y;
|
||||||
_jpeg.iOptions = iOptions;
|
_jpeg.iOptions = iOptions;
|
||||||
_jpeg.pDitherBuffer = pDither;
|
_jpeg.pDitherBuffer = pDither;
|
||||||
return DecodeJPEG(&_jpeg);
|
return DecodeJPEG(&_jpeg);
|
||||||
|
|
|
@ -213,7 +213,7 @@ class JPEGDEC
|
||||||
#endif
|
#endif
|
||||||
void close();
|
void close();
|
||||||
int decode(int x, int y, int iOptions);
|
int decode(int x, int y, int iOptions);
|
||||||
int decodeDither(uint8_t *pDither, int iOptions);
|
int decodeDither(int x, int y, uint8_t *pDither, int iOptions);
|
||||||
int getOrientation();
|
int getOrientation();
|
||||||
int getWidth();
|
int getWidth();
|
||||||
int getHeight();
|
int getHeight();
|
||||||
|
|
|
@ -38,7 +38,7 @@ int JPEGDraw(JPEGDRAW *pDraw) {
|
||||||
for(int x = 0; x < pDraw->iWidth; x++) {
|
for(int x = 0; x < pDraw->iWidth; x++) {
|
||||||
int i = y * pDraw->iWidth + x;
|
int i = y * pDraw->iWidth + x;
|
||||||
uint8_t p = pixels[i / 2];
|
uint8_t p = pixels[i / 2];
|
||||||
p >>= (i & 0b1) * 4;
|
p >>= (i & 0b1) ? 0 : 4;
|
||||||
p &= 0xf;
|
p &= 0xf;
|
||||||
current_graphics->set_pen(p);
|
current_graphics->set_pen(p);
|
||||||
current_graphics->pixel({pDraw->x + x, pDraw->y + y});
|
current_graphics->pixel({pDraw->x + x, pDraw->y + y});
|
||||||
|
@ -108,7 +108,7 @@ static int _open(_JPEG_obj_t *self, void *buf, size_t len) {
|
||||||
break;
|
break;
|
||||||
// TODO currently uses EIGHT_BIT_GREYSCALE and shifts down should this use a 4-bit dither?
|
// TODO currently uses EIGHT_BIT_GREYSCALE and shifts down should this use a 4-bit dither?
|
||||||
case PicoGraphics::PEN_P4:
|
case PicoGraphics::PEN_P4:
|
||||||
self->jpeg->setPixelType(EIGHT_BIT_GRAYSCALE);
|
self->jpeg->setPixelType(FOUR_BIT_DITHERED);
|
||||||
break;
|
break;
|
||||||
// TODO 2-bit is currently unsupported
|
// TODO 2-bit is currently unsupported
|
||||||
case PicoGraphics::PEN_P2:
|
case PicoGraphics::PEN_P2:
|
||||||
|
@ -174,7 +174,15 @@ mp_obj_t _JPEG_decode(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args
|
||||||
// We need to store a pointer to the PicoGraphics surface
|
// We need to store a pointer to the PicoGraphics surface
|
||||||
// since the JPEGDRAW struct has no userdata
|
// since the JPEGDRAW struct has no userdata
|
||||||
current_graphics = self->graphics->graphics;
|
current_graphics = self->graphics->graphics;
|
||||||
int result = self->jpeg->decode(x, y, f);
|
int result = -1;
|
||||||
|
|
||||||
|
if(self->graphics->graphics->pen_type == PicoGraphics::PEN_P4) {
|
||||||
|
uint8_t *buf = new uint8_t[1024];
|
||||||
|
result = self->jpeg->decodeDither(x, y, buf, f);
|
||||||
|
delete[] buf;
|
||||||
|
} else {
|
||||||
|
result = self->jpeg->decode(x, y, f);
|
||||||
|
}
|
||||||
current_graphics = nullptr;
|
current_graphics = nullptr;
|
||||||
return result == 1 ? mp_const_true : mp_const_false;
|
return result == 1 ? mp_const_true : mp_const_false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue