Skip to content

Instantly share code, notes, and snippets.

@yohhoy
yohhoy / huffman1.py
Last active April 17, 2017 16:06
Huffman encode PGM image
#!/usr/bin/env python3
import math
import sys
from operator import itemgetter
pgmfile = sys.argv[1]
with open(pgmfile, 'rb') as f:
# parse PGM header
f.readline()
@yohhoy
yohhoy / hevcdec.java
Created August 5, 2017 17:24
render "single I-frame HEVC bitstream" with MediaCodec decoder
package jp.yohhoy.hevcdec;
import android.app.Activity;
import android.content.Context;
import android.media.MediaCodec;
import android.media.MediaFormat;
import android.os.Bundle;
import android.util.Log;
import android.util.Size;
import android.view.Surface;
@yohhoy
yohhoy / heic2hevc.cpp
Created August 12, 2017 07:16
convert HEIC file to H.265 bitstream(Annex.B)
/*
* heic2hevc.cpp -- convert HEIC file to H.265 bitstream(Annex.B)
* Copyright(c) 2017 yohhoy
*
* depends https://github.com/nokiatech/heif
*/
#include <iostream>
#include "hevcimagefilereader.hpp"
int extract(const char* srcfile, const char* dstfile)
*********** NAL UNIT (VPS) ***********
0 forbidden_zero_bit u(1) : 0
1 nal_unit_type u(6) : 32
2 nuh_layer_id u(6) : 0
3 nuh_temporal_id_plus1 u(3) : 1
=========== Video Parameter Set ===========
4 vps_video_parameter_set_id u(4) : 0
5 vps_base_layer_internal_flag u(1) : 1
6 vps_base_layer_available_flag u(1) : 1
7 vps_max_layers_minus1 u(6) : 0
@yohhoy
yohhoy / output.s
Created November 15, 2017 13:01
std::string_view constructor and UDL (g++7.1 -std=c++1z -O1)
.LC0:
.string "ABCDEFGHIJKLMNOP"
main:
subq $8, %rsp
movl $16, %edi
movl $.LC0, %esi
call sink(std::basic_string_view<char, std::char_traits<char> >)
movl $16, %edi
movl $.LC0, %esi
call sink(std::basic_string_view<char, std::char_traits<char> >)
@yohhoy
yohhoy / premium_fri.cpp
Last active April 14, 2018 12:03
listing next "Premium Friday" (last friday in month) with C++20 Standard Library.
#include <chrono>
#include <iostream>
using namespace std::chrono;
year_month_day premium_friday(year y, month m)
{
return sys_days{y/m/Friday[last]};
}
@yohhoy
yohhoy / av1-codec.md
Last active August 14, 2019 09:50
AV1 video codec memorandum

AV1 coding scheme

  • Arithmetic coding
    • multi-symbols (up to 16 values)
    • Coefficients coding: lv_map
    • CDF: Cumulative distribution function
      • CDF update (at the end of frame)
      • CDF update (adaptive per symbol)
  • Image blocking
@yohhoy
yohhoy / jls10-var.txt
Created April 1, 2018 13:43
var x = new ArrayList<>();
>>
15.9. Class Instance Creation Expressions
A class instance creation expression is a poly expression (§15.2) if it uses the diamond form for type arguments to the class, and it appears in an assignment context or an invocation context (§5.2, §5.3). Otherwise, it is a standalone expression.
We say that a class is instantiated when an instance of the class is created by a class instance creation expression. Class instantiation involves determining the class to be instantiated (§15.9.1), the enclosing instances (if any) of the newly created instance (§15.9.2), and the constructor to be invoked to create the new instance (§15.9.3).
<<
>>
15.9.1. Determining the Class being Instantiated
@yohhoy
yohhoy / sleepsort.cpp
Created April 11, 2018 08:44
"Sleep Sort" implementation with C++ Coroutines TS
#include <condition_variable>
#include <chrono>
#include <iostream>
#include <mutex>
#include <thread>
#include <utility>
#include <vector>
#include <experimental/coroutine>
@yohhoy
yohhoy / delayqueue.cpp
Last active July 29, 2023 14:59
C++ delay queue - unbound blocking queue with delay of element deque (like Java's java.util.concurrent.DelayQueue)
// delayqueue.cpp -- C++ delay queue
// Copyright (c) 2018 yohhoy
//
// Boost Software License, Version 1.0
// https://www.boost.org/LICENSE_1_0.txt
#include <chrono>
#include <condition_variable>
#include <mutex>
#include <utility>
#include <vector>