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

◆ outputCallback()

int fl::third_party::TJpgInstanceDecoder::outputCallback ( JDEC * jd,
void * bitmap,
JRECT * rect )
staticprivate

Definition at line 317 of file driver.cpp.hpp.

317 {
318
319 EmbeddedTJpgState* state = reinterpret_cast<EmbeddedTJpgState*>(jd->device);
320
321 if (!state || !state->decoder_instance) {
322 return 0;
323 }
324
325 TJpgInstanceDecoder* decoder = state->decoder_instance;
326
327 if (!decoder->current_frame_) {
328 return 0;
329 }
330
331 fl::u16 frame_width = decoder->current_frame_->getWidth();
332 fl::u16 frame_height = decoder->current_frame_->getHeight();
333
334 // Calculate rectangle dimensions
335 fl::u16 x = rect->left;
336 fl::u16 y = rect->top;
337 fl::u16 w = rect->right - rect->left + 1; // JRECT is inclusive
338 fl::u16 h = rect->bottom - rect->top + 1; // JRECT is inclusive
339
340
341 // Handle zero-size rectangle by treating it as full frame for small images
342 if (w == 0 && h == 0 && frame_width <= 8 && frame_height <= 8) {
343 x = 0;
344 y = 0;
345 w = frame_width;
346 h = frame_height;
347 }
348
349 // Bounds check
350 if (x >= frame_width || y >= frame_height ||
351 x + w > frame_width || y + h > frame_height) {
352 return 0;
353 }
354
355 // Get pointer to frame's RGB buffer
356 CRGB* frame_pixels = decoder->current_frame_->rgb().data();
357 if (!frame_pixels) {
358 return 0;
359 }
360
361 // Copy pixels (already in RGB888 format since JD_FORMAT=0)
362 fl::u8* rgb_data = reinterpret_cast<fl::u8*>(bitmap);
363
364 for (fl::u16 row = 0; row < h; ++row) {
365 for (fl::u16 col = 0; col < w; ++col) {
366 fl::u16 src_idx = (row * w + col) * 3; // RGB888 is 3 bytes per pixel
367
368 // Calculate destination position
369 int pixel_x = x + col;
370 int pixel_y = y + row;
371 int frame_idx = pixel_y * frame_width + pixel_x;
372
373 // Get RGB888 values directly
374 fl::u8 r = rgb_data[src_idx + 0];
375 fl::u8 g = rgb_data[src_idx + 1];
376 fl::u8 b = rgb_data[src_idx + 2];
377
378 // Set pixel in frame buffer
379 frame_pixels[frame_idx] = CRGB(r, g, b);
380 }
381 }
382
383 return 1; // Success
384}
TestState state
unsigned char u8
Definition coder.h:132
fl::CRGB CRGB
Definition video.h:15

References TJpgInstanceDecoder(), current_frame_, FL_NOEXCEPT, state, fl::x, and fl::y.

Referenced by processChunk().

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