Skip to content

Commit

Permalink
align variable names with T.81 standard
Browse files Browse the repository at this point in the history
  • Loading branch information
xbarin02 committed Nov 29, 2020
1 parent f7105ad commit fb8709a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 20 deletions.
8 changes: 4 additions & 4 deletions common.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ int init_qtable(struct qtable *qtable)
{
assert(qtable != NULL);

qtable->precision = 0;
qtable->Pq = 0;

for (int i = 0; i < 64; ++i) {
qtable->element[i] = 0;
qtable->Q[i] = 0;
}

return RET_SUCCESS;
Expand Down Expand Up @@ -63,12 +63,12 @@ int init_context(struct context *context)
init_qtable(&context->qtable[i]);
}

context->precision = 0;
context->P = 0;

context->Y = 0;
context->X = 0;

context->components = 0;
context->Nf = 0;

for (int i = 0; i < 256; ++i) {
init_component(&context->component[i]);
Expand Down
12 changes: 6 additions & 6 deletions common.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ static const uint8_t zigzag[64] = {
} while (0)

struct qtable {
/* Value 0 indicates 8-bit Qk values; value 1 indicates 16-bit Qk values. */
uint8_t precision;
/* in zig-zag scan order */
uint16_t element[64];
/* precision: Value 0 indicates 8-bit Qk values; value 1 indicates 16-bit Qk values. */
uint8_t Pq;
/* elements: in raster scan order */
uint16_t Q[64];
};

struct component {
Expand Down Expand Up @@ -120,13 +120,13 @@ struct context {
struct qtable qtable[4];

/* Sample precision */
uint8_t precision;
uint8_t P;

/* Number of lines, Number of samples per line */
uint16_t Y, X;

/* Number of image components in frame */
uint8_t components;
uint8_t Nf;

struct component component[256];

Expand Down
9 changes: 5 additions & 4 deletions imgproc.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ int dequantize(struct context *context)
struct int_block *int_block = &context->component[i].int_buffer[b];

for (int j = 0; j < 64; ++j) {
int_block->c[j] *= (int32_t)qtable->element[j];
int_block->c[j] *= (int32_t)qtable->Q[j];
}
}
}
Expand Down Expand Up @@ -108,7 +108,8 @@ int invert_dct(struct context *context)

idct(flt_block);

uint8_t P = context->precision;
/* precision */
uint8_t P = context->P;
int shift = 1 << (P - 1);

// level shift
Expand Down Expand Up @@ -191,10 +192,10 @@ int frame_create(struct context *context, struct frame *frame)
assert(context != NULL);
assert(frame != NULL);

frame->components = context->components;
frame->components = context->Nf;
frame->Y = context->Y;
frame->X = context->X;
frame->precision = context->precision;
frame->precision = context->P;

size_t size_x = ceil_div(frame->X, 8 * context->max_H) * 8 * context->max_H;
size_t size_y = ceil_div(frame->Y, 8 * context->max_V) * 8 * context->max_V;
Expand Down
17 changes: 11 additions & 6 deletions parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,26 @@ int parse_qtable(FILE *stream, struct context *context)

qtable = &context->qtable[Tq];

qtable->precision = Pq;
/* precision */
qtable->Pq = Pq;

for (int i = 0; i < 64; ++i) {
if (Pq == 0) {
uint8_t byte;
err = read_byte(stream, &byte);
RETURN_IF(err);
qtable->element[zigzag[i]] = (uint16_t)byte;
qtable->Q[zigzag[i]] = (uint16_t)byte;
} else {
uint16_t word;
err = read_word(stream, &word);
RETURN_IF(err);
qtable->element[zigzag[i]] = word;
qtable->Q[zigzag[i]] = word;
}
}

for (int y = 0; y < 8; ++y) {
for (int x = 0; x < 8; ++x) {
printf("%3" PRIu16 " ", qtable->element[y * 8 + x]);
printf("%3" PRIu16 " ", qtable->Q[y * 8 + x]);
}
printf("\n");
}
Expand Down Expand Up @@ -116,10 +117,14 @@ int parse_frame_header(FILE *stream, struct context *context)

printf("P = %" PRIu8 " (Sample precision), Y = %" PRIu16 ", X = %" PRIu16 ", Nf = %" PRIu8 " (Number of image components)\n", P, Y, X, Nf);

context->precision = P;
/* precision */
context->P = P;

context->Y = Y;
context->X = X;
context->components = Nf;

/* components */
context->Nf = Nf;

uint8_t max_H = 0, max_V = 0;

Expand Down

0 comments on commit fb8709a

Please sign in to comment.