Skip to content

Commit

Permalink
version 1
Browse files Browse the repository at this point in the history
  • Loading branch information
ayushmankumar7 committed Apr 8, 2022
1 parent ed2b74d commit 247572e
Show file tree
Hide file tree
Showing 22 changed files with 2,246 additions and 3 deletions.
Binary file added .sconsign.dblite
Binary file not shown.
2 changes: 2 additions & 0 deletions Sconstruct
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
print([Glob("src/*.c")])
Program("bin/output", [Glob("src/*.c")])
Binary file added etc/yuvplayer.exe
Binary file not shown.
13 changes: 13 additions & 0 deletions includes/global.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once
#include <stdio.h>
#include <stdlib.h>
#include "ops.h"
#include "utils.h"
#include "model.h"

#ifndef _GLOBAL_H_
#define _GLOBAL_H_

int main(int,char **);

#endif
9 changes: 8 additions & 1 deletion includes/model.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
#ifndef
#pragma once
#include <stdio.h>
#include "ops.h"
#include "utils.h"
#include "vars.h"

#ifndef MODEL_H
#define MODEL_H


void FSRCNN(double *img_hr, double *img_lr, int rows, int cols, int scale);
void PReLU(double *img_fltr, int rows, int cols, double bias, double prelu_coeff);

Expand Down
2 changes: 1 addition & 1 deletion includes/ops.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma ONCE
#pragma once
#include <stdio.h>
#include <stdlib.h>

Expand Down
2 changes: 1 addition & 1 deletion includes/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

double Max(double a, double b);
double Min(double a, double b);
void double_to_uint8(double *img, unsigned char *uint8_img, int cols, int rows)
void double_to_uint8(double *img, unsigned char *uint8_img, int cols, int rows);

#endif
16 changes: 16 additions & 0 deletions includes/vars.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#define WEIGHT1 "../pretrained/weights_layer1.txt"
#define WEIGHT2 "../pretrained/weights_layer2.txt"
#define WEIGHT3 "../pretrained/weights_layer3.txt"
#define WEIGHT4 "../pretrained/weights_layer4.txt"
#define WEIGHT5 "../pretrained/weights_layer5.txt"
#define WEIGHT6 "../pretrained/weights_layer6.txt"
#define WEIGHT7 "../pretrained/weights_layer7.txt"
#define WEIGHT8 "../pretrained/weights_layer8.txt"

#define BIAS1 "../pretrained/biases_layer1.txt"
#define BIAS2 "../pretrained/biases_layer2.txt"
#define BIAS3 "../pretrained/biases_layer3.txt"
#define BIAS4 "../pretrained/biases_layer4.txt"
#define BIAS5 "../pretrained/biases_layer5.txt"
#define BIAS6 "../pretrained/biases_layer6.txt"
#define BIAS7 "../pretrained/biases_layer7.txt"
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1,531 changes: 1,531 additions & 0 deletions share/akiyo_qcif.yuv

Large diffs are not rendered by default.

128 changes: 128 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
#include "../includes/global.h"

int main(int argc, char *argv[]){
char *inFile = argv[1];
char *outFile = argv[2];

//Upsampler parameters
int scale = 2;

//Compressed Assault Cube
int num = 300; //Number of frames to interpolate
int inCols = 176; //Width of input (downsampled) video
int inRows = 144; //Height of input (downsampled) video

int outCols = inCols*scale;
int outRows = inRows*scale;

FILE *inFp, *outFp;

inFp = fopen(inFile, "rb");
if (inFp == NULL)
{
printf("\n We have null pointer \n");
}
outFp = fopen(outFile, "wb");
if (outFp == NULL)
{
printf("\n We have null pointer \n");
}

// To read and write each frame in an unsigned character format
unsigned char *inBuf = (unsigned char *)malloc(inCols*inRows*sizeof(unsigned char));
unsigned char *outBuf = (unsigned char *)malloc(outCols*outRows*sizeof(unsigned char));
// To work with each pixel in the range of 0~1
double *inBuf_tmp = (double *)malloc(inCols*inRows*sizeof(double));
double *outBuf_tmp = (double *)malloc(outCols*outRows*sizeof(double));

for (int fcnt = 0; fcnt < num; fcnt++)
{
//////// Interpolate each frame using FSRCNN for Y component and simple repitition for U and V components
// Pointer to obtain value of each tpixel of input frame
unsigned char *inP = inBuf;
double *inP_tmp = inBuf_tmp;
// Pointer to obtain value of each pixel of output frame
unsigned char *outP = outBuf;
double *outP_tmp = outBuf_tmp;

//Y Component
fread(inBuf, sizeof(unsigned char), inCols*inRows, inFp);
int i, j;

for (i = 0; i<inRows; i++)
for (j = 0; j<inCols; j++)
{
int cnt = i*inCols + j;
int x = *inP++;
*(inP_tmp + cnt) = (double)(x / 255.0);
}

FSRCNN(outP_tmp, inP_tmp, inRows, inCols, scale);

outP_tmp = outBuf_tmp;

for (i = 0; i<inRows*scale; i++)
for (j = 0; j<inCols*scale; j++)
{
int cnt = i*inCols*scale + j;
*(outP_tmp + cnt) = *(outP_tmp + cnt) * 255;
}


double_to_uint8( outP_tmp, outP, outCols, outRows);

fwrite(outBuf, sizeof(unsigned char), outCols*outRows, outFp);

//U Component
fread(inBuf, sizeof(unsigned char), inCols*inRows / 4, inFp);

inP = inBuf;
outP = outBuf;

for (i = 0; i < inRows / 2; i++)
for (j = 0; j < inCols / 2; j++) {

int cnt = 2 * (i * outCols / 2 + j);

unsigned char x = *inP++;

*(outP + cnt) = x;
*(outP + cnt + 1) = x;
*(outP + cnt + outCols / 2) = x;
*(outP + cnt + outCols / 2 + 1) = x;

}

fwrite(outBuf, sizeof(unsigned char), outCols*outRows / 4, outFp);

// V COmponent
fread(inBuf, sizeof(unsigned char), inCols*inRows / 4, inFp);
inP = inBuf;
outP= outBuf;

for (i = 0; i < inRows / 2; i++)
for (j = 0; j < inCols / 2; j++) {

int cnt = 2 * (i*outCols / 2 + j);

unsigned char x = *inP++;

*(outP + cnt) = x;
*(outP + cnt + 1) = x;
*(outP + cnt + outCols / 2) = x;
*(outP + cnt + outCols / 2 + 1) = x;

}

fwrite(outBuf, sizeof(unsigned char), outCols*outRows / 4, outFp);

}
free(inBuf);
inBuf = NULL;
free(inBuf_tmp);
inBuf_tmp = NULL;
free(outBuf);
outBuf = NULL;
free(outBuf_tmp);
outBuf_tmp = NULL;
}
Binary file added src/main.obj
Binary file not shown.
Loading

0 comments on commit 247572e

Please sign in to comment.