aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDaniil Cherednik <dan.cherednik@gmail.com>2018-09-26 23:48:37 +0300
committerDaniil Cherednik <dan.cherednik@gmail.com>2018-09-26 23:48:37 +0300
commit1216b63c7b6864b0faeb2c6fd68a2a0ef5893f0e (patch)
treed19b992c6efc352eb075024e8fff2903e2da7669 /src
parent01a9391be1655617c9bb2f9922b4a51ac5ab4b93 (diff)
downloadanalogcolor-1216b63c7b6864b0faeb2c6fd68a2a0ef5893f0e.tar.gz
Verbose output added
Diffstat (limited to 'src')
-rw-r--r--src/libanalog/ntsc.c31
-rw-r--r--src/libanalog/ntsc.h4
-rw-r--r--src/main.c13
3 files changed, 44 insertions, 4 deletions
diff --git a/src/libanalog/ntsc.c b/src/libanalog/ntsc.c
index a0b52e1..2aaea49 100644
--- a/src/libanalog/ntsc.c
+++ b/src/libanalog/ntsc.c
@@ -17,11 +17,16 @@ struct biquad_filter_ctx {
float z1, z2;
};
+struct verbose_ctx {
+ FILE* fout;
+};
+
struct ntsc_ctx {
struct generator_ctx {
float* sin_table;
float* cos_table;
+ int f;
int shift;
} generator;
uint16_t width;
@@ -29,6 +34,8 @@ struct ntsc_ctx {
struct biquad_filter_ctx i_filter;
struct biquad_filter_ctx q_filter;
+
+ struct verbose_ctx* verbose;
};
static void ntsc_filter_init(struct biquad_filter_ctx* filter, float fc)
@@ -77,12 +84,12 @@ static void ntsc_create_generator(struct ntsc_ctx* ctx)
int n = 2 * ctx->width;
float width = ctx->width;
//TODO: tune the freq
- int f = (int)(width / 2.5) | 0x01;
+ ctx->generator.f = (int)(width / 2.5) | 0x01;
ctx->generator.sin_table = malloc(sizeof(float) * n);
ctx->generator.cos_table = malloc(sizeof(float) * n);
for (i = 0; i < n; i++) {
- ctx->generator.sin_table[i] = sin(f * i * M_PI/width);
- ctx->generator.cos_table[i] = cos(f * i * M_PI/width);
+ ctx->generator.sin_table[i] = sin(ctx->generator.f * i * M_PI/width);
+ ctx->generator.cos_table[i] = cos(ctx->generator.f * i * M_PI/width);
}
ctx->generator.shift = 0;
}
@@ -108,16 +115,34 @@ ntsc_ctx* ntsc_create_context(int width, int encode)
ntsc_filter_init(&p->i_filter, 0.08);
ntsc_filter_init(&p->q_filter, 0.05);
+ p->verbose = NULL;
return p;
}
void ntsc_free_context(ntsc_ctx* ctx)
{
+ if (ctx->verbose)
+ free(ctx->verbose);
ntsc_free_generator(ctx);
free(ctx->iq);
free(ctx);
}
+static void verbose_carrier(ntsc_ctx* ctx)
+{
+ float t = (ctx->width * 2) / (float)ctx->generator.f;
+ fprintf(ctx->verbose->fout, "Width: %d pixels\n", ctx->width);
+ fprintf(ctx->verbose->fout, "Carrier: period is %f pixels (%f of Fmax)\n", t, 2/t);
+}
+
+void ntsc_enable_verbose(FILE* fout, ntsc_ctx* ctx)
+{
+ ctx->verbose = malloc(sizeof(struct verbose_ctx));
+ ctx->verbose->fout = fout;
+ fprintf(ctx->verbose->fout, "Verbose output enabled\n");
+ verbose_carrier(ctx);
+}
+
static void ntsc_next_line(ntsc_ctx* ctx)
{
if (ctx->generator.shift) {
diff --git a/src/libanalog/ntsc.h b/src/libanalog/ntsc.h
index 908e9a6..9cc520b 100644
--- a/src/libanalog/ntsc.h
+++ b/src/libanalog/ntsc.h
@@ -1,6 +1,8 @@
#ifndef NTSC_H
#define NTSC_H
+#include <stdio.h>
+
typedef struct ntsc_ctx ntsc_ctx;
ntsc_ctx* ntsc_create_context(int width, int encode);
@@ -8,4 +10,6 @@ void ntsc_free_context(ntsc_ctx* ctx);
void ntsc_process_encode(const float* input, float* output, ntsc_ctx* ctx);
void ntsc_process_decode(const float* input, float* output, ntsc_ctx* ctx);
+void ntsc_enable_verbose(FILE* fout, ntsc_ctx* ctx);
+
#endif
diff --git a/src/main.c b/src/main.c
index 8a45c3a..7bd2bcb 100644
--- a/src/main.c
+++ b/src/main.c
@@ -22,12 +22,15 @@ void print_usage(const char* self_name)
int main(int argc, char** argv)
{
- if (argc != 4)
+ if (argc != 4 && argc != 5) {
print_usage(argv[0]);
+ return 1;
+ }
const char* input_file = argv[2];
const char* output_file = argv[3];
const int encode = *argv[1] == 'e';
+ int verbose = 0;
int width, height, components, out_components;
int line = 0;
@@ -37,6 +40,11 @@ int main(int argc, char** argv)
unsigned char* input_image = stbi_load(input_file,
&width, &height, &components, encode ? STBI_rgb : STBI_grey);
+ if (argc == 5)
+ if (*argv[4] == 'v')
+ verbose = 1;
+
+
if (!input_image) {
fprintf(stderr, "Unable to load image\n");
goto exit;
@@ -53,6 +61,9 @@ int main(int argc, char** argv)
ntsc_ctx* ctx = ntsc_create_context(width, encode);
+ if (verbose)
+ ntsc_enable_verbose(stderr, ctx);
+
if (!ctx) {
fprintf(stderr, "Unable to crete ntsc context\n");
goto exit_free_input_image;