Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .cproject
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
<option id="com.ti.ccstudio.buildDefinitions.C6000_7.4.compilerID.OTHER_FLAGS.1361031337" name="Other flags" superClass="com.ti.ccstudio.buildDefinitions.C6000_7.4.compilerID.OTHER_FLAGS" valueType="stringList">
<listOptionValue builtIn="false" value=""/>
</option>
<option id="com.ti.ccstudio.buildDefinitions.C6000_7.4.compilerID.KEEP_ASM.1570084957" superClass="com.ti.ccstudio.buildDefinitions.C6000_7.4.compilerID.KEEP_ASM" value="true" valueType="boolean"/>
<option id="com.ti.ccstudio.buildDefinitions.C6000_7.4.compilerID.KEEP_ASM.1570084957" name="Keep the generated assembly language (.asm) file (--keep_asm, -k)" superClass="com.ti.ccstudio.buildDefinitions.C6000_7.4.compilerID.KEEP_ASM" value="true" valueType="boolean"/>
<inputType id="com.ti.ccstudio.buildDefinitions.C6000_7.4.compiler.inputType__C_SRCS.1050805964" name="C Sources" superClass="com.ti.ccstudio.buildDefinitions.C6000_7.4.compiler.inputType__C_SRCS"/>
<inputType id="com.ti.ccstudio.buildDefinitions.C6000_7.4.compiler.inputType__CPP_SRCS.1842487531" name="C++ Sources" superClass="com.ti.ccstudio.buildDefinitions.C6000_7.4.compiler.inputType__CPP_SRCS"/>
<inputType id="com.ti.ccstudio.buildDefinitions.C6000_7.4.compiler.inputType__ASM_SRCS.1400598400" name="Assembly Sources" superClass="com.ti.ccstudio.buildDefinitions.C6000_7.4.compiler.inputType__ASM_SRCS"/>
Expand Down
26 changes: 7 additions & 19 deletions include/madlad.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,19 @@
* @file madlad.h
* @author Atlanswer (atlanswer@gmail.com)
* @brief Matrix laboratory, but writes as MADLAD.
* @version 0.2
* @date 2020-12-26
* @version 0.3
* @date 2020-12-27
*
* @copyright Copyright (c) 2020
*
*/

#include <stdio.h>
#include <stdlib.h>
#include <file.h>
#include "debug.h"

#ifndef _MADLAD_H_
#define _MADLAD_H_

/**
* @brief File access permission
* @see https://man7.org/linux/man-pages/man2/open.2.html
*/
#define S_IRWXU 00700
#define S_IRUSR 00400
#define S_IWUSR 00200

/**
* @brief Buffers.
* Matrix size: 352 * 288 = 101376
Expand All @@ -34,20 +24,18 @@
*
*/
enum { H_ROW = 4, H_COL = 4,
MATSIZE = 352 * 288,
S_ROW = MATSIZE / 4,
LCOUNT = S_ROW / 4};
extern unsigned char src[S_ROW][H_COL];
MATSIZE = 352 * 288,
S_ROW = MATSIZE / 4,
LCOUNT = S_ROW / 4};
extern short src[S_ROW][H_COL];
extern short buf[H_ROW][H_COL];
extern short dst[S_ROW][H_COL];
// Transformation matrix
extern const char H[H_ROW][H_COL];
extern const short H[H_ROW][H_COL];
// Transform
void transform(void);
// Helper functions
void parseYUV(const char* restrict const YUVPATH);
void writeYUV(const char* restrict const YUVPATH);
void printMATs(const short MAT[][H_COL], unsigned rows);
void printMATuc(unsigned char const MAT[][H_COL], unsigned rows);

#endif /** _MADLAD_H_ **/
44 changes: 11 additions & 33 deletions src/madlad.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* @file madlad.c
* @author Atlanswer (atlanswer@gmail.com)
* @brief Optimized matrix operation.
* @version 0.2
* @date 2020-12-26
* @version 0.3
* @date 2020-12-27
*
* @copyright Copyright (c) 2020
*
Expand All @@ -13,17 +13,10 @@
#include "madlad.h"
#endif /** _MADLAD_H_ **/

void debugPrintf(const char *fmt, ...) {
va_list args;
va_start(args, fmt);
vfprintf(stderr, fmt, args);
va_end(args);
}

unsigned char src[S_ROW][H_COL] = {0};
short src[S_ROW][H_COL] = {0};
short buf[H_ROW][H_COL] = {0};
short dst[S_ROW][H_COL] = {0};
const char H[H_ROW][H_COL] = {
const short H[H_ROW][H_COL] = {
{1, 1, 1, 1},
{2, 1, -1, -2},
{1, -1, -1, 1},
Expand Down Expand Up @@ -60,9 +53,14 @@ void parseYUV(const char* restrict const YUVPATH) {
perror("[parseYUV] Failed to open the YUV file.");
exit(EXIT_FAILURE);
}
char* buffer = (char*) src[0];
short* restrict buffer = (void*) src;
setvbuf(fYUV, NULL, _IOFBF, MATSIZE);
int bytesRead = fread(buffer, 1, MATSIZE, fYUV);
int bytesRead = 0, i;
unsigned char buf;
for (i = 0; i < MATSIZE; ++i) {
bytesRead += fread(&buf, 1, 1, fYUV);
buffer[i] = (short) buf;
}
printf("[parseYUV] %d bytes read.\n", bytesRead);
// Close file.
int status = fclose(fYUV);
Expand All @@ -89,23 +87,3 @@ void writeYUV(const char* restrict const YUVPATH) {
exit(EXIT_FAILURE);
}
}

void printMATs(const short MAT[][H_COL], unsigned rows) {
unsigned r, c;
for (r = 0; r < rows; ++r) {
for (c = 0; c < 4; ++c) {
printf("%d\t", MAT[r][c]);
}
printf("\n");
}
}

void printMATuc(unsigned char const MAT[][H_COL], unsigned rows) {
unsigned r, c;
for (r = 0; r < rows; ++r) {
for (c = 0; c < 4; ++c) {
printf("%X\t", MAT[r][c]);
}
printf("\n");
}
}