Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Goにおける画像ファイル処理 / golang.tokyo #19

Harukasan
November 13, 2018

Goにおける画像ファイル処理 / golang.tokyo #19

ImageFlux
Goにおける画像ファイル処理
Golang.Tokyo #19 Talks.2 / 2018-11-03

Harukasan

November 13, 2018
Tweet

More Decks by Harukasan

Other Decks in Technology

Transcript

  1. (Pחֶֽ׷歗⫷ؿ؋؎ٕⳢ椚 )BSVLBTBO.*$)**4IVOTVLF QJYJW*OD HPMBOHUPLZPˋ Gopher images were created by Takuya

    Ueda (https://twitter.com/tenntenn). Licensed under the Creative Commons 3.0 Attributions license.
  2. JNBHF*NBHF type Image interface { // ը૾ͷΧϥʔϞσϧΛฦ͢ ColorModel() color.Model //

    ը૾ͷBoundsΛฦ͢ Bounds() Rectangle // (x, y)ϐΫηϧͷ৭Λฦ͢ɻAt(0,0)͸Ұ൪ࠨ্ɺ
 // At(Bounds().Max.X-1, Bounds().Max.Y-1)͸Ұ൪ӈԼΛฦ͢ɻ At(x, y int) color.Color } 歗⫷ر٦ةⰟ鸐ך؎ٝة٦ؿؑ٦أ "U Y Z ׾欽ְ׷ֿהדծぐ歗稆ך葿׾《䖤דֹ׷ DPMPS$PMPSכ3(#葿瑞꟦ח㢌䳔׃ג葿׾《䖤דֹ׷
  3. JNBHF:$C$S type YCbCr struct { Y, Cb, Cr []uint8 YStride

    int CStride int SubsampleRatio YCbCrSubsampleRatio Rect Rectangle } :ծ$Cծ$S׉׸׊׸ךꂁ⴨ח؝ٝه٦طٝز׀הךر٦ةָろת׸גְ׷ 1MBOFS 
 :$C$S4VCTBNQMF3BUJPכ؟ـ؟ٝفؚٔٝ嫰׾㹀纏ׅ׷ Y Y Y Y Y Y Y Y 0 … Y Y Y Cb Cb Cb Cb Cb Cb Cb 0 0 … Cb Cb Cb Cr Cr Cr Cr Cr Cr Cr 0 0 … Cr Cr Cr :4USJEF $4USJEF
  4. JNBHF/3(#" type NRGBA struct { Pix []uint8 Stride int Rect

    Rectangle } 3(#"ָ♧אךꂁ⴨ח鑥׭׵׸גְ׷ 1BDLFE3(#"  3(#"ה/3(#"ך麩ְכ1SFNVMUJQMJFE"MQIBה/PO1SFNVMUJQMJFE"MQIBך麩ְ RGBA R G B A R G B A 0 0 R G B … 4USJEF
  5. 歗⫷غحؿ؋הأزٓ؎س R G B A R G B A R

    G B A R G B A 0 0 R G B A R G B A R G B A R G B A 0 0 R G B A R G B A R G B A R G B A 0 0 R G B A R G B A R G B A R G B A 0 0 R G B A R G B A R G B A R G B A 0 0 R G B A R G B A R G B A R G B A 0 0 R G B A R G B A R G B A R G B A 0 0 R G B A R G B A R G B A R G B A 0 0 8JEUI 4USJEF 歗⫷غحؿ؋כ剑黝⻉ך׋׭4USJEF؟؎ؤד،ٓ؎ًٝٝزׁ׸גְ׷ Y Z ָ妜׃ְהֹכ1JY< Z3FDU.JO: 4USJEF  Y3FDU.JO9 >
  6. JNBHFVY4DBO-JOF3FBEFS type ScanLineReader interface { io.Closer // Config returns the

    configurations of the image planes. Config() *Config // ReadScanLines reads scan lines into the p for each image component. it // reads up to len(p[0]) at once and returns number of bytes read and any // error. When the image is YCbCr 4:2:0, // ReadScanLines(p) returns // p[0]: read scan lines of the Y component. // p[1]: read scan lines of the Cb component. // p[2]: read scan lines of the Cr component. // // ReadScanLines returns an error in the same manner of io.Reader. ReadScanLines(ctx context.Context, p [][]byte) (n int, err error) // ReadLen returns the minimum buffer length that needs to read from this. ReadLen() (n int) }
  7. 3FBE4DBO-JOFT 㛇劤涸חכ如⯋ꂁ⴨ח䭁䓸׃׋JP3FBEFS ؝ٝذؗأز׾欽ְג铣׫鴥׫ךة؎ي،ؐزծٍؗٝإָٕדֹ׷ // ReadScanLines reads scan lines into the

    p for each image component… ReadScanLines(ctx context.Context, p [][]byte) (n int, err error) p[0]: Y Y Y Y Y Y Y Y … p[1]: Cb Cb Cb Cb Cb Cb Cb Cb … p[2]: Cr Cr Cr Cr Cr Cr Cr Cr … +1&(%FDPEFS p[0]: R G B A R G B A … 1/(%FDPEFS
  8. JPEG PNG GIF WebP RGB Compositing Scaling Clipping Color Converter

    JPEG PNG GIF WebP 4DBO-JOF3FBEFS׾㹋鄲׃׋؝ٝه٦طٝز ׾אזֺさ׻ׇ׷ +1&(׾+1&(ךתתٔ؟؎ؤׅ׷הֹכ葿瑞 ꟦ך㢌䳔כ遤׻זְ ٥
  9. JPEG PNG GIF WebP RGB Compositing Scaling Clipping Color Converter

    JPEG PNG GIF WebP 4DBO-JOF3FBEFS׾㹋鄲׃׋؝ٝه٦طٝز ׾אזֺさ׻ׇ׷ +1&(׾+1&(ךתתٔ؟؎ؤׅ׷הֹכ葿瑞 ꟦ך㢌䳔כ遤׻זְ ػ؎فٓ؎ٝך穄畭כ♧菙涸זJP3FBEFSծ JP8SJUFSד㹋鄲ׁ׸גְ׷ךדծIUUQ$MJFOU װIUUQ3FTQPOTF8SJUFSהאזּֿהד歗⫷㢌 䳔فٗؗء׾⡲׷ֿהָדֹ׷ ٥ ٥ IUUQ$MJFOU IUUQ3FTQPOTF8SJUFS
  10. JPEG PNG GIF WebP RGB Compositing Scaling Clipping Color Converter

    JPEG PNG GIF WebP 4DBO-JOF3FBEFS׾㹋鄲׃׋؝ٝه٦طٝز ׾אזֺさ׻ׇ׷ ؔ٦غ٦ٖ؎さ䧭׾遤ֲꥷכ3(#葿瑞꟦ח㢌 䳔׃גַ׵さ䧭׾遤ֲ ٥
  11. *NBHF'MVYחֶֽ׷歗⫷㢌䳔 ˖ ػ؎فٓ؎ٝⳢ椚ח״׏גغحؿ؋؟؎ؤ׾剑㼭⻉דֹ׷ ˖ 歗⫷ؿ؋؎ٕךر؝٦سծؒٝ؝٦سחכ垥彊涸ז$ٓ؎ـٓٔ׾欽ְ׷
 MJCKQFHUVSCPծMJCQOHծHJJCזו ˖ 葿瑞꟦ך㢌䳔ծؔ٦غ٦ٖ؎さ䧭כأٍؗٝٓ؎ٝ׀החתה׭ג遤ֲ
 1MBO،إٝـٔ׾欽ְג4*.%剑黝⻉ ˖

    *NBHF'MVYך椚䟝ـٓؐؠָ邌爙דֹ׷歗⫷כׅץג㢌䳔דֹ׷
 垥彊鋉呓ה׃ג姻׃ֻג׮ـٓؐؠכ姻׃ֻ䪔׻זְֿהָ֮׷
 㸣Ⰻח㠨׸׋歗⫷ד׮ـٓؐؠכז׿ַ姻׃ֻ邌爙׃ג׃תֲֿהָ֮׷ ˖ ؕٓ٦فٗؿ؋؎ٕזו歗⫷ر٦ة⟃㢩׮䪔ֲֿהָדֹ׷