| 443 | } |
| 444 | |
| 445 | bool FileOp::operateLoadTryFormat(IFileOpProgress* progress) |
| 446 | { |
| 447 | if (!isSequence() || !m_format->support(FILE_SUPPORT_SEQUENCES)) { |
| 448 | // Direct load from one file. |
| 449 | return m_format->load(this); |
| 450 | } |
| 451 | |
| 452 | // Load a sequence |
| 453 | // Default palette |
| 454 | m_seq.palette->makeBlack(); |
| 455 | |
| 456 | // Load the sequence |
| 457 | frame_t frames(m_seq.filename_list.size()); |
| 458 | frame_t frame(0); |
| 459 | Image* old_image = nullptr; |
| 460 | |
| 461 | // TODO set_palette for each frame??? |
| 462 | auto add_image = [&]() { |
| 463 | m_seq.last_cel->data()->setImage(m_seq.image); |
| 464 | m_seq.layer->addCel(m_seq.last_cel); |
| 465 | |
| 466 | if (m_document->sprite()->palette(frame) |
| 467 | ->countDiff(*m_seq.palette, NULL, NULL) > 0) { |
| 468 | m_seq.palette->setFrame(frame); |
| 469 | m_document->sprite()->setPalette(*m_seq.palette, true); |
| 470 | } |
| 471 | |
| 472 | old_image = m_seq.image.get(); |
| 473 | m_seq.image.reset(); |
| 474 | m_seq.last_cel = NULL; |
| 475 | }; |
| 476 | |
| 477 | m_seq.has_alpha = false; |
| 478 | m_seq.progress_offset = 0.0f; |
| 479 | m_seq.progress_fraction = 1.0f / (double)frames; |
| 480 | |
| 481 | auto it = m_seq.filename_list.begin(), |
| 482 | end = m_seq.filename_list.end(); |
| 483 | for (; it != end; ++it) { |
| 484 | m_filename = it->c_str(); |
| 485 | |
| 486 | // Call the "load" procedure to read the first bitmap. |
| 487 | bool loadres = m_format->load(this); |
| 488 | if (!loadres) { |
| 489 | setError("Error loading frame %d from file \"%s\"\n", frame+1, m_filename.c_str()); |
| 490 | } |
| 491 | |
| 492 | // For the first frame... |
| 493 | if (!old_image) { |
| 494 | // Error reading the first frame |
| 495 | if (!loadres || !m_document || !m_seq.last_cel) { |
| 496 | m_seq.image.reset(); |
| 497 | delete m_document; |
| 498 | m_document = nullptr; |
| 499 | break; |
| 500 | } |
| 501 | // Read ok |
| 502 | else { |
nothing calls this directly
no test coverage detected