Skip to content

Instantly share code, notes, and snippets.

View tamarous's full-sized avatar
🎯
Focusing

Tamarous tamarous

🎯
Focusing
View GitHub Profile
@tamarous
tamarous / glErrorChecker.cpp
Created December 28, 2018 03:38
OpenGL error checker
#define glCheckError() glCheckError_(__LINE__)
void glCheckError_(int line) {
GLenum errorCode;
char error[100];
memset(error, 0, sizeof(error));
while ((errorCode = glGetError()) != GL_NO_ERROR) {
switch (errorCode) {
case GL_INVALID_ENUM: sprintf_s(error, "GL_INVALID_ENUM"); break;
case GL_INVALID_VALUE: sprintf_s(error, "GL_INVALID_VALUE"); break;
@tamarous
tamarous / rgb24ToBMP.cpp
Created September 12, 2018 02:55
save RGB24 frame to bmp file.
void rgb24ToBMP(unsigned char *rgbBuffer, int width, int height, const char *bmppath) {
typedef struct {
long imageSize;
long blank;
long startPosition;
} BmpHead;
typedef struct {
long Length;
long width;
@tamarous
tamarous / NV12ToBGR24.cpp
Created September 12, 2018 02:54
Convert NV12 to BGR24 format.
void NV12ToBGR24(uint8_t* pYUV, uint8_t* pBGR24, int width, int height) {
if(width < 1 || height < 1 || pYUV == NULL || pBGR24 == NULL)
return;
const long len = width * height;
unsigned char* yData = pYUV;
unsigned char* vData = &yData[len];
unsigned char* uData = &vData[len >> 2];
int bgr[3];
int yIdx, uIdx, vIdx, idx;
@tamarous
tamarous / quickSort-list.cpp
Created September 9, 2018 16:03
单链表快速排序
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef struct ListNode {
int val;
struct ListNode *next;
ListNode(int val):val(val) {}
@tamarous
tamarous / searchInRotatedArray.cpp
Created September 9, 2018 07:14
在旋转数组中寻找一个数字
class Solution {
public:
int search(vector<int>& nums, int target) {
int size = nums.size();
int low = 0, high = size;
while(low < high) {
int mid = low + (high-low)/2;
if (nums[mid] == target) {
return mid;
}
@tamarous
tamarous / recover.cpp
Created April 27, 2018 13:27
Recover Binary Search Tree
/**
* Definition of TreeNode:
* class TreeNode {
* public:
* int val;
* TreeNode *left, *right;
* TreeNode(int val) {
* this->val = val;
* this->left = this->right = NULL;
* }
@tamarous
tamarous / heap.cpp
Last active April 20, 2018 16:11
Heap Sort-小顶堆实现
#include <iostream>
#include <cstdlib>
/**
* 小顶堆
*/
void heapInsert(int *heap, int n, int num) {
int i, j;
heap[n] = num;
i = n;
j = (n - 1) / 2;
@tamarous
tamarous / search_in_rotated_array.cpp
Last active March 31, 2018 14:44
在一个旋转过的数组中搜索一个数,返回它的索引
class Solution1 {
public:
/**
* @param A: an integer rotated sorted array
* @param target: an integer to be searched
* @return: an integer
*/
int search(vector<int> &A, int target) {
int size = A.size();
if (size == 0) {
@tamarous
tamarous / bitOperation.cpp
Created March 30, 2018 13:51
使用位运算实现两个数的加减乘法
// 加法
int getSum(int a, int b) {
int sum = 0;
while(b != 0) {
sum = a ^ b;
b = (a & b) << 1;
a = sum;
}
return sum;
}
@tamarous
tamarous / travel.cpp
Created March 29, 2018 12:19
Pseudo-code for DFS and BFS.
// DFS
void search(Node root) {
if (root == NULL) {
return;
}
visit(root);
root.visited = true;
foreach (Node n in root.adjacent) {
if (n.visited = false) {
search(n);