Skip to content

Commit

Permalink
Extend the stacked g00 parsing code.
Browse files Browse the repository at this point in the history
In 28e4a60, we started dealing with a sort of g00 file that was first
used in Tomoyo After, where all regions had the same boundaries. This
previously broke the Little Busters Refrain, and now is causing problems
for the waku buttons in the Clannad English Edition.

This extends the logic so that it detects images that have only one
region specified multiple times. It looks like the logic which allocates
more room doesn't need to change.

Closes GH-69.
  • Loading branch information
eglaysher committed Jun 13, 2016
1 parent 6148fd7 commit ebc2c5b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
21 changes: 16 additions & 5 deletions vendor/xclannad/file.cc
Expand Up @@ -88,10 +88,19 @@ int g_isBigEndian = IsBigEndian();
#include "file.h"
#include "endian.hpp"

#include <set>
#include <tuple>

using namespace std;

// -----------------------------------------------------------------------

bool GRPCONV::REGION::operator<(const REGION& rhs) const {
return
std::tie(x1, y1, x2, y2, origin_x, origin_y) <
std::tie(rhs.x1, rhs.y1, rhs.x2, rhs.y2, rhs.origin_x, rhs.origin_y);
}

/**********************************************
**
** 画像展開系クラスの定義、実装
Expand Down Expand Up @@ -248,6 +257,8 @@ G00CONV::G00CONV(const char* _inbuf, int _inlen, const char* filename) {

region_table = vector<REGION>(head_size);

int real_region_count = 0;
std::set<REGION> unique_regions;
const char* head = _inbuf + 9;
bool overlaid_image = head_size > 1;
for (int i = 0; i < head_size; i++) {
Expand All @@ -258,16 +269,16 @@ G00CONV::G00CONV(const char* _inbuf, int _inlen, const char* filename) {
region_table[i].origin_x = read_little_endian_int(head+16);
region_table[i].origin_y = read_little_endian_int(head+20);
region_table[i].Fix(w, h);

if (region_table[i].x1 != 0 || region_table[i].y1 != 0 ||
region_table[i].x2 != (w - 1) || region_table[i].y2 != (h - 1)) {
overlaid_image = false;
if (region_table[i].Width() &&
region_table[i].Height()) {
unique_regions.insert(region_table[i]);
real_region_count++;
}

head += 24;
}

if (overlaid_image) {
if (real_region_count > 1 && unique_regions.size() == 1) {
// This is one of those newer images where each region is the size of
// width/height and is stacked on top of each other. We therefore have to
// munge the height and the region table so each region gets its own
Expand Down
6 changes: 4 additions & 2 deletions vendor/xclannad/file.h
Expand Up @@ -40,8 +40,8 @@ class GRPCONV {
struct REGION {
int x1, y1, x2, y2;
int origin_x, origin_y;
int Width() { return x2-x1+1;}
int Height() { return y2-y1+1;}
int Width() { return x2-x1;}
int Height() { return y2-y1;}
void FixVar(int& v, int& w) {
if (v < 0) v = 0;
if (v >= w) v = w-1;
Expand All @@ -56,6 +56,8 @@ class GRPCONV {
if (x1 > x2) x2 = x1;
if (y1 > y2) y2 = y1;
}

bool operator<(const REGION& rhs) const;
};

std::vector<REGION> region_table;
Expand Down

0 comments on commit ebc2c5b

Please sign in to comment.