FastLED 3.9.15
Loading...
Searching...
No Matches

◆ mcu_load()

static JRESULT fl::third_party::mcu_load ( JDEC * jd)
static

Definition at line 711 of file tjpgd.cpp.hpp.

714{
715 int32_t *tmp = (int32_t*)jd->workbuf; /* Block working buffer for de-quantize and IDCT */
716 int d, e;
717 unsigned int blk, nby, i, bc, z, id, cmp;
718 jd_yuv_t *bp;
719 const int32_t *dqf;
720
721
722 nby = jd->msx * jd->msy; /* Number of Y blocks (1, 2 or 4) */
723 bp = jd->mcubuf; /* Pointer to the first block of MCU */
724
725 for (blk = 0; blk < nby + 2; blk++) { /* Get nby Y blocks and two C blocks */
726 cmp = (blk < nby) ? 0 : blk - nby + 1; /* Component number 0:Y, 1:Cb, 2:Cr */
727
728 if (cmp && jd->ncomp != 3) { /* Clear C blocks if not exist (monochrome image) */
729 for (i = 0; i < 64; bp[i++] = 128) ;
730
731 } else { /* Load Y/C blocks from input stream */
732 id = cmp ? 1 : 0; /* Huffman table ID of this component */
733
734 /* Extract a DC element from input stream */
735 d = huffext(jd, id, 0); /* Extract a huffman coded data (bit length) */
736 if (d < 0) return (JRESULT)(0 - d); /* Err: invalid code or input */
737 bc = (unsigned int)d;
738 d = jd->dcv[cmp]; /* DC value of previous block */
739 if (bc) { /* If there is any difference from previous block */
740 e = bitext(jd, bc); /* Extract data bits */
741 if (e < 0) return (JRESULT)(0 - e); /* Err: input */
742 bc = 1 << (bc - 1); /* MSB position */
743 if (!(e & bc)) e -= (bc << 1) - 1; /* Restore negative value if needed */
744 d += e; /* Get current value */
745 jd->dcv[cmp] = (int16_t)d; /* Save current DC value for next block */
746 }
747 dqf = jd->qttbl[jd->qtid[cmp]]; /* De-quantizer table ID for this component */
748 tmp[0] = d * dqf[0] >> 8; /* De-quantize, apply scale factor of Arai algorithm and descale 8 bits */
749
750 /* Extract following 63 AC elements from input stream */
751 fl::memset(&tmp[1], 0, 63 * sizeof (int32_t)); /* Initialize all AC elements */
752 z = 1; /* Top of the AC elements (in zigzag-order) */
753 do {
754 d = huffext(jd, id, 1); /* Extract a huffman coded value (zero runs and bit length) */
755 if (d == 0) break; /* EOB? */
756 if (d < 0) return (JRESULT)(0 - d); /* Err: invalid code or input error */
757 bc = (unsigned int)d;
758 z += bc >> 4; /* Skip leading zero run */
759 if (z >= 64) return JDR_FMT1; /* Too long zero run */
760 if (bc &= 0x0F) { /* Bit length? */
761 d = bitext(jd, bc); /* Extract data bits */
762 if (d < 0) return (JRESULT)(0 - d); /* Err: input device */
763 bc = 1 << (bc - 1); /* MSB position */
764 if (!(d & bc)) d -= (bc << 1) - 1; /* Restore negative value if needed */
765 i = Zig[z]; /* Get raster-order index */
766 tmp[i] = d * dqf[i] >> 8; /* De-quantize, apply scale factor of Arai algorithm and descale 8 bits */
767 }
768 } while (++z < 64); /* Next AC element */
769
770 if (JD_FORMAT != 2 || !cmp) { /* C components may not be processed if in grayscale output */
771 if (z == 1 || (JD_USE_SCALE && jd->scale == 3)) { /* If no AC element or scale ratio is 1/8, IDCT can be ommited and the block is filled with DC value */
772 d = (jd_yuv_t)((*tmp / 256) + 128);
773 if (JD_FASTDECODE >= 1) {
774 for (i = 0; i < 64; bp[i++] = d) ;
775 } else {
776 fl::memset(bp, d, 64);
777 }
778 } else {
779 block_idct(tmp, bp); /* Apply IDCT and store the block to the MCU buffer */
780 }
781 }
782 }
783
784 bp += 64; /* Next block */
785 }
786
787 return JDR_OK; /* All blocks have been loaded successfully */
788}
uint32_t z[NUM_LAYERS]
Definition Fire2023.h:93
static void block_idct(int32_t *src, jd_yuv_t *dst) FL_NOEXCEPT
static int bitext(JDEC *jd, unsigned int nbit) FL_NOEXCEPT
static const uint8_t Zig[64]
Definition tjpgd.cpp.hpp:50
fl::i32 int32_t
Definition coder.h:220
static int huffext(JDEC *jd, unsigned int id, unsigned int cls) FL_NOEXCEPT
uint8_t jd_yuv_t
Definition tjpgd.h:19
uint8_t qtid[3]
Definition tjpgd.h:57
jd_yuv_t * mcubuf
Definition tjpgd.h:76
int16_t dcv[3]
Definition tjpgd.h:59
int32_t * qttbl[4]
Definition tjpgd.h:65
fl::i16 int16_t
Definition s16x16x4.h:215
void * memset(void *s, int c, size_t n) FL_NOEXCEPT
#define JD_FORMAT
Definition tjpgdcnf.h:8
#define JD_FASTDECODE
Definition tjpgdcnf.h:27
#define JD_USE_SCALE
Definition tjpgdcnf.h:15

References bitext(), block_idct(), FL_NOEXCEPT, huffext(), JD_FASTDECODE, JD_FORMAT, JD_USE_SCALE, JDR_FMT1, JDR_OK, fl::memset(), z, and Zig.

Referenced by jd_decomp(), and jd_decomp_progressive().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: