Created
November 30, 2016 20:17
-
-
Save luctrudeau/91bf2bd9aefddc03d23aec0d24387818 to your computer and use it in GitHub Desktop.
TF Experiment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <png.h> | |
#include "dct.h" | |
#include "vidinput.h" | |
#include "intra.h" | |
void luma2png(char *filename, od_coeff *luma, int width, int height) { | |
int y; | |
FILE *fp = fopen(filename, "wb"); | |
if(!fp) abort(); | |
png_structp png = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); | |
if (!png) abort(); | |
png_infop info = png_create_info_struct(png); | |
if (!info) abort(); | |
if (setjmp(png_jmpbuf(png))) abort(); | |
png_init_io(png, fp); | |
// Output is 8bit depth, RGBA format. | |
png_set_IHDR( | |
png, | |
info, | |
width, height, | |
8, | |
PNG_COLOR_TYPE_GRAY, | |
PNG_INTERLACE_NONE, | |
PNG_COMPRESSION_TYPE_DEFAULT, | |
PNG_FILTER_TYPE_DEFAULT | |
); | |
png_write_info(png, info); | |
// To remove the alpha channel for PNG_COLOR_TYPE_RGB format, | |
// Use png_set_filler(). | |
//png_set_filler(png, 0, PNG_FILLER_AFTER); | |
png_bytep *row_pointers = (png_bytep*)malloc(sizeof(png_bytep) * height); | |
for(int y = 0; y < height; y++) { | |
row_pointers[y] = (png_byte*)malloc(png_get_rowbytes(png,info)); | |
} | |
for (int y = 0; y < height; y++) { | |
for (int x = 0; x < width; x++) { | |
row_pointers[y][x] = luma[y * width + x]; | |
} | |
} | |
png_write_image(png, row_pointers); | |
png_write_end(png, NULL); | |
for(int y = 0; y < height; y++) { | |
free(row_pointers[y]); | |
} | |
free(row_pointers); | |
fclose(fp); | |
} | |
int main(int _argc,char **_argv) { | |
// Open Y4M | |
FILE *fin = fopen(_argv[1], "rb"); | |
video_input vid; | |
video_input_info info; | |
video_input_open(&vid,fin); | |
video_input_get_info(&vid,&info); | |
video_input_ycbcr f; | |
int ret1=video_input_fetch_frame(&vid,f,NULL); | |
const int height = info.pic_h; | |
const int width = info.pic_w; | |
const int block_size = 8; | |
const int block_square = block_size * block_size; | |
const int image_square = height * width; | |
od_coeff block[block_square]; | |
od_coeff *dct_image = (od_coeff*) malloc(sizeof(od_coeff)* image_square); | |
od_coeff *tf_image = (od_coeff*) malloc(sizeof(od_coeff)* image_square); | |
od_coeff *idct_image = (od_coeff*) malloc(sizeof(od_coeff)* image_square); | |
for (int y = 0; y < height; y += block_size) { | |
for (int x = 0; x < width; x += block_size) { | |
for (int by = 0; by < block_size; by++) { | |
int fy = by + y; | |
// Copy pixels 8 bit pixels into a block of 32 bit coeff. | |
for (int bx = 0; bx < block_size; bx++) { | |
int fx = bx + x; | |
block[by * block_size + bx] = f[0].data[fy * width + fx]; | |
} | |
} | |
// 8x8 Transform | |
od_bin_fdct8x8(&dct_image[y * width + x], width, block, block_size); | |
} | |
} | |
for (int y = 0; y < height; y += 16) { | |
int row = y * width; | |
for (int x = 0; x < width; x += 16) { | |
od_tf_up_hv_lp(&tf_image[row + x], width, &dct_image[row + x], width, | |
block_size, block_size, block_size); | |
od_bin_idct16x16(&idct_image[row + x], width, &tf_image[row + x], width); | |
} | |
} | |
luma2png("tf_experiment.png", idct_image, width, height); | |
free(dct_image); | |
free(tf_image); | |
free(idct_image); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is image I get. Some white artefacts are present