396 if (frame_start < 0 || frame_start >=
getNFrames() ||
397 frame_end < frame_start || frame_end >=
getNFrames())
399 std::cerr <<
"EERRenderer::renderFrames(frame_start = " << frame_start <<
", frame_end = " << frame_end <<
"), NFrames = " <<
getNFrames() << std::endl;
403 long long total_n_electron = 0;
405 std::vector<unsigned int> positions;
406 std::vector<unsigned char> symbols;
409 for (
int iframe = frame_start; iframe <= frame_end; iframe++)
411 RCTIC(TIMING_UNPACK_RLE);
412 if ((preread_start > 0 && iframe < preread_start) ||
413 (preread_end > 0 && iframe > preread_end))
415 std::cerr <<
"EERRenderer::renderFrames(frame_start = " << frame_start + 1 <<
", frame_end = " << frame_end + 1<<
"), NFrames = " <<
getNFrames() <<
" preread_start = " << preread_start + 1 <<
" prered_end = " << preread_end + 1<< std::endl;
419 long long pos = frame_starts[iframe];
420 unsigned int n_pix = 0, n_electron = 0;
421 const int max_electrons = frame_sizes[iframe] * 2;
422 if (positions.size() < max_electrons)
424 positions.resize(max_electrons);
425 symbols.resize(max_electrons);
430 unsigned int bit_pos = 0;
440 long long first_byte = pos + (bit_pos >> 3);
441 const unsigned int bit_offset_in_first_byte = bit_pos & 7;
442 const unsigned int chunk = (*(
unsigned int*)(buf + first_byte)) >> bit_offset_in_first_byte;
444 p = (
unsigned char)(chunk & 127);
447 if (n_pix >= EER_IMAGE_PIXELS)
break;
448 if (p == 127)
continue;
450 s = (
unsigned char)((chunk >> 7) & 15) ^ 0x0A;
452 positions[n_electron] = n_pix;
453 symbols[n_electron] = s;
457 p = (
unsigned char)((chunk >> 11) & 127);
460 if (n_pix >= EER_IMAGE_PIXELS)
break;
461 if (p == 127)
continue;
463 s = (
unsigned char)((chunk >> 18) & 15) ^ 0x0A;
465 positions[n_electron] = n_pix;
466 symbols[n_electron] = s;
476 unsigned char p1, p2, s1, s2;
478 const long long pos_limit = frame_starts[iframe] + frame_sizes[iframe];
480 while (pos < pos_limit)
484 s1 = (buf[pos + 1] & 0x0F) ^ 0x0A;
486 p2 = (buf[pos + 1] >> 4) | (buf[pos + 2] << 4);
487 s2 = (buf[pos + 2] >> 4) ^ 0x0A;
491 if (n_pix >= EER_IMAGE_PIXELS)
break;
494 positions[n_electron] = n_pix;
495 symbols[n_electron] = s1;
501 if (n_pix >= EER_IMAGE_PIXELS)
break;
504 positions[n_electron] = n_pix;
505 symbols[n_electron] = s2;
509 #ifdef DEBUG_EER_DETAIL 510 printf(
"%d: %u %u, %u %u %d\n", pos, p1, s1, p2, s2, n_pix);
516 if (n_pix != EER_IMAGE_PIXELS)
518 std::cerr <<
"WARNING: The number of pixels is not right in " + fn_movie +
" frame " +
integerToString(iframe + 1) +
". Probably this frame is corrupted. This frame is skipped." << std::endl;
522 RCTOC(TIMING_UNPACK_RLE);
524 RCTIC(TIMING_RENDER_ELECTRONS);
525 if (eer_upsampling == 3)
526 render16K(image, positions, symbols, n_electron);
527 else if (eer_upsampling == 2)
528 render8K(image, positions, symbols, n_electron);
529 else if (eer_upsampling == 1)
530 render4K(image, positions, symbols, n_electron);
533 RCTOC(TIMING_RENDER_ELECTRONS);
535 total_n_electron += n_electron;
537 printf(
"Decoded %lld electrons / %d pixels from frame %5d.\n", n_electron, n_pix, iframe);
541 printf(
"Decoded %lld electrons in total.\n", total_n_electron);
545 EERtimer.printTimes(
false);
548 return total_n_electron;
#define REPORT_ERROR(nerr, ErrormMsg)
String integerToString(int I, int _width, char fill_with)
void initZeros(const MultidimArray< T1 > &op)
Some logical error in the pipeline.