Skip to content

Commit

Permalink
rename some functions
Browse files Browse the repository at this point in the history
  • Loading branch information
xbarin02 committed Nov 30, 2020
1 parent 5192a8b commit af2e0ec
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
28 changes: 14 additions & 14 deletions frame.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ int frame_to_rgb(struct frame *frame)
return RET_SUCCESS;
}

size_t convert_maxval_to_size(int maxval)
size_t convert_maxval_to_sample_size(int maxval)
{
assert(maxval > 0);

Expand All @@ -165,13 +165,13 @@ size_t convert_maxval_to_size(int maxval)
return 0;
}

int dump_frame_body(struct frame *frame, int components, FILE *stream)
int write_frame_body(struct frame *frame, int components, FILE *stream)
{
assert(frame != NULL);

uint8_t Nf = frame->components;
int maxval = (1 << frame->precision) - 1;
size_t sample_size = convert_maxval_to_size(maxval);
size_t sample_size = convert_maxval_to_sample_size(maxval);
size_t width = (size_t)frame->X;
size_t height = (size_t)frame->Y;
size_t line_size = sample_size * components * width;
Expand Down Expand Up @@ -219,7 +219,7 @@ int dump_frame_body(struct frame *frame, int components, FILE *stream)
return RET_SUCCESS;
}

int dump_frame_header(struct frame *frame, int components, FILE *stream)
int write_frame_header(struct frame *frame, int components, FILE *stream)
{
assert(frame != NULL);

Expand All @@ -243,7 +243,7 @@ int dump_frame_header(struct frame *frame, int components, FILE *stream)
return RET_SUCCESS;
}

int dump_frame(struct frame *frame)
int write_frame(struct frame *frame, const char *path)
{
assert(frame != NULL);

Expand All @@ -252,35 +252,35 @@ int dump_frame(struct frame *frame)
switch (frame->components) {
FILE *stream;
case 4:
stream = fopen("output.ppm", "w");
stream = fopen(path != NULL ? path : "output.ppm", "w");
if (stream == NULL) {
return RET_FAILURE_FILE_OPEN;
}
err = dump_frame_header(frame, 3, stream);
err = write_frame_header(frame, 3, stream);
RETURN_IF(err);
err = dump_frame_body(frame, 3, stream);
err = write_frame_body(frame, 3, stream);
RETURN_IF(err);
fclose(stream);
break;
case 3:
stream = fopen("output.ppm", "w");
stream = fopen(path != NULL ? path : "output.ppm", "w");
if (stream == NULL) {
return RET_FAILURE_FILE_OPEN;
}
err = dump_frame_header(frame, 3, stream);
err = write_frame_header(frame, 3, stream);
RETURN_IF(err);
err = dump_frame_body(frame, 3, stream);
err = write_frame_body(frame, 3, stream);
RETURN_IF(err);
fclose(stream);
break;
case 1:
stream = fopen("output.pgm", "w");
stream = fopen(path != NULL ? path : "output.pgm", "w");
if (stream == NULL) {
return RET_FAILURE_FILE_OPEN;
}
err = dump_frame_header(frame, 1, stream);
err = write_frame_header(frame, 1, stream);
RETURN_IF(err);
err = dump_frame_body(frame, 1, stream);
err = write_frame_body(frame, 1, stream);
RETURN_IF(err);
fclose(stream);
break;
Expand Down
2 changes: 1 addition & 1 deletion frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ void frame_destroy(struct frame *frame);

int frame_to_rgb(struct frame *frame);

int dump_frame(struct frame *frame);
int write_frame(struct frame *frame, const char *path);

#endif
4 changes: 2 additions & 2 deletions imgproc.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ int conv_blocks_to_frame(struct context *context)
return RET_SUCCESS;
}

int dump_image(struct context *context)
int write_image(struct context *context, const char *path)
{
int err;

Expand All @@ -166,7 +166,7 @@ int dump_image(struct context *context)
RETURN_IF(err);
err = frame_to_rgb(&frame);
RETURN_IF(err);
err = dump_frame(&frame);
err = write_frame(&frame, path);
RETURN_IF(err);
frame_destroy(&frame);

Expand Down
2 changes: 1 addition & 1 deletion imgproc.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ int invert_dct(struct context *context);

int conv_blocks_to_frame(struct context *context);

int dump_image(struct context *context);
int write_image(struct context *context, const char *path);

#endif
2 changes: 1 addition & 1 deletion parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ int parse_format(FILE *stream, struct context *context)
RETURN_IF(err);
err = conv_blocks_to_frame(context);
RETURN_IF(err);
err = dump_image(context);
err = write_image(context, NULL);
RETURN_IF(err);
return RET_SUCCESS;
/* DRI Define restart interval */
Expand Down

0 comments on commit af2e0ec

Please sign in to comment.