Skip to content

Commit

Permalink
The size of the segment page association field must be four bytes for
Browse files Browse the repository at this point in the history
pages with page numbers greater than 255.

Signed-off-by: Adam Langley <agl@imperialviolet.org>
  • Loading branch information
smuehlst authored and agl committed Aug 18, 2009
1 parent 779bbe4 commit 0077964
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions jbig2segments.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,20 @@ struct Segment {
return refsize;
}

// ---------------------------------------------------------------------------
// Return the size of the segment page association field for this segment.
// (7.2.6)
// ---------------------------------------------------------------------------
unsigned page_size() const {
return page <= 255 ? 1 : 4;
}

// ---------------------------------------------------------------------------
// Return the number of bytes that this segment header will take up
// ---------------------------------------------------------------------------
unsigned size() const {
const int refsize = reference_size();
const int pagesize = page <= 255 ? 1 : 2;
const int pagesize = page_size();

return sizeof(struct jbig2_segment) + refsize * referred_to.size() +
pagesize + sizeof(u32);
Expand All @@ -111,9 +119,9 @@ struct Segment {
#undef F
s.segment_count = referred_to.size();

const int pagesize = page <= 255 ? 1 : 2;
const int pagesize = page_size();
const int refsize = reference_size();
if (pagesize == 2) s.page_assoc_size = 1;
if (pagesize == 4) s.page_assoc_size = 1;

unsigned j = 0;

Expand All @@ -134,8 +142,8 @@ struct Segment {
}
}

if (pagesize == 2) {
APPEND(u16, htonl(page));
if (pagesize == 4) {
APPEND(u32, htonl(page));
} else {
APPEND(u8, page);
}
Expand Down

0 comments on commit 0077964

Please sign in to comment.