2019-08-11 03:37:52 +11:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "../floatimg.h"
|
|
|
|
|
|
|
|
#include "funcs.h"
|
|
|
|
|
2019-09-04 00:37:49 +11:00
|
|
|
extern int verbosity;
|
|
|
|
|
2019-08-24 22:24:01 +11:00
|
|
|
/*
|
|
|
|
* Be careful, these functions are not yet fireproof,
|
|
|
|
* and calling conventions are fluctuating.
|
|
|
|
*/
|
|
|
|
|
2019-08-12 10:53:17 +11:00
|
|
|
/* --------------------------------------------------------------------- */
|
2019-09-04 00:37:49 +11:00
|
|
|
int x_upscaler_0(unsigned char *src, int w, int h, FloatImg *d)
|
2019-08-12 10:53:17 +11:00
|
|
|
{
|
2019-09-04 00:37:49 +11:00
|
|
|
int x, y, xx, yy, ox, oy;
|
2019-08-15 14:50:40 +11:00
|
|
|
// float *rp, *gp, *bp;
|
2019-08-12 10:53:17 +11:00
|
|
|
float r, g, b;
|
|
|
|
static unsigned short modz;
|
|
|
|
|
2019-08-24 22:24:01 +11:00
|
|
|
/*
|
|
|
|
* check in image sizes are correct
|
|
|
|
*/
|
|
|
|
if ( d->width != w*2 || d->height != h*2 ) {
|
|
|
|
fprintf(stderr, "%s : dimension error\n", __func__);
|
|
|
|
return -2;
|
|
|
|
}
|
|
|
|
|
2019-09-04 07:01:16 +11:00
|
|
|
ox = ! ! (modz & 2);
|
|
|
|
oy = ! ! (modz & 1);
|
2019-09-04 00:37:49 +11:00
|
|
|
|
|
|
|
if (verbosity>2) fprintf(stderr, "%s %5d %d %d\n", __func__,
|
|
|
|
modz, ox, oy);
|
2019-08-12 10:53:17 +11:00
|
|
|
|
|
|
|
for (y=0; y<h; y++) {
|
2019-09-04 00:37:49 +11:00
|
|
|
yy = (y*2) + oy;
|
2019-08-12 10:53:17 +11:00
|
|
|
for (x=0; x<w; x++) {
|
2019-09-04 00:37:49 +11:00
|
|
|
xx = (x*2) + ox;
|
2019-08-12 10:53:17 +11:00
|
|
|
r = (float)*src++;
|
|
|
|
g = (float)*src++;
|
|
|
|
b = (float)*src++;
|
2019-12-21 22:37:26 +11:00
|
|
|
|
|
|
|
/* may be, here, we can speed up the job */
|
2019-09-04 04:35:45 +11:00
|
|
|
fimg_add_rgb(d, xx, yy, r, g, b);
|
2020-01-15 04:00:10 +11:00
|
|
|
/* or may be jump directly to asm and SSE2
|
|
|
|
http://www.mikekohn.net/stuff/image_processing.php */
|
2019-08-12 10:53:17 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-17 20:43:06 +11:00
|
|
|
modz++; /* next displacment index */
|
|
|
|
|
2019-09-26 01:48:34 +11:00
|
|
|
if ( ! (modz & 0x03)) {
|
|
|
|
d->count++; /* one more frame in the accumulator */
|
|
|
|
}
|
2019-08-12 10:53:17 +11:00
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
2019-08-11 03:37:52 +11:00
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
int x_rgb2fimg(unsigned char *src, int w, int h, FloatImg *d)
|
|
|
|
{
|
|
|
|
int iter, size;
|
|
|
|
float *rp, *gp, *bp;
|
|
|
|
|
|
|
|
size = w * h;
|
2019-08-11 06:26:39 +11:00
|
|
|
rp = d->R, gp = d->G, bp = d->B;
|
2019-08-11 03:37:52 +11:00
|
|
|
|
|
|
|
for (iter=0; iter<size; iter++) {
|
|
|
|
*rp++ = (float)*src++;
|
|
|
|
*gp++ = (float)*src++;
|
|
|
|
*bp++ = (float)*src++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* --------------------------------------------------------------------- */
|
2019-08-15 14:50:40 +11:00
|
|
|
int x_add_rgb2fimg(unsigned char *src, int w, int h, FloatImg *d)
|
|
|
|
{
|
|
|
|
int iter, size;
|
|
|
|
float *rp, *gp, *bp;
|
|
|
|
|
|
|
|
size = w * h;
|
|
|
|
rp = d->R, gp = d->G, bp = d->B;
|
|
|
|
|
|
|
|
for (iter=0; iter<size; iter++) {
|
|
|
|
*rp++ += (float)*src++;
|
|
|
|
*gp++ += (float)*src++;
|
|
|
|
*bp++ += (float)*src++;
|
|
|
|
}
|
|
|
|
|
2019-08-24 22:24:01 +11:00
|
|
|
d->count++; /* one more frame in the accumulator */
|
|
|
|
|
2019-08-15 14:50:40 +11:00
|
|
|
return 0;
|
|
|
|
}
|
2019-08-24 22:24:01 +11:00
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|
2019-08-11 03:37:52 +11:00
|
|
|
int x_rgb2file(unsigned char *src, int w, int h, char *fname)
|
|
|
|
{
|
|
|
|
FloatImg buff;
|
|
|
|
int foo;
|
|
|
|
|
|
|
|
#if DEBUG_LEVEL
|
|
|
|
fprintf(stderr, ">>> %s ( %p %d %d '%s' )\n", __func__,
|
|
|
|
src, w, h, fname);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
foo = fimg_create(&buff, w, h, FIMG_TYPE_RGB);
|
|
|
|
if (foo) {
|
|
|
|
fprintf(stderr, "Crash on create in %s %s\n", __FILE__, __func__);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
foo = x_rgb2fimg(src, w, h, &buff);
|
|
|
|
if (foo) {
|
|
|
|
fprintf(stderr, "Crash on bit massage in %s %s\n", __FILE__, __func__);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
foo = fimg_dump_to_file(&buff, fname, 0);
|
|
|
|
if (foo) {
|
|
|
|
fprintf(stderr, "Crash on dump in %s %s\n", __FILE__, __func__);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
fimg_destroy(&buff);
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
/* --------------------------------------------------------------------- */
|