#! /bin/sh # # ppmtocamedia -- 画像ファイルを Olympus C-820L 形式に変換 # # Copyright (C) 1998 by Dai ISHIJIMA # # revision history: # 0.0: Aug. 24, 1998 by Dai ISHIJIMA (jpegto820.c) # 0.1: Sep. 14, 1998 by Dai ISHIJIMA # 1.0: Sep. 17, 1998 by Dai ISHIJIMA # # 注1: perl, jpeg-6a (cjpeg, djpeg), pbmplus (netpbm) が必要です # 注2: 640×480ドットの画像にしか対応していません # 注3: デジカメがハングする危険性があります (^^;) # # 使用例: # その1 # % ppmtocamedia foo.ppm > pic00000.jpg # % cp pic00000.jpg /flash/imolym # その2 # % cat hogehoge.gif | ppmtocamedia > /flash/imolym/pic00001.jpg # その3 # % djpeg baa.jpg | pnmscale -width 640 -height 480 | # ppmtocamedia > /flash/imolym/pic00002.jpg # # 参考文献: # JIS X4301-1995「連続階調静止画像のディジタル圧縮及び符号処理」 # jpeg-6a付属ドキュメント ``wizard.doc'' # debug=NO #debug=YES case x$debug in xYES) temp=/tmp/camedia ;; *) temp=/tmp/camedia-$$ ; trap "/bin/rm -f $temp*" 0 1 2 3 5 10 13 15 ;; esac # # とりあえず 2x1 (4:2:2) サンプリングの jpeg に変換する # C-820L は 2x1 サンプリングしかデコードできない(?)ようだ # cat "$@" | cjpeg -sample 2x1,1x1,1x1 > $temp.main.jpg case $? in [^0]) echo "$0: Unknown input file format" 1>&2 ; exit 1 ;; esac # # 寸法チェックとサムネイル画像の下準備 # djpeg -v -v $temp.main.jpg > $temp.main.ppm 2> $temp.diag if ! grep 'width=640, height=480' < $temp.diag > /dev/null ; then echo -n "$0: invalid size: " 1>&2 grep width= $temp.diag 1>&2 exit 1 fi cat << EOF > $temp.qtable ######################################################################## # Define Quantization Table 0 precision 0 3 2 2 3 5 8 10 12 2 2 3 4 5 12 12 11 3 3 3 5 8 11 14 11 3 3 4 6 10 17 16 12 4 4 7 11 14 22 21 15 5 7 11 13 16 21 23 18 10 13 16 17 21 24 24 20 14 18 19 20 22 20 21 20 # Define Quantization Table 1 precision 0 3 4 5 9 20 20 20 20 4 4 5 13 20 20 20 20 5 5 11 20 20 20 20 20 9 13 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ######################################################################## EOF # # サムネイル画像の生成 # pnmscale -width 80 -height 60 < $temp.main.ppm | cjpeg -qtables $temp.qtable -sample 2x1,1x1,1x1 > $temp.thumb.jpg # # ヘッダ書き込み # perl -e ' @header = ( 0xff, 0xd8, 0xff, 0xe0, 0x00, 0x10, 0x4a, 0x46, 0x49, 0x46, 0x00, 0x01, 0x02, 0x01, 0x00, 0x90, 0x00, 0x90, 0x00, 0x00, 0xff, 0xe0, 0x0f, 0xba, 0x4a, 0x46, 0x58, 0x58, 0x00, 0x10, 0xff, 0xd8 ); for ($i = 0; $i < @header; $i++) { printf "%c", $header[$i]; } ' > $temp.result # # サムネイル画像書き込み # perl -e ' $skiplen = 0x14; $thumblen = 0x0fb0; for ($i = 0; $i < $skiplen; $i++) { $ch = getc; } $i = 0; while (($ch = getc) ne "") { print $ch; ++$i; } while ($i < $thumblen) { printf "%c", 0xff; ++$i } ' < $temp.thumb.jpg >> $temp.result # # 撮影時の情報をでっちあげる # size=`wc -c < $temp.main.jpg` perl -e ' $size = $ARGV[0] - 59345 + 59328; print "\xff\xec\x03\xf2"; print "OLYMPUS OPTICAL CO.,LTD. "; print "\x00"; print " 701\r\n"; print "[picture info]\r\n"; print "TimeDate=-1\r\n"; # 日付なし print "Shutter=127125\r\n"; print "Flash=0\r\n"; print "Resolution=1\r\n"; print "Protect=0\r\n"; print "ContTake=0\r\n"; print "ImageSize=640-480\r\n"; print "ColorMode=1\r\n"; print "FNumber=F5.6\r\n"; print "Zoom=x1.0\r\n"; print "Macro=1\r\n"; print "[camera info]\r\n"; print "Type=SR55\r\n"; print "Serial#=#00000001\r\n"; print "Version=v55-76\r\n"; print "ID=OLYMPUS DIGITAL CAMERA\r\n"; print "[diag info]\r\n"; printf "PicLen=%d\r\n", $size; print "ThmLen=4016\r\n"; print "Q=66\r\n"; print "R=268\r\n"; print "B=189\r\n"; print "s0=8253,0,1e848,8cd4,1f095,9997,0,1010000,"; print "11,2d4047d,5c90700,7870732,648353a,109003a,0,0,0,0\r\n"; print "T0=3e7,7,a,2883c,e8,1edd7\r\n"; print "[user]"; print "\xff"; ' $size > $temp.info # # (ニセの) 撮影時の情報書き込み # perl -e ' $infolen = 0x1220 - 0x0fd0; $i = 0; while (($ch = getc) ne "") { print $ch; ++$i; } while ($i < $infolen) { print "\x00"; ++$i; } ' < $temp.info >> $temp.result # # ファイルサイズ他書き込み (このへんはよくわかんない) # perl -e ' $size = $ARGV[0] - 59345 + 59328; print "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"; print " \r\n"; print " \r\n"; print " \r\n"; print " \r\n"; print " \r\n"; print "\x00\x00"; print " "; print "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"; print "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\r\n"; print "[end]\r\n"; print "\x00\x00\x00\x00"; print "[file info]"; print "\x00\xa8\x00\x00\x00\x00\x00\x00\x01x\x00\x00\x00\x00"; print "\xff\xff\xff\xff"; printf "%c%c", ($size >> 24) & 0xff, ($size >> 16) & 0xff; printf "%c%c", ($size >> 8) & 0xff, $size & 0xff; print "\x0f\xb0"; print "\x00\xff"; print "PIC00000JPG"; print " "; ' $size >> $temp.result # # よくわかんない情報生成 # cat << EOF > $temp.unknown ############################################################################## 000012e4 00 01 f0 95 00 01 01 0c 00 80 00 bd |............| 000012f0 00 01 42 00 a2 00 00 00 ff ff ff ff 02 80 01 e0 |..B.............| 00001300 00 01 00 00 00 01 00 00 00 00 82 53 00 00 00 00 |...........S....| 00001310 00 01 e8 48 00 00 8c d4 00 01 f0 95 00 00 99 97 |...H............| 00001320 00 00 00 00 01 01 00 00 00 00 00 11 02 d4 04 7d |...............}| 00001330 05 c9 07 00 07 87 07 32 06 48 35 3a 01 09 00 3a |.......2.H5:...:| 00001340 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 00001350 00 00 03 e7 00 00 00 07 00 00 00 0a 00 02 88 3c |...............<| 00001360 00 00 00 e8 00 01 ed d7 37 33 32 2c 36 34 38 33 |........732,6483| 00001370 35 33 61 2c 31 30 39 30 30 33 61 2c 30 2c 30 2c |53a,109003a,0,0,| 00001380 30 2c 30 0d 0a 54 30 3d 34 32 35 2c 37 2c 61 2c |0,0..T0=425,7,a,| 00001390 32 38 38 33 63 2c 65 38 2c 31 65 64 64 37 0d 0a |2883c,e8,1edd7..| 000013a0 5b 75 73 65 72 5d ff 00 00 00 00 00 00 00 00 00 |[user]..........| 000013b0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 000013c0 00 00 00 00 ############################################################################## EOF # # よくわかんない情報書き込み # perl -ne ' s/[#;|].*$//; # コメント削除 @a = split; $n = @a; for ($i = 1; $i < $n; $i++) { printf "%c", hex($a[$i]); } ' < $temp.unknown >> $temp.result # # 画像本体書き込み # perl -e ' $skiplen = 0x14; for ($i = 0; $i < $skiplen; $i++) { $ch = getc; } while (($ch = getc) ne "") { print $ch; } ' < $temp.main.jpg >> $temp.result cat $temp.result exit 0 # EOF