75int main(
int argc,
char* argv[]) {
76 const char* opt_fsk_id = NULL;
77 const char* opt_channels =
"1";
78 const char* opt_mode =
"M1";
79 const char* opt_input_img = NULL;
80 const char* opt_output_au = NULL;
85 uint8_t total_audio_channels;
86 uint8_t select_audio_channels;
89 static struct option long_options[] = {
91 .has_arg = required_argument,
95 .has_arg = required_argument,
99 .has_arg = required_argument,
103 .has_arg = required_argument,
107 .has_arg = required_argument,
110 {.name = NULL, .has_arg = 0, .flag = NULL, .val = 0},
114 int c = getopt_long(argc, argv,
"B:C:M:R:f:", long_options,
118 }
else if (!c && !long_options[opt_idx].flag) {
119 c = long_options[opt_idx].val;
126 opt_bits = strtol(optarg, &endptr, 10);
159 "Invalid number of bits: %s\n"
160 "Supported values: 8, 16, 32/32s/32f "
167 opt_channels = optarg;
173 opt_rate = atoi(optarg);
184 if ((argc - optind) != 2) {
188 opt_input_img = argv[optind];
189 opt_output_au = argv[optind + 1];
191 switch (opt_channels[0]) {
196 total_audio_channels = 1;
197 select_audio_channels = 1;
203 total_audio_channels = 2;
204 select_audio_channels = UINT8_MAX;
209 total_audio_channels = 2;
210 select_audio_channels = 1;
215 total_audio_channels = 2;
216 select_audio_channels = 2;
219 printf(
"Unknown channel mode: %s\n", opt_channels);
228 fprintf(stderr,
"Unknown mode %s\n", opt_mode);
229 printf(
"Valid modes are:\n");
242 = malloc(mode->
width * mode->
height * colours *
sizeof(uint8_t));
244 FILE* in = fopen(opt_input_img,
"rb");
246 perror(
"Failed to open input file");
249 gdImagePtr im = gdImageCreateFromPng(in);
253 gdImagePtr im_resized = gdImageScale(im, mode->
width, mode->
height);
255 for (uint16_t y = 0; y < mode->
height; y++) {
256 for (uint16_t x = 0; x < mode->
width; x++) {
257 int c = gdImageGetTrueColorPixel(im_resized, x, y);
260 uint8_t r = gdTrueColorGetRed(c);
261 uint8_t g = gdTrueColorGetGreen(c);
262 uint8_t b = gdTrueColorGetBlue(c);
264 switch (colourspace) {
284 for (uint8_t c = 0; c < colours; c++) {
289 gdImageDestroy(im_resized);
297 total_audio_channels);
299 fprintf(stderr,
"Failed to open output file %s: %s\n",
300 opt_output_au, strerror(-res));
311 double samples[total_audio_channels];
316 for (uint8_t ch = 0; ch < total_audio_channels; ch++) {
317 if (select_audio_channels & (1 << ch)) {
326 &au, total_audio_channels, samples);
328 fprintf(stderr,
"Failed to write audio samples: %s\n",
338 "Failed to close audio output file: %s\n",
void sstvenc_modulator_init(struct sstvenc_mod *const mod, const struct sstvenc_mode *mode, const char *fsk_id, const uint8_t *framebuffer, double rise_time, double fall_time, uint32_t sample_rate, uint8_t time_unit)