Skip to content

Commit

Permalink
Use same struct scheme as box from imath for consistency (#1073)
Browse files Browse the repository at this point in the history
Initially we did this differently so it was obvious it didn't have the
other functionality, but by having the same nested scheme of a box
having 2 vecs, enables us to add templated sfinae constructors to auto
convert the C type into c++ instead of just having to reinterpret cast

Signed-off-by: Kimball Thurston <kdt3rd@gmail.com>
  • Loading branch information
kdt3rd committed Jun 27, 2021
1 parent 72c2444 commit bbcdeb6
Show file tree
Hide file tree
Showing 11 changed files with 142 additions and 149 deletions.
98 changes: 49 additions & 49 deletions src/lib/OpenEXRCore/chunk.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,29 +168,29 @@ exr_read_scanline_block_info (
}

dw = part->data_window;
if (y < dw.y_min || y > dw.y_max)
if (y < dw.min.y || y > dw.max.y)
{
return pctxt->print_error (
pctxt,
EXR_ERR_INVALID_ARGUMENT,
"Invalid request for scanline %d outside range of data window (%d - %d)",
y,
dw.y_min,
dw.y_max);
dw.min.y,
dw.max.y);
}

lpc = part->lines_per_chunk;
cidx = (y - dw.y_min);
cidx = (y - dw.min.y);
if (lpc > 1) cidx /= lpc;

if (part->lineorder == EXR_LINEORDER_DECREASING_Y)
{
cidx = part->chunk_count - (cidx + 1);
miny = dw.y_max - (cidx + 1) * lpc;
miny = dw.max.y - (cidx + 1) * lpc;
}
else
{
miny = cidx * lpc + dw.y_min;
miny = cidx * lpc + dw.min.y;
}

if (cidx < 0 || cidx >= part->chunk_count)
Expand All @@ -207,18 +207,18 @@ exr_read_scanline_block_info (
cinfo->idx = cidx;
cinfo->type = (uint8_t) part->storage_mode;
cinfo->compression = (uint8_t) part->comp_type;
cinfo->start_x = dw.x_min;
cinfo->start_x = dw.min.x;
cinfo->start_y = miny;
cinfo->width = dw.x_max - dw.x_min + 1;
cinfo->width = dw.max.x - dw.min.x + 1;
cinfo->height = lpc;
if (miny < dw.y_min)
if (miny < dw.min.y)
{
cinfo->start_y = dw.y_min;
cinfo->height -= (dw.y_min - miny);
cinfo->start_y = dw.min.y;
cinfo->height -= (dw.min.y - miny);
}
else if ((miny + lpc) > dw.y_max)
else if ((miny + lpc) > dw.max.y)
{
cinfo->height = (dw.y_max - miny + 1);
cinfo->height = (dw.max.y - miny + 1);
}
cinfo->level_x = 0;
cinfo->level_y = 0;
Expand Down Expand Up @@ -512,20 +512,20 @@ exr_read_tile_block_info (
if (tiledesc->y_size < (uint32_t) tileh) tileh = (int) tiledesc->y_size;

if (((int64_t) (tilex) * (int64_t) (tilew) + (int64_t) (tilew) +
(int64_t) (part->data_window.x_min) - 1) >
(int64_t) (part->data_window.x_max))
(int64_t) (part->data_window.min.x) - 1) >
(int64_t) (part->data_window.max.x))
{
int64_t sz = (int64_t) (part->data_window.x_max) -
(int64_t) (part->data_window.x_min) + 1;
int64_t sz = (int64_t) (part->data_window.max.x) -
(int64_t) (part->data_window.min.x) + 1;
tilew = (int) (sz - ((int64_t) (tilex) * (int64_t) (tilew)));
}

if (((int64_t) (tiley) * (int64_t) (tileh) + (int64_t) (tileh) +
(int64_t) (part->data_window.y_min) - 1) >
(int64_t) (part->data_window.y_max))
(int64_t) (part->data_window.min.y) - 1) >
(int64_t) (part->data_window.max.y))
{
int64_t sz = (int64_t) (part->data_window.y_max) -
(int64_t) (part->data_window.y_min) + 1;
int64_t sz = (int64_t) (part->data_window.max.y) -
(int64_t) (part->data_window.min.y) + 1;
tileh = (int) (sz - ((int64_t) (tiley) * (int64_t) (tileh)));
}

Expand Down Expand Up @@ -960,29 +960,29 @@ write_scan_chunk (
(uint64_t) sample_data_size,
sample_data);

if (y < part->data_window.y_min || y > part->data_window.y_max)
if (y < part->data_window.min.y || y > part->data_window.max.y)
{
return pctxt->print_error (
pctxt,
EXR_ERR_INVALID_ARGUMENT,
"Invalid attempt to write scanlines starting at %d outside range of data window (%d - %d)",
y,
part->data_window.y_min,
part->data_window.y_max);
part->data_window.min.y,
part->data_window.max.y);
}

lpc = part->lines_per_chunk;
cidx = (y - part->data_window.y_min);
cidx = (y - part->data_window.min.y);
if (lpc > 1) cidx /= lpc;

if (part->lineorder == EXR_LINEORDER_DECREASING_Y)
{
cidx = part->chunk_count - (cidx + 1);
miny = part->data_window.y_max - (cidx + 1) * lpc;
miny = part->data_window.max.y - (cidx + 1) * lpc;
}
else
{
miny = cidx * lpc + part->data_window.y_min;
miny = cidx * lpc + part->data_window.min.y;
}

if (y != miny)
Expand Down Expand Up @@ -1132,29 +1132,29 @@ exr_write_scanline_block_info (
}

dw = part->data_window;
if (y < dw.y_min || y > dw.y_max)
if (y < dw.min.y || y > dw.max.y)
{
return EXR_UNLOCK_AND_RETURN_PCTXT (pctxt->print_error (
pctxt,
EXR_ERR_INVALID_ARGUMENT,
"Invalid request for scanline %d outside range of data window (%d - %d)",
y,
dw.y_min,
dw.y_max));
dw.min.y,
dw.max.y));
}

lpc = part->lines_per_chunk;
cidx = (y - dw.y_min);
cidx = (y - dw.min.y);
if (lpc > 1) cidx /= lpc;

if (part->lineorder == EXR_LINEORDER_DECREASING_Y)
{
cidx = part->chunk_count - (cidx + 1);
miny = dw.y_max - (cidx + 1) * lpc;
miny = dw.max.y - (cidx + 1) * lpc;
}
else
{
miny = cidx * lpc + dw.y_min;
miny = cidx * lpc + dw.min.y;
}

if (cidx < 0 || cidx >= part->chunk_count)
Expand All @@ -1172,18 +1172,18 @@ exr_write_scanline_block_info (
cinfo->idx = cidx;
cinfo->type = (uint8_t) part->storage_mode;
cinfo->compression = (uint8_t) part->comp_type;
cinfo->start_x = dw.x_min;
cinfo->start_x = dw.min.x;
cinfo->start_y = miny;
cinfo->width = dw.x_max - dw.x_min + 1;
cinfo->width = dw.max.x - dw.min.x + 1;
cinfo->height = lpc;
if (miny < dw.y_min)
if (miny < dw.min.y)
{
cinfo->start_y = dw.y_min;
cinfo->height -= (dw.y_min - miny);
cinfo->start_y = dw.min.y;
cinfo->height -= (dw.min.y - miny);
}
else if ((miny + lpc) > dw.y_max)
else if ((miny + lpc) > dw.max.y)
{
cinfo->height = (dw.y_max - miny + 1);
cinfo->height = (dw.max.y - miny + 1);
}
cinfo->level_x = 0;
cinfo->level_y = 0;
Expand Down Expand Up @@ -1259,20 +1259,20 @@ exr_write_tile_block_info (
if (tiledesc->y_size < (uint32_t) tileh) tileh = (int) tiledesc->y_size;

if (((int64_t) (tilex) * (int64_t) (tilew) + (int64_t) (tilew) +
(int64_t) (part->data_window.x_min) - 1) >
(int64_t) (part->data_window.x_max))
(int64_t) (part->data_window.min.x) - 1) >
(int64_t) (part->data_window.max.x))
{
int64_t sz = (int64_t) (part->data_window.x_max) -
(int64_t) (part->data_window.x_min) + 1;
int64_t sz = (int64_t) (part->data_window.max.x) -
(int64_t) (part->data_window.min.x) + 1;
tilew = (int) (sz - ((int64_t) (tilex) * (int64_t) (tilew)));
}

if (((int64_t) (tiley) * (int64_t) (tileh) + (int64_t) (tileh) +
(int64_t) (part->data_window.y_min) - 1) >
(int64_t) (part->data_window.y_max))
(int64_t) (part->data_window.min.y) - 1) >
(int64_t) (part->data_window.max.y))
{
int64_t sz = (int64_t) (part->data_window.y_max) -
(int64_t) (part->data_window.y_min) + 1;
int64_t sz = (int64_t) (part->data_window.max.y) -
(int64_t) (part->data_window.min.y) + 1;
tileh = (int) (sz - ((int64_t) (tiley) * (int64_t) (tileh)));
}

Expand Down Expand Up @@ -1656,7 +1656,7 @@ internal_validate_next_chunk (
else
{
lpc = part->lines_per_chunk;
cidx = (encode->chunk_block.start_y - part->data_window.y_min);
cidx = (encode->chunk_block.start_y - part->data_window.min.y);
if (lpc > 1) cidx /= lpc;

if (part->lineorder == EXR_LINEORDER_DECREASING_Y)
Expand Down
20 changes: 10 additions & 10 deletions src/lib/OpenEXRCore/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,20 @@ print_attr (const exr_attribute_t* a, int verbose)
case EXR_ATTR_BOX2I:
printf (
"[ %d, %d - %d %d ] %d x %d",
a->box2i->x_min,
a->box2i->y_min,
a->box2i->x_max,
a->box2i->y_max,
a->box2i->x_max - a->box2i->x_min + 1,
a->box2i->y_max - a->box2i->y_min + 1);
a->box2i->min.x,
a->box2i->min.y,
a->box2i->max.x,
a->box2i->max.y,
a->box2i->max.x - a->box2i->min.x + 1,
a->box2i->max.y - a->box2i->min.y + 1);
break;
case EXR_ATTR_BOX2F:
printf (
"[ %g, %g - %g %g ]",
(double) a->box2f->x_min,
(double) a->box2f->y_min,
(double) a->box2f->x_max,
(double) a->box2f->y_max);
(double) a->box2f->min.x,
(double) a->box2f->min.y,
(double) a->box2f->max.x,
(double) a->box2f->max.y);
break;
case EXR_ATTR_CHLIST:
printf ("%d channels\n", a->chlist->num_channels);
Expand Down
8 changes: 4 additions & 4 deletions src/lib/OpenEXRCore/internal_structs.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,10 @@ internal_exr_add_part (

/* assign appropriately invalid values */
part->storage_mode = EXR_STORAGE_LAST_TYPE;
part->data_window.x_max = -1;
part->data_window.y_max = -1;
part->display_window.x_max = -1;
part->display_window.y_max = -1;
part->data_window.max.x = -1;
part->data_window.max.y = -1;
part->display_window.max.x = -1;
part->display_window.max.y = -1;
part->chunk_count = -1;

/* put it into the part table */
Expand Down
32 changes: 14 additions & 18 deletions src/lib/OpenEXRCore/openexr_attr.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,24 +106,6 @@ typedef enum
* structs to be tightly packed */
#pragma pack(push, 1)

/** @brief struct to hold an integer box / region definition */
typedef struct
{
int32_t x_min;
int32_t y_min;
int32_t x_max;
int32_t y_max;
} exr_attr_box2i_t;

/** @brief struct to hold a floating-point box / region definition */
typedef struct
{
float x_min;
float y_min;
float x_max;
float y_max;
} exr_attr_box2f_t;

/** @brief struct to hold color chromaticities to interpret the tristimulus color values in the image data */
typedef struct
{
Expand Down Expand Up @@ -265,6 +247,20 @@ typedef struct
};
} exr_attr_v3d_t;

/** @brief struct to hold an integer box / region definition */
typedef struct
{
exr_attr_v2i_t min;
exr_attr_v2i_t max;
} exr_attr_box2i_t;

/** @brief struct to hold a floating-point box / region definition */
typedef struct
{
exr_attr_v2f_t min;
exr_attr_v2f_t max;
} exr_attr_box2f_t;

/** @brief Struct holding base tiledesc attribute type defined in spec
*
* NB: this is in a tightly packed area so it can be read directly, be
Expand Down
Loading

0 comments on commit bbcdeb6

Please sign in to comment.