Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

iOSアプリ上でGIFのループ回数をいい感じに解釈する

iOSアプリでGIFアニメーションを再生してみたところ、PCのブラウザ上でのループ再生回数と異なるケースがあることがわかりました。PCのブラウザ上で動作するWebアプリケーションと同等のGIFループ再生機能を提供したかったので、なぜループ再生回数が違うのか調査し、その違いを吸収することを試みました。

具体的な事象としては、ブラウザで表示すると1回アニメーションするGIFのループ回数が、kCGImagePropertyGIFLoopCount を使ってGIFファイル中のループ回数を取得すると0が返ってきていました。 UIImageViewのanimationRepeatCountではrepeat count == 0は無限ループを意味し、このまま解釈するとiOS上では無限ループしてしまい、ブラウザと同様に再生できません。

Netscape Looping Application Extensionをどう解釈するか

GIFのフォーマットについて調べてみると、GIF内にはNetscape Looping Application Extension (GIF Unofficial Specification)という領域があり、ここにGIFのループ回数が記されていることがわかりました。

  • [Netscape Looping Application Extension (GIF Unofficial Specification) - vurdalakov.net](http://w
@koyachi
koyachi / private_fork.md
Created July 17, 2018 00:14 — forked from 0xjac/private_fork.md
Create a private fork of a public repository

The repository for the assignment is public and Github does not allow the creation of private forks for public repositories.

The correct way of creating a private frok by duplicating the repo is documented here.

For this assignment the commands are:

  1. Create a bare clone of the repository. (This is temporary and will be removed so just do it wherever.)

git clone --bare git@github.com:usi-systems/easytrace.git

@koyachi
koyachi / scrape.dart
Last active April 7, 2018 01:09 — forked from kui/scrape.dart
a web scraping script with Dart and html
import 'dart:io';
import 'dart:async';
import 'package:html/parser.dart';
import 'package:html/dom.dart';
main() {
final url = 'http://comic-walker.com/';
getHtml(url).then((document) {
print(document.querySelector('title').text);
document.querySelectorAll('#mainContent > li h2 span').forEach((e) {
@koyachi
koyachi / introducing-mint.md
Created December 9, 2017 05:35
Swift Package Managerを使って作成したコマンドをMintでインストールする

Swift Package Managerを使って作成したコマンドをMintでインストールする

[Mint][1]はSwift Package Managerで作成したコマンドラインツールのインストール、実行、配布を簡単にすることを目的としたツールです。 Homebrewでのformula管理の煩わしさの無さ、同一コマンドをバージョン指定で実行可能というところが売りのようです。

ここでは簡単なコマンドラインツールをSwift Package Managerで作成し、Mintで実行する流れを確認します。 SPMでCLIツールを作る手順を既に知ってる場合は「Mintをインストール」から確認するとよいでしょう。

#!/bin/bash
# via https://github.com/koyachi/diff_pdf_image/blob/master/diff_pdf_image.rb
# before
image_b=$1
# after
image_a=$2
function to_gray {
convert $1 -type GrayScale $1.gray.png
echo '花村太郎' | mecab | cut -f2 | cut -d "," -f8 | ./saygaijin
echo '花村太郎' | mecab | cut -f2 | cut -d "," -f8 | paste -d " " - - -
# => ハナムラ タロウ EOS
@koyachi
koyachi / organ2.go
Last active December 15, 2015 06:08
package main
import (
"github.com/koyachi/go-asynth"
"github.com/koyachi/go-baudio"
"math"
)
func main() {
s := asynth.New(func(note asynth.Note, t float64) float64 {
package main
// Usage:
// % go run wstail.go a.txt
// or
// % go build wstail.go
// % wstail a.txt
import (
"code.google.com/p/go.net/websocket"
package main
// Usage:
// % tail -f a.txt | go run wstail.go
import (
"code.google.com/p/go.net/websocket"
"fmt"
"io"
"net/http"