Skip to content

Commit

Permalink
use pict bounds from subheader if present
Browse files Browse the repository at this point in the history
  • Loading branch information
fuzziqersoftware committed Jul 5, 2023
1 parent ee22d63 commit 7668295
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 27 deletions.
37 changes: 22 additions & 15 deletions src/QuickDrawEngine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,23 @@ static const ColorTable& get_color_table(StringReader& r) {
}

struct PictSubheaderV2 {
be_int32_t version; // == -1
Fixed bounds_x1;
Fixed bounds_y1;
Fixed bounds_x2;
Fixed bounds_y2;
be_uint32_t reserved2;
/* 00 */ be_int32_t version; // == -1
/* 04 */ Fixed bounds_x1;
/* 08 */ Fixed bounds_y1;
/* 0C */ Fixed bounds_x2;
/* 10 */ Fixed bounds_y2;
/* 14 */ be_uint32_t reserved2;
/* 18 */
} __attribute__((packed));

struct PictSubheaderV2Extended {
be_int16_t version; // == -2
be_uint16_t reserved1;
Fixed horizontal_resolution_dpi;
Fixed vertical_resolution_dpi;
Rect source_rect;
be_uint16_t reserved2;
/* 00 */ be_int16_t version; // == -2
/* 02 */ be_uint16_t reserved1;
/* 04 */ Fixed horizontal_resolution_dpi;
/* 08 */ Fixed vertical_resolution_dpi;
/* 0C */ Rect source_rect;
/* 14 */ be_uint32_t reserved2;
/* 18 */
} __attribute__((packed));

union PictSubheader {
Expand Down Expand Up @@ -1257,10 +1259,15 @@ void QuickDrawEngine::render_pict(const void* vdata, size_t size) {
r.go(r.where() + 22);

} else if (opcode == 0x0C00) { // args: header
// Currently we don't do anything with the data in this subheader, so just
// check that its version makes sense and then ignore it
PictSubheader h = r.get<PictSubheader>();
if ((h.v2.version != -1) && (h.v2e.version != -2)) {
if (h.v2.version == -1) {
// Nothing to do - it seems using the bounds in this header version is
// incorrect (but it's correct to use the bounds in the V2E header)
} else if (h.v2e.version == -2) {
this->pict_bounds = h.v2e.source_rect;
Rect port_bounds = this->pict_bounds.anchor();
this->port->set_bounds(port_bounds);
} else {
throw runtime_error(string_printf("subheader has incorrect version (%08X or %04hX)",
h.v2.version.load(), h.v2e.version.load()));
}
Expand Down
34 changes: 22 additions & 12 deletions src/QuickDrawFormats.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ using namespace std;

Color8::Color8(uint32_t c) : Color8(c >> 16, c >> 8, c) {}

Color8::Color8(uint8_t r, uint8_t g, uint8_t b) : r(r),
g(g),
b(b) {}
Color8::Color8(uint8_t r, uint8_t g, uint8_t b)
: r(r),
g(g),
b(b) {}

Color::Color(uint16_t r, uint16_t g, uint16_t b) : r(r),
g(g),
b(b) {}
Color::Color(uint16_t r, uint16_t g, uint16_t b)
: r(r),
g(g),
b(b) {}

Color8 Color::as8() const {
return {
Expand All @@ -43,8 +45,9 @@ uint64_t Color::to_u64() const {
(static_cast<uint64_t>(this->b));
}

Point::Point(int16_t y, int16_t x) : y(y),
x(x) {}
Point::Point(int16_t y, int16_t x)
: y(y),
x(x) {}

bool Point::operator==(const Point& other) const {
return (this->y == other.y) && (this->x == other.x);
Expand All @@ -58,10 +61,11 @@ string Point::str() const {
return string_printf("Point(x=%hd, y=%hd)", this->x.load(), this->y.load());
}

Rect::Rect(int16_t y1, int16_t x1, int16_t y2, int16_t x2) : y1(y1),
x1(x1),
y2(y2),
x2(x2) {}
Rect::Rect(int16_t y1, int16_t x1, int16_t y2, int16_t x2)
: y1(y1),
x1(x1),
y2(y2),
x2(x2) {}

bool Rect::operator==(const Rect& other) const {
return (this->y1 == other.y1) && (this->x1 == other.x1) &&
Expand Down Expand Up @@ -96,6 +100,12 @@ bool Rect::is_empty() const {
return (this->x1 == this->x2) || (this->y1 == this->y2);
}

Rect Rect::anchor(int16_t x, int16_t y) const {
int16_t x_delta = x - this->x1;
int16_t y_delta = y - this->y1;
return Rect(this->y1 + y_delta, this->x1 + x_delta, this->y2 + y_delta, this->x2 + x_delta);
}

string Rect::str() const {
return string_printf("Rect(x1=%hd, y1=%hd, x2=%hd, y2=%hd)",
this->x1.load(), this->y1.load(), this->x2.load(), this->y2.load());
Expand Down
2 changes: 2 additions & 0 deletions src/QuickDrawFormats.hh
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ struct Rect {

bool is_empty() const;

Rect anchor(int16_t x = 0, int16_t y = 0) const;

std::string str() const;
} __attribute__((packed));

Expand Down
5 changes: 5 additions & 0 deletions src/ResourceFile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2575,6 +2575,11 @@ class QuickDrawResourceDasmPort : public QuickDrawPortInterface {
return this->bounds;
}
virtual void set_bounds(Rect z) {
if (((this->img.get_width() != 0) || (this->img.get_height() != 0)) &&
((static_cast<size_t>(z.width()) != this->img.get_width()) &&
(static_cast<size_t>(z.height()) != this->img.get_height()))) {
throw runtime_error("bounds resized after initial drawing");
}
this->bounds = z;
}

Expand Down

0 comments on commit 7668295

Please sign in to comment.