|
¡û ¤Ï¤¸¤á¤Ë
LECTURE 20 Imlib ¤ò»È¤Ã¤¿²èÁüɽ¼¨ ¤Ç¤Ï¡¢Imlib (freshmeat.net ¤Î¾Ò²ð¥Ú¡¼¥¸) ¤ò»È¤Ã¤¿²èÁüɽ¼¨¤Ë¤Ä¤¤¤Æ¾Ò²ð¤·¤Þ¤·¤¿¡£º£²ó¤Ï¡¢Imlib ¤ÇÆɤ߹þ¤ó¤À²èÁü¥Ç¡¼¥¿¤ò²Ã¹©¤¹¤ë¤Á¤ç¤Ã¤È¤·¤¿²èÁü½èÍý¤Ë¤Ä¤¤¤Æ½ñ¤¤¿¤¤¤È»×¤¤¤Þ¤¹¡£¤Ê¤ª¡¢Ãø¼Ô¤Ï²èÁü½èÍý¤ò¤«¤¸¤Ã¤¿ÄøÅ٤Ǿܤ·¤¯¤Ï¤¢¤ê¤Þ¤»¤ó¤Î¤Ç¡¢¤´Î»¾µ¤¯¤À¤µ¤¤¡°¡°¡¨¾Ü¤·¤¯ÃΤꤿ¤¤¾ì¹ç¤Ï³Æ¼«¤Ç¤ªÄ´¤Ù¤¯¤À¤µ¤¤¡£
¡û Imlib ¤ÇÆɤ߹þ¤ó¤À²èÁü¤ÎÆâÉô¥Ç¡¼¥¿·Á¼°
Imlib ¤ÇÆɤ߹þ¤ó¤À²èÁü¤Ï¡¢ÆâÉôŪ¤Ë¤Ï 24-bit ¥Ô¥¯¥»¥ë¥Ç¡¼¥¿¤Î½¸¹ç¤È¤·¤Æ´ÉÍý¤µ¤ì¤Æ¤¤¤Þ¤¹¡£1 ¥Ô¥¯¥»¥ë¤Ë¤Ä¤ RGB ¤Î½ç¤Ëʤӡ¢¤½¤ì¤¬¥Ô¥¯¥»¥ë¿ôʬ³¤¤Þ¤¹¡ÊRGBRGBRGBRGB...¡Ë¡£¤Ê¤ª RGB ¤½¤ì¤¾¤ì 8 bit ¤º¤Ä¤ÎÃͤȤʤê¤Þ¤¹¡£¤½¤Î¾¤Ë¤âÆ©ÌÀ¿§¤Ë´ØÏ¢¤Å¤¤¤¿¥Ç¡¼¥¿Åù¤¢¤ëÍͤǤ¹¤¬¡¢ËÜ¥Ú¡¼¥¸¤Ç¤Ï²èÁü¤½¤Î¤â¤Î¤òɽ¤¹ RGB ¤ÎÇÛÎó¥Ç¡¼¥¿¤ò½èÍý¤ÎÂоݤȤ·¤Æ¤¤¤Þ¤¹¡£
¡û ¥°¥ì¡¼¥¹¥±¡¼¥ë½èÍý
¥°¥ì¡¼¥¹¥±¡¼¥ë¤È¤Ï¡¢ºÌÅÙ¡Ê¿§¤Î¶¯¤µ¤È¤«¿§¤é¤·¤µ¡Ë¤ò»ý¤¿¤Ê¤¤²èÁü¤Ç¤¹¡£¥«¥é¡¼²èÁü¤«¤é¥°¥ì¡¼¥¹¥±¡¼¥ë²èÁü¤Ø¤ÎÊÑ´¹¤Ë¤Ï¡¢°Ê²¼¤ÎÍͤÊÊýË¡¤¬¤¢¤ë¤ß¤¿¤¤¤Ç¤¹¡Ê¾¤Ë¤â¤¤¤í¤¤¤í¤¢¤ëÍͤǤ¹¤¬¡¢¤½¤ì¤é¤Ë¤Ä¤¤¤Æ¤Ï¤³¤³¤Ç¤Ï¼è¤ê¾å¤²¤Þ¤»¤ó¡Ë¡£¤Ê¤ª¡¢ËÜ¥Ú¡¼¥¸¤Î¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à¤Ç¤Ï¡¢RGB ¤ÎÊ¿¶ÑÃͤòÍѤ¤¤ëÊýË¡¤ò»È¤Ã¤Æ¤¤¤Þ¤¹¡£
ÊýË¡ | ÀâÌÀ |
---|---|
RGB ¤ÎÊ¿¶ÑÃͤòÍѤ¤¤ë | ÊÑ´¹¸å¤ÎÃÍ = (R + G + B)/3 ¤È¤¹¤ëÊýË¡¡£RGB Á´¤Æ¤ÎÀ®Ê¬¤¬Æ±¤¸¤À¤ÈºÌÅÙ 0 ¤È¤Ê¤ë¤³¤È¤òÍøÍѡʤ·¤Æ¤¤¤ë¤é¤·¤¤¡Ë¡£¤³¤ÎÊýË¡¤Ç¤Ï¡¢ÎФÈÀĤÎÊÑ´¹·ë²Ì¤¬¸µ¤Î¿§¤ËÂФ¹¤ë»ë³Ð°õ¾Ý¤È°Û¤Ê¤ë·ë²Ì¤È¤Ê¤ë¤È¤¤¤¦ÌäÂ꤬¤¢¤ë¡Ê¤é¤·¤¤¡Ë¡£¿Í´Ö¤Î»ë³Ð¤ÏÎФε±ÅÙ¤ËÉÒ´¶¤ËÈ¿±þ¤·¡¢ÀĤε±Å٤ˤϤ¢¤Þ¤êÈ¿±þ¤·¤Ê¤¤¤È¤¤¤¦·¹¸þ¤¬¤¢¤ë¤½¤¦¤Ç¤¹¡£ |
½Å¤ßÉդʿ¶Ñ¤òÍѤ¤¤ë | RGB ¤Î¤½¤ì¤¾¤ì¤Ë½Å¤ßÉÕ¤±¤ò¹Ô¤Ã¤ÆÊ¿¶Ñ¤òµá¤á¤ëÊýË¡¡£ÊÑ´¹¸å¤ÎÃÍ = (0.299 * R + 0.587 * G + 0.114 * B) ¤È¤¹¤ëÊýË¡¤Ï¡¢ÆüËܤ䥢¥á¥ê¥«¤Î¥Æ¥ì¥ÓÊüÁ÷µ¬³Ê NTSC ¤Ç»ÈÍѤµ¤ì¤Æ¤¤¤ë¤½¤¦¤Ç¤¹¡£ |
¡û ¥Í¥¬¥Æ¥£¥Ö½èÍý
¥Í¥¬¥Æ¥£¥Ö½èÍý¤È¤Ï¡¢¿§¤ÎÌÀ°Å¤òȿž¤µ¤»¥Õ¥£¥ë¥à¤ÎÍͤʲèÁü¤òÆÀ¤ë½èÍý¤Ç¤¹¡£ËÜ¥Ú¡¼¥¸¤Î¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à¤Ç¤Ï
ÊÑ´¹¸å¤ÎÃÍ = ºÇÂçÃÍ - ÊÑ´¹Á°¤ÎÃÍ
¤È¤¤¤¦ÊýË¡¤ò»È¤Ã¤Æ¤¤¤Þ¤¹¡£
¡û ¥¨¥Ã¥¸¸¡½Ð½èÍý
¥¨¥Ã¥¸¸¡½Ð¤È¤Ï¡¢²èÁüÃæ¤ÎʪÂΤ泦Àþ¤òµá¤á¤ë½èÍý¤Ç¤¹¡£¥³¥ó¥Ô¥å¡¼¥¿¤ÇÍÍ¡¹¤Ê²èÁü½èÍý¡¿²èÁüǧ¼±¤ò¹Ô¤¦¾ì¹ç¡¢¶³¦Àþ¤Ë¤è¤Ã¤ÆʪÂΤòǧ¼±¤·¤¿¤ê¤¹¤ë¤³¤È¤¬½ÐÍè¤ë¤¿¤á¡¢¥¨¥Ã¥¸¸¡½Ð¤ÏÈó¾ï¤Ë½ÅÍפʽèÍý¤È¸À¤¨¤Þ¤¹¡£
²èÁü½èÍýŪ¤Ë¤Ï¡¢¥¨¥Ã¥¸¤ÏÃͤ¬µÞ·ã¤ËÊѲ½¤¹¤ë²Õ½ê¤Ç¤¢¤ë¤È¸À¤¨¤Þ¤¹¡£ÊѲ½Î̤¬Â礤¤¾ì½ê¤ò¸¡½Ð¤¹¤ë¤¿¤á¤Ë¤Ï¡¢°ìÈÌŪ¤ËÈùʬ½èÍý¤ò¹Ô¤¤¤Þ¤¹¡£¥Ç¥¸¥¿¥ë¥Ç¡¼¥¿¤Î¾ì¹ç¡¢Èùʬ½èÍý¤È¤ÏÆó¤Ä¤ÎÃͤκ¹Ê¬¤òµá¤á¤ë¤³¤È¤ò°ÕÌ£¤·¤Þ¤¹¡£Èùʬ½èÍý¤Ë¤Ï 1 ¼¡Èùʬ¤È 2 ¼¡Èùʬ¤¬¤¢¤ê¤Þ¤¹¤¬¡¢¤³¤³¤Ç¤Ï¡ÊÀâÌÀ¤¬¡©¡Ë´Êñ¤Ê 1 ¼¡Èùʬ¤ò¼è¤ê¾å¤²¤Þ¤¹¡£
1 ¼¡Èùʬ½èÍý¤Ç¤Ï¤Þ¤º¡¢³Æ¥Ô¥¯¥»¥ë¤ÈÎÙÀܤ¹¤ë¥Ô¥¯¥»¥ë¤È¤Îº¹Ê¬¤ò x Êý¸þ¡ÊΔx¡Ë¤È y Êý¸þ¡ÊΔy¡Ë¤½¤ì¤¾¤ì¤Ë¤Ä¤¤¤Æµá¤á¡¢ºÇ½ªÅª¤ÊÃͤò
ÊÑ´¹¸å¤ÎÃÍ = sqrt( Δx * Δx + Δy * Δy ); ¢¨sqrt ¤ÏÊ¿Êýº¬¤òɽ¤¹¡£
¤È¤·¤Þ¤¹¡£¤Ê¤ª¡¢¥«¥é¡¼²èÁü¤Ç¤Ï¥Î¥¤¥º¤¬Â¿¤¯¤¦¤Þ¤¯¸¡½Ð¤Ç¤¤Ê¤¤¾ì¹ç¤¬¤¢¤ë¤¿¤á¡¢ÆóÃͲ½¡ÊïçÃͤè¤ê¾å¤Ê¤éÇò¡¢°Ê²¼¤Ê¤é¹õ¤ÎÍͤÊÆóÃͤΤߤΥǡ¼¥¿¡Ë¤·¤¿²èÁü¤ä¥°¥ì¡¼¥¹¥±¡¼¥ë²èÁü¤ò¸µ¤Ë¸¡½Ð¤¹¤ë¤³¤È¤¬Â¿¤¤¤Ç¤¹¡£
ÎÙÀܤ¹¤ë¥Ô¥¯¥»¥ë¤È¤Î·×»»¤òɽ¸½¤¹¤ë¤¿¤á¤Î·¸¿ô¤ÎÁȤòÈùʬ¥ª¥Ú¥ì¡¼¥¿¤È¸Æ¤Ó¡¢
m1 | m2 | m3 |
m4 | m5 | m6 |
m7 | m8 | m9 |
¤ÎÍͤʷÁ¼°¤ÇÄêµÁ¤µ¤ì¤Þ¤¹¡£m5 ¤ÎÉôʬ¤¬Âоݥԥ¯¥»¥ë¤ËÂФ¹¤ë·¸¿ô¤Ç¤¢¤ê¡¢¤½¤ì°Ê³°¤¬ÎÙÀܤ¹¤ë¥Ô¥¯¥»¥ë¤ËÂФ¹¤ë·¸¿ô¤Ç¤¹¡£(x,y) °ÌÃ֤Υԥ¯¥»¥ë¤ò p(x,y) ¤È¤¹¤ë¡Êx ¤Ï²èÁü¤Î±¦Êý¸þ¡¢y ¤Ï²èÁü¤Î²¼Êý¸þ¤òÀµ¤È¤·¤Þ¤¹¡Ë¤È
&Delta = p(x-1,y-1) * m1 + p(x,y-1) * m2 + p(x+1,y-1) * m3 + p(x-1,y) * m4 + p(x,y) * m5 + p(x+1,y) * m6 + p(x-1,y+1) * m7 + p(x,y+1) * m8 + p(x+1,y+1) * m9
¤È¤·¤Æ·×»»¤Ç¤¤Þ¤¹¡£¤Ê¤ª¡¢ÎÙÀÜ¥Ô¥¯¥»¥ë¤¬²èÁü¤Î¶³¦³°¤Ç¤¢¤ë¾ì¹ç¤Ë¤Ï¡¢ºÇ¤â¶á¤¤¶³¦¾å¤Î¥Ô¥¯¥»¥ë¤òÂå¤ï¤ê¤Ë»ÈÍѤ·¤Þ¤¹¡£
1 ¼¡Èùʬ¤ÎºÝ¤Ë¤è¤¯»È¤ï¤ì¤ëÍ̾¤ÊÈùʬ¥ª¥Ú¥ì¡¼¥¿¤Ë Roberts ¥ª¥Ú¥ì¡¼¥¿¡¿Sobel ¥ª¥Ú¥ì¡¼¥¿¤¬¤¢¤ê¤Þ¤¹¡£ËÜ¥Ú¡¼¥¸¤Î¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à¤Ç¤Ï Sobel ¥ª¥Ú¥ì¡¼¥¿¤ò»È¤Ã¤Æ¤¤¤Þ¤¹¡£
- Roberts ¥ª¥Ú¥ì¡¼¥¿
Δx Êý¸þ Δy Êý¸þ 0 0 0 0 0 0 0 1 0 0 0 1 0 0 -1 0 -1 0
- Sobel ¥ª¥Ú¥ì¡¼¥¿
Δx Êý¸þ Δy Êý¸þ 1 0 -1 1 2 1 2 0 -2 0 0 0 1 0 -1 -1 -2 -1
¡û ¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à
²èÁü½èÍý¥Õ¥£¥ë¥¿¤ò¼ÂÁõ¤·¤¿¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à filter.c ¤Ç¤¹¡£¤Ï¤¸¤á¤Ë ¤Î¥Ú¡¼¥¸¤«¤éÁ´¤Æ¤Î¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à¤ò¸Ç¤á¤¿ tar ¥Ü¡¼¥ë¤ò¥À¥¦¥ó¥í¡¼¥É¤¹¤ë¤³¤È¤â¤Ç¤¤Þ¤¹¡£
Á°²ó¤ÈƱ¤¸¤¯¡¢-lImlib ¥ª¥×¥·¥ç¥ó¤ò»ØÄꤷ¤Æ¥³¥ó¥Ñ¥¤¥ë¤·¤Æ¤¯¤À¤µ¤¤¡£
¥³¥ó¥Ñ¥¤¥ë¤ò½ª¤¨¤¿¤é¡¢²èÁü¥Õ¥¡¥¤¥ë̾¤ò°ú¿ô¤ËÍ¿¤¨¤Æ¼Â¹Ô¤·¤Æ¤ß¤Æ¤¯¤À¤µ¤¤¡£²èÁü¤¬É½¼¨¤µ¤ì¤Þ¤¹¡£±¦¤Î¥«¡¼¥½¥ë¥¡¼¤ò²¡¤¹¤È¡¢¥°¥ì¡¼¥¹¥±¡¼¥ë½èÍý¤ò»Ü¤·¤¿²èÁü¤¬É½¼¨¤µ¤ì¤Þ¤¹¡£¾å¤ò²¡¤¹¤È¥Í¥¬¥Æ¥£¥Ö½èÍý¤ò»Ü¤·¤¿²èÁü¤¬¡¢²¼¤ò²¡¤¹¤È¥¨¥Ã¥¸Ãê½Ð½èÍý¤ò»Ü¤·¤¿²èÁü¤¬É½¼¨¤µ¤ì¤Þ¤¹¡£º¸¤ò²¡¤¹¤È¸µ²èÁü¤¬É½¼¨¤µ¤ì¤Þ¤¹¡£Esc ¥¡¼¤ò²¡¤¹¤È½ªÎ»¤·¤Þ¤¹¡£
ËÜ¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à¤Ï¡¢µ¯Æ°»þ¤Ë¸µ²èÁü¤ª¤è¤Ó¥°¥ì¡¼¥¹¥±¡¼¥ë²èÁü¤ò¥á¥â¥ê¾å¤ËÊݸ¤·¤Þ¤¹¡£¤½¤Î¤¿¤á¡¢Â礤ʲèÁüÅù¤òɽ¼¨¤¹¤ë¤È·ë¹½¥á¥â¥ê¤ò¾ÃÈñ¤¹¤ë¤È»×¤¤¤Þ¤¹¡£¥Õ¥£¥ë¥¿½èÍý¤Ë¤ª¤¤¤Æ¤ÏÆä˹⮲½¤È¤«¹Í¤¨¤Æ¤¤¤Ê¤¤¤¿¤á¡¢¥µ¥¤¥º¤¬Â礤¤Äø½èÍý¤Ë»þ´Ö¤¬¤«¤«¤ê¤Þ¤¹¤Î¤Ç¤´Ãí°Õ¤¯¤À¤µ¤¤¡£
¤Þ¤¿¡¢¥¤¥Ù¥ó¥È¥ë¡¼¥×Æâ¤Ç¥¡¼¤ò²¡¤¹¤È¥Õ¥£¥ë¥¿½èÍý¤ò¼Â¹Ô¤·¤Æ·ë²Ì²èÁü¤òɽ¼¨¡Ê¸µ²èÁü¤È¥°¥ì¡¼¥¹¥±¡¼¥ë¤Ï¥¥ã¥Ã¥·¥å¤ò¤½¤Î¤Þ¤Þɽ¼¨¡Ë¤·¤Þ¤¹¤¬¡¢·ë²Ì²èÁü¤òɽ¼¨¤·½ª¤¨¤ë¤Þ¤Ç¥¤¥Ù¥ó¥È½èÍý¤ò¹Ô¤Ã¤Æ¤¤¤Ê¤¤¤¿¤á¡¢¥¦¥£¥ó¥É¥¦¤¬¸Ç¤Þ¤Ã¤¿Íͤˤʤë¤È»×¤¤¤Þ¤¹¡£¤´Î»¾µ¤¯¤À¤µ¤¤¡£GUI ¤È¤·¤Æ¼ÂÍÑŪ¤Ë¤¹¤ë¤¿¤á¤Ë¤Ï¡¢¥Õ¥£¥ë¥¿½èÍýÉô¤òÊÌ¥¹¥ì¥Ã¥É¤È¤·¤Æ¼ÂÁõ¤¹¤ëÅù¤ò¹Í¤¨¤¿Êý¤¬Îɤ¤¤Ç¤·¤ç¤¦¡£
--- ¸µ²èÁü ---
--- ¥°¥ì¡¼¥¹¥±¡¼¥ë½èÍý¸å ---
--- ¥Í¥¬¥Æ¥£¥Ö½èÍý¸å ---
--- ¥¨¥Ã¥¸¸¡½Ð½èÍý¸å ---
¤Ê¤ª¡¢¥µ¥ó¥×¥ë¥×¥í¥°¥é¥àÆâ¤Î process_filter() ´Ø¿ô ( 383 ¡Á 462 ¹ÔÌÜ ) ¤Î 421 ¡Á 461 ¹ÔÌܤϥ³¥á¥ó¥È¥¢¥¦¥È¾õÂ֤ȤʤäƤ¤¤Þ¤¹¤¬¡¢¤³¤Î¤Þ¤Þ¡Êcase1¡Ë¤È 387 ¡Á 419 ¹ÔÌܤò¥³¥á¥ó¥È¥¢¥¦¥È¤·¤Æ 421 ¡Á 461 ¹ÔÌܤò͸ú²½¤·¤¿¾ì¹ç¡Êcase2¡Ë¤Ë¤Ä¤¤¤Æ¡¢1280x1024 ¤Î JPEG ²èÁü¤Î¥¨¥Ã¥¸Ãê½Ð¤Ë¤«¤«¤Ã¤¿»þ´Ö¤ò¼«´Ä¶¤Ç·×¬¤·¤¿·ë²Ì¤ò°Ê²¼¤ËºÜ¤»¤Æ¤ª¤¤Þ¤¹¡£
PentiumIII 450MHz memory 512MB |
Xeon 3.60GHz memory 1GB |
|
---|---|---|
case1 | 5069.06 ms | 707.413 ms |
case2 | 3650.404 | 409.337 ms |
--- filter.c ---
1 #include <X11/Xlib.h> 2 #include <X11/keysym.h> 3 #include <X11/Xutil.h> /* shape.h ¤ÎÁ°¤ËɬÍ× */ 4 #include <X11/extensions/shape.h> /* Shape Extension */ 5 #include <Imlib.h> 6 #include <limits.h> 7 #include <math.h> 8 #include <stdio.h> 9 #include <string.h> 10 #include <sys/time.h> 11 #include <unistd.h> 12 13 14 static Display* display; 15 static Window window; 16 static ImlibData* imlib_data; 17 static ImlibImage* imlib_image; 18 static Pixmap pixmap; 19 static Pixmap mask; 20 static unsigned char* original; 21 static unsigned char* grayscale; 22 static int width; 23 static int height; 24 25 26 static int save_original( void ); 27 static void disable_resize( void ); 28 static void render( void ); 29 static void update_image( void ); 30 static void show_original( void ); 31 static void show_grayscale( void ); 32 static void filter_negative( void ); 33 static void filter_edge( void ); 34 35 static void process_filter( int t_row, int t_col, int* mask, 36 int* delta_r, int* delta_g, int* delta_b ); 37 38 39 int 40 main( int argc, char** argv ) 41 { 42 int screen; 43 44 if ( argc <= 1 ) { 45 fprintf( stderr, "²èÁü¥Õ¥¡¥¤¥ë¤ò»ØÄꤷ¤Æ¤¯¤À¤µ¤¤¡£\n" ); 46 exit(1); 47 } 48 49 display = XOpenDisplay( NULL ); 50 screen = DefaultScreen( display ); 51 52 if ( ( imlib_data = Imlib_init( display ) ) == NULL ) { 53 fprintf( stderr, "Imlib ¤Î½é´ü²½¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£\n" ); 54 XCloseDisplay( display ); 55 exit(1); 56 } 57 58 if ( ( imlib_image = Imlib_load_image( imlib_data, argv[1] ) ) == NULL ) { 59 fprintf( stderr, "²èÁü¤ÎÆɤ߹þ¤ß¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£\n" ); 60 XCloseDisplay( display ); 61 exit(1); 62 } 63 64 width = imlib_image->rgb_width; 65 height = imlib_image->rgb_height; 66 67 if ( save_original() != 0 ) { 68 fprintf( stderr, "¸µ²èÁü¤ÎÊݸ¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£\n" ); 69 Imlib_kill_image( imlib_data, imlib_image ); 70 XCloseDisplay( display ); 71 exit(1); 72 } 73 74 window = XCreateSimpleWindow( 75 display, 76 DefaultRootWindow( display ), 77 width, 78 height, 79 width, 80 height, 81 0, 82 BlackPixel( display, screen ), 83 BlackPixel( display, screen ) 84 ); 85 86 disable_resize(); 87 XSelectInput( display, window, StructureNotifyMask | KeyPressMask ); 88 XMapWindow( display, window ); 89 render(); 90 update_image(); 91 92 while ( 1 ) { 93 int esc_pressed = 0; 94 XEvent event; 95 KeySym key_sym; 96 97 XNextEvent( display, &event ); 98 99 switch ( event.type ) { 100 case KeyPress: 101 XLookupString( &( event.xkey ), 102 NULL, 0, &key_sym, NULL ); 103 104 switch ( key_sym ) { 105 case XK_Left: 106 show_original(); 107 break; 108 109 case XK_Right: 110 show_grayscale(); 111 break; 112 113 case XK_Up: 114 filter_negative(); 115 break; 116 117 case XK_Down: 118 filter_edge(); 119 break; 120 121 case XK_Escape: 122 esc_pressed = 1; 123 break; 124 } 125 126 break; 127 } 128 129 if ( esc_pressed ) { 130 break; 131 } 132 } 133 134 Imlib_free_pixmap( imlib_data, pixmap ); 135 Imlib_kill_image( imlib_data, imlib_image ); 136 free( original ); 137 free( grayscale ); 138 XDestroyWindow( display, window ); 139 XCloseDisplay( display ); 140 return 0; 141 } 142 143 144 static int 145 save_original( void ) 146 { 147 int bufsize = width * height * 3; 148 149 if ( ( original = ( unsigned char* )malloc( bufsize ) ) == NULL ) { 150 return -1; 151 } 152 153 if ( ( grayscale = ( unsigned char* )malloc( bufsize ) ) == NULL ) { 154 free( original ); 155 return -1; 156 } 157 158 memcpy( original, imlib_image->rgb_data, bufsize ); 159 160 /* 161 * ¸µ²èÁü¤ÎÊݸ¤ÈƱ»þ¤Ë¡¢¡Ê¼ç¤Ë¥¨¥Ã¥¸Ãê½Ð¥Õ¥£¥ë¥¿ÍÑ¤Î¡Ë 162 * ¥°¥ì¡¼¥¹¥±¡¼¥ë²èÁü¤òºîÀ®¤·¤Æ¤ª¤¯¡£ 163 */ 164 { 165 int row; 166 int col; 167 int index; 168 int mid; 169 170 unsigned char r; 171 unsigned char g; 172 unsigned char b; 173 174 printf( "Creating grayscale image..." ); 175 fflush( stdout ); 176 177 for ( row = 0; row < height; row ++ ) { 178 for ( col = 0; col < width; col ++ ) { 179 index = ( row * width + col ) * 3; 180 181 r = imlib_image->rgb_data[ index + 0 ]; 182 g = imlib_image->rgb_data[ index + 1 ]; 183 b = imlib_image->rgb_data[ index + 2 ]; 184 185 mid = ( int )( ( r + g + b ) / 3 ); 186 187 grayscale[ index + 0 ] = ( unsigned char )mid; 188 grayscale[ index + 1 ] = ( unsigned char )mid; 189 grayscale[ index + 2 ] = ( unsigned char )mid; 190 } 191 } 192 193 printf( "done.\n" ); 194 fflush( stdout ); 195 } 196 197 return 0; 198 } 199 200 201 static void 202 disable_resize( void ) 203 { 204 XSizeHints hints; 205 206 hints.min_width = width; 207 hints.min_height = height; 208 hints.max_width = width; 209 hints.max_height = height; 210 hints.flags = PMinSize | PMaxSize; 211 212 XSetWMNormalHints( display, window, &hints ); 213 } 214 215 216 static void 217 render( void ) 218 { 219 Imlib_render( imlib_data, imlib_image, width, height ); 220 pixmap = Imlib_move_image( imlib_data, imlib_image ); 221 mask = Imlib_move_mask( imlib_data, imlib_image ); 222 } 223 224 225 static void 226 update_image( void ) 227 { 228 XSetWindowBackgroundPixmap( display, window, pixmap ); 229 230 if ( mask ) { 231 XShapeCombineMask( display, window, 232 ShapeBounding, 0, 0, mask, ShapeSet ); 233 } 234 235 XClearWindow( display, window ); 236 XSync( display, False ); 237 } 238 239 240 static void 241 show_original( void ) 242 { 243 memcpy( imlib_image->rgb_data, original, width * height * 3 ); 244 Imlib_free_pixmap( imlib_data, pixmap ); 245 Imlib_changed_image( imlib_data, imlib_image ); 246 render(); 247 update_image(); 248 } 249 250 251 static void 252 show_grayscale( void ) 253 { 254 memcpy( imlib_image->rgb_data, grayscale, width * height * 3 ); 255 Imlib_free_pixmap( imlib_data, pixmap ); 256 Imlib_changed_image( imlib_data, imlib_image ); 257 render(); 258 update_image(); 259 } 260 261 262 static void 263 filter_negative( void ) 264 { 265 int row; 266 int col; 267 int rgb; 268 int index; 269 270 printf( "Processing negative filter..." ); 271 fflush( stdout ); 272 273 for ( row = 0; row < height; row ++ ) { 274 for ( col = 0; col < width; col ++ ) { 275 for ( rgb = 0; rgb < 3; rgb ++ ) { 276 index = ( row * width + col ) * 3 + rgb; 277 imlib_image->rgb_data[ index ] = 278 UCHAR_MAX - original[ index ]; 279 } 280 } 281 } 282 283 printf( "done.\n" ); 284 fflush( stdout ); 285 286 Imlib_free_pixmap( imlib_data, pixmap ); 287 Imlib_changed_image( imlib_data, imlib_image ); 288 render(); 289 update_image(); 290 } 291 292 293 #define TIMER_DIFF( diff, end, start ) { \ 294 (diff)->tv_usec = (end)->tv_usec - (start)->tv_usec; \ 295 if ( (diff)->tv_usec < 0 ) {\ 296 (diff)->tv_usec += 1000000; \ 297 (diff)->tv_sec = (end)->tv_sec - (start)->tv_sec - 1;\ 298 }\ 299 else {\ 300 (diff)->tv_sec = (end)->tv_sec - (start)->tv_sec;\ 301 }\ 302 if ( (diff)->tv_sec < 0 ) {\ 303 (diff)->tv_sec = (diff)->tv_usec = 0;\ 304 }\ 305 } 306 307 static void 308 filter_edge( void ) 309 { 310 /* Sobel Operator (X) */ 311 int mask_x[] = { 312 1, 0, -1, 313 2, 0, -2, 314 1, 0, -1 315 }; 316 317 /* Sobel Operator (Y) */ 318 int mask_y[] = { 319 1, 2, 1, 320 0, 0, 0, 321 -1, -2, -1 322 }; 323 324 int rx; 325 int gx; 326 int bx; 327 int ry; 328 int gy; 329 int by; 330 331 int r; 332 int g; 333 int b; 334 335 int row; 336 int col; 337 int index; 338 339 struct timeval start; 340 struct timeval end; 341 struct timeval diff; 342 343 printf( "Processing edge filter..." ); 344 fflush( stdout ); 345 gettimeofday( &start, NULL ); 346 347 for ( row = 0; row < height; row ++ ) { 348 for ( col = 0; col < width; col ++ ) { 349 process_filter( row, col, mask_x, &rx, &gx, &bx ); 350 process_filter( row, col, mask_y, &ry, &gy, &by ); 351 352 r = ( int )sqrt( ( double )( rx * rx + ry * ry ) ); 353 g = ( int )sqrt( ( double )( gx * gx + gy * gy ) ); 354 b = ( int )sqrt( ( double )( bx * bx + by * by ) ); 355 356 index = ( row * width + col ) * 3; 357 358 imlib_image->rgb_data[ index + 0 ] = 359 ( r > UCHAR_MAX ) ? UCHAR_MAX : r; 360 361 imlib_image->rgb_data[ index + 1 ] = 362 ( g > UCHAR_MAX ) ? UCHAR_MAX : g; 363 364 imlib_image->rgb_data[ index + 2 ] = 365 ( b > UCHAR_MAX ) ? UCHAR_MAX : b; 366 } 367 } 368 369 gettimeofday( &end, NULL ); 370 TIMER_DIFF( &diff, &end, &start ); 371 printf( "done ( %ld ).\n", diff.tv_sec * 1000000 + diff.tv_usec ); 372 fflush( stdout ); 373 374 Imlib_free_pixmap( imlib_data, pixmap ); 375 Imlib_changed_image( imlib_data, imlib_image ); 376 render(); 377 update_image(); 378 } 379 380 381 #define INDEX( row, col ) ( ( (row) * width + (col) ) * 3 ) 382 383 static void 384 process_filter( int t_row, int t_col, int* mask, 385 int* delta_r, int* delta_g, int* delta_b ) 386 { 387 int s_row; 388 int s_col; 389 int index; 390 int m_index; 391 int i; 392 int j; 393 394 *delta_r = 0; 395 *delta_g = 0; 396 *delta_b = 0; 397 398 for ( i = -1; i <= 1; i ++ ) { 399 s_row = t_row + i; 400 s_row = ( s_row < 0 ) ? 0 : 401 ( ( s_row >= height ) ? height - 1 : s_row ); 402 403 for ( j = -1; j <= 1; j ++ ) { 404 s_col = t_col + j; 405 s_col = ( s_col < 0 ) ? 0 : 406 ( ( s_col >= width ) ? width - 1 : s_col ); 407 408 index = s_row * width + s_col; 409 m_index = ( i + 1 ) * 3 + ( j + 1 ); 410 411 ( *delta_r ) += ( int )( 412 grayscale[ index * 3 + 0 ] * mask[ m_index ] ); 413 414 ( *delta_g ) += ( int )( 415 grayscale[ index * 3 + 1 ] * mask[ m_index ] ); 416 417 ( *delta_b ) += ( int )( 418 grayscale[ index * 3 + 2 ] * mask[ m_index ] ); 419 } 420 } 421 #if 0 422 int r0 = ( t_row - 1 < 0 ) ? 0 : t_row - 1; 423 int r1 = t_row; 424 int r2 = ( t_row + 1 >= height ) ? height - 1 : t_row + 1; 425 int c0 = ( t_col - 1 < 0 ) ? 0 : t_col - 1; 426 int c1 = t_col; 427 int c2 = ( t_col + 1 >= width ) ? width - 1 : t_col + 1; 428 429 *delta_r = 430 grayscale[ INDEX( r0, c0 ) + 0 ] * mask[0] + 431 grayscale[ INDEX( r0, c1 ) + 0 ] * mask[1] + 432 grayscale[ INDEX( r0, c2 ) + 0 ] * mask[2] + 433 grayscale[ INDEX( r1, c0 ) + 0 ] * mask[3] + 434 grayscale[ INDEX( r1, c1 ) + 0 ] * mask[4] + 435 grayscale[ INDEX( r1, c2 ) + 0 ] * mask[5] + 436 grayscale[ INDEX( r2, c0 ) + 0 ] * mask[6] + 437 grayscale[ INDEX( r2, c1 ) + 0 ] * mask[7] + 438 grayscale[ INDEX( r2, c2 ) + 0 ] * mask[8]; 439 440 *delta_g = 441 grayscale[ INDEX( r0, c0 ) + 1 ] * mask[0] + 442 grayscale[ INDEX( r0, c1 ) + 1 ] * mask[1] + 443 grayscale[ INDEX( r0, c2 ) + 1 ] * mask[2] + 444 grayscale[ INDEX( r1, c0 ) + 1 ] * mask[3] + 445 grayscale[ INDEX( r1, c1 ) + 1 ] * mask[4] + 446 grayscale[ INDEX( r1, c2 ) + 1 ] * mask[5] + 447 grayscale[ INDEX( r2, c0 ) + 1 ] * mask[6] + 448 grayscale[ INDEX( r2, c1 ) + 1 ] * mask[7] + 449 grayscale[ INDEX( r2, c2 ) + 1 ] * mask[8]; 450 451 *delta_b = 452 grayscale[ INDEX( r0, c0 ) + 2 ] * mask[0] + 453 grayscale[ INDEX( r0, c1 ) + 2 ] * mask[1] + 454 grayscale[ INDEX( r0, c2 ) + 2 ] * mask[2] + 455 grayscale[ INDEX( r1, c0 ) + 2 ] * mask[3] + 456 grayscale[ INDEX( r1, c1 ) + 2 ] * mask[4] + 457 grayscale[ INDEX( r1, c2 ) + 2 ] * mask[5] + 458 grayscale[ INDEX( r2, c0 ) + 2 ] * mask[6] + 459 grayscale[ INDEX( r2, c1 ) + 2 ] * mask[7] + 460 grayscale[ INDEX( r2, c2 ) + 2 ] * mask[8]; 461 #endif 462 } 463 464 465 /* End of filter.c */
¡û ¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à¤ÎÀâÌÀ
¤Ç¤Ï¡¢¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à¤Ë¤Ä¤¤¤ÆÀâÌÀ¤·¤Æ¤¤¤¤Þ¤¹¡£Imlib ¤Ë¤è¤ë²èÁüÆɤ߹þ¤ß¡¿É½¼¨Åù¤Ë¤Ä¤¤¤Æ¤Ï¡¢LECTURE 20 Imlib ¤ò»È¤Ã¤¿²èÁüɽ¼¨ ¤ò´ðËܤȤ·¤Æ¤¤¤Þ¤¹¤Î¤Ç¡¢¤½¤Á¤é¤ò»²¾È¤·¤Æ¤¯¤À¤µ¤¤¡£
- 20 ¡Á 21 ¹ÔÌÜ
original ¤ª¤è¤Ó grayscale ¤Ï¡¢¤½¤ì¤¾¤ì¸µ²èÁü¤ª¤è¤Ó¥°¥ì¡¼¥¹¥±¡¼¥ë½èÍý¸å¤Î²èÁü¥Ç¡¼¥¿¤òÊÝ»ý¤¹¤ë¤¿¤á¤ÎÎΰè¤òÊݸ¤¹¤ë¤¿¤á¤ÎÊÑ¿ô¤Ç¤¹¡£
- 39 ¡Á 141 ¹ÔÌÜ ( main() )
filter.c ¤Î main ´Ø¿ô¤Ç¤¹¡£³Æ½èÍý¤Ë¤Ä¤¤¤Æ°Ê²¼¤ÇÀâÌÀ¤·¤Æ¤¤¤¤Þ¤¹¡£
- 67 ¡Á 72 ¹ÔÌÜ
save_original() ¤È¤¤¤¦¼«ºî´Ø¿ô¤Ç¡¢Imlib ¤ÇÆɤ߹þ¤ó¤À¸µ²èÁü¥Ç¡¼¥¿¤ÎÊݸ¤ª¤è¤Ó¥°¥ì¡¼¥¹¥±¡¼¥ë½èÍý¸å¤Î²èÁü¥Ç¡¼¥¿¤ÎÊݸ¤ò¹Ô¤Ã¤Æ¤¤¤Þ¤¹¡£¾Ü¤·¤¯¤Ï¸åÄøÀâÌÀ¤·¤Þ¤¹¡£
- 86 ¹ÔÌÜ
´Êñ¤Î¤¿¤á¡¢disable_resize() ¤È¤¤¤¦¼«ºî´Ø¿ô¤Ç¥¦¥£¥ó¥É¥¦¥µ¥¤¥º¤òÊѹ¹¤Ç¤¤Ê¤¯¤·¤Æ¤¤¤Þ¤¹¡£¾Ü¤·¤¯¤Ï¸åÄøÀâÌÀ¤·¤Þ¤¹¡£
- 105 ¡Á 107 ¹ÔÌÜ
º¸¥«¡¼¥½¥ë¥¡¼¤¬²¡¤µ¤ì¤¿»þ¤Î½èÍý¤Ç¤¹¡£show_original() ¤È¤¤¤¦¼«ºî´Ø¿ô¤Ç¸µ²èÁü¤Îɽ¼¨¤ò¹Ô¤Ã¤Æ¤¤¤Þ¤¹¡£¾Ü¤·¤¯¤Ï¸åÄøÀâÌÀ¤·¤Þ¤¹¡£
- 109 ¡Á 111 ¹ÔÌÜ
±¦¥«¡¼¥½¥ë¥¡¼¤¬²¡¤µ¤ì¤¿»þ¤Î½èÍý¤Ç¤¹¡£show_grayscale() ¤È¤¤¤¦¼«ºî´Ø¿ô¤Ç¥°¥ì¡¼¥¹¥±¡¼¥ë½èÍý¸å¤Î²èÁü¤òɽ¼¨¤·¤Æ¤¤¤Þ¤¹¡£¾Ü¤·¤¯¤Ï¸åÄøÀâÌÀ¤·¤Þ¤¹¡£
- 113 ¡Á 115 ¹ÔÌÜ
¾å¥«¡¼¥½¥ë¥¡¼¤¬²¡¤µ¤ì¤¿»þ¤Î½èÍý¤Ç¤¹¡£filter_negative() ¤È¤¤¤¦¼«ºî´Ø¿ô¤Ç¥Í¥¬¥Æ¥£¥Ö½èÍý¸å¤Î²èÁü¤òɽ¼¨¤·¤Æ¤¤¤Þ¤¹¡£¾Ü¤·¤¯¤Ï¸åÄøÀâÌÀ¤·¤Þ¤¹¡£
- 117 ¡Á 119 ¹ÔÌÜ
²¼¥«¡¼¥½¥ë¥¡¼¤¬²¡¤µ¤ì¤¿»þ¤Î½èÍý¤Ç¤¹¡£filter_edge() ¤È¤¤¤¦¼«ºî´Ø¿ô¤Ç¥¨¥Ã¥¸¸¡½Ð½èÍý¸å¤Î²èÁü¤òɽ¼¨¤·¤Æ¤¤¤Þ¤¹¡£¾Ü¤·¤¯¤Ï¸åÄøÀâÌÀ¤·¤Þ¤¹¡£
- 134 ¡Á 137 ¹ÔÌÜ
Imlib_free_pixmap() ¤Ë¤è¤Ã¤Æ Pixmap ¤ò²òÊü¤·¤¿¸å¡¢Imlib_kill_image() ¤ò»È¤Ã¤Æ ImlibImage ¹½Â¤ÂΤò²òÊü¤·¤Æ¤¤¤Þ¤¹¡£¹¹¤Ë¡¢Êݸ¤·¤Æ¤ª¤¤¤¿¸µ²èÁü¤ª¤è¤Ó¥°¥ì¡¼¥¹¥±¡¼¥ë²èÁü¥Ç¡¼¥¿¤ò²òÊü¤·¤Æ¤¤¤Þ¤¹¡£
- 144 ¡Á 198 ¹ÔÌÜ ( save_original() )
ËÜ´Ø¿ô¤Ç¤Ï¡¢Imlib ÆâÉô¤Ë³ÊǼ¤µ¤ì¤Æ¤¤¤ë¸µ²èÁü¥Ç¡¼¥¿¤ÎÊݸ¤ª¤è¤Ó¡¢¥°¥ì¡¼¥¹¥±¡¼¥ë½èÍý¸å¤Î²èÁü¥Ç¡¼¥¿¤ÎÊݸ¤ò¹Ô¤¤¤Þ¤¹¡£¸µ²èÁü¥Ç¡¼¥¿¤Ï¸µ²èÁüɽ¼¨ÍѤª¤è¤Ó¥Í¥¬¥Æ¥£¥Ö½èÍýÍѤˡ¢¥°¥ì¡¼¥¹¥±¡¼¥ë²èÁü¥Ç¡¼¥¿¤Ï¥°¥ì¡¼¥¹¥±¡¼¥ë²èÁüɽ¼¨ÍѤª¤è¤Ó¥¨¥Ã¥¸Ãê½Ð½èÍýÍѤËÊݸ¤·¤Æ¤¤¤Þ¤¹¡£
149 ¡Á 151 ¹ÔÌܤǸµ²èÁü¥Ç¡¼¥¿ÊݸÍѤΥá¥â¥êÎΰè¤ò¡¢153 ¡Á 156 ¹ÔÌܤǥ°¥ì¡¼¥¹¥±¡¼¥ë²èÁü¥Ç¡¼¥¿ÊݸÍѤΥá¥â¥êÎΰè¤ò³ÎÊݤ·¤Æ¤¤¤Þ¤¹¡£Imlib ÆâÉô¤Ç¤Ï 1 ¥Ô¥¯¥»¥ë 24 ¥Ó¥Ã¥È¤Ç´ÉÍý¤µ¤ì¤Æ¤¤¤ë¤¿¤á¡¢Éý * ¹â¤µ * 3 ¥Ð¥¤¥È¤Î¥á¥â¥êÎΰè¤ò³ÎÊݤ·¤Æ¤¤¤Þ¤¹¡£
158 ¹ÔÌܤǡ¢Imlib ÆâÉô¤Î¸µ²èÁü¥Ç¡¼¥¿¤ò³ÎÊݤ·¤¿¥á¥â¥êÎΰè¤ËžÁ÷¤·¤Æ¤¤¤Þ¤¹¡£¸µ²èÁü¥Ç¡¼¥¿¤Ï
ImlibImage* image; unsigned char* image->rgb_data;
¤È¤·¤Æ»²¾È¤Ç¤¤Þ¤¹¡£
160 ¡Á 195 ¹ÔÌܤǥ°¥ì¡¼¥¹¥±¡¼¥ë²èÁü¤ò³ÎÊݤ·¤¿¥á¥â¥êÎΰè¤ËºîÀ®¤·¤Æ¤¤¤Þ¤¹¡£Á°½Ò¤Î¥°¥ì¡¼¥¹¥±¡¼¥ë½èÍý¤ÎÀâÌÀÄ̤ꡢ³Æ¥Ô¥¯¥»¥ë¤Ë¤Ä¤¤¤Æ RGB ¤ÎÊ¿¶ÑÃÍ ( 185 ¹ÔÌܤΠmid ) ¤ò·×»»¤·¡¢¤½¤ÎÃͤò grayscale ¾å¤ÇÂбþ¤¹¤ë¥Ô¥¯¥»¥ë¤Î RGB Á´¤Æ¤ËÀßÄꤷ¤Æ¤¤¤Þ¤¹¡£
- 201 ¡Á 213 ¹ÔÌÜ ( disable_resize() )
LECTURE 13 ¥¦¥£¥ó¥É¥¦¥Þ¥Í¡¼¥¸¥ã¤È¤Î¤ä¤ê¤È¤ê ¤ÇÀâÌÀ¤·¤Æ¤¤¤ëÊýË¡¤ò»È¤Ã¤Æ¡¢¥¦¥£¥ó¥É¥¦¥µ¥¤¥º¤ÎÊѹ¹¤òÉԲĤȤ·¤Æ¤¤¤Þ¤¹¡£
- 240 ¡Á 248 ¹ÔÌÜ ( show_original() )
¸µ²èÁü¤Îɽ¼¨¤ò¹Ô¤¦´Ø¿ô¤Ç¤¹¡£original ¤ËÊݸ¤·¤Æ¤ª¤¤¤¿¸µ²èÁü¥Ç¡¼¥¿¤ò ImlibImage ¤Î rgb_data ¤ËžÁ÷¤·¤Þ¤¹¡£rgb_data ¤òľÀܲù©¤¹¤ë¾ì¹ç¡¢Imlib_changed_image() ¤ò¼Â¹Ô¤·¤Æ Imlib ¤ËÊѹ¹¤òÄÌÃΤ¹¤ëɬÍפ¬¤¢¤ê¤Þ¤¹¡£
void Imlib_changed_image( ImlibData* id, ImlibImage* image );
¤¢¤È¤Ï Imlib_free_pixmap() ¤Ë¤è¤Ã¤Æ´û¸¤Î Pixmap ¤ò²òÊüÂоݤȤ·¡¢render()¡¿update_image() ¤Ç Pixmap ¤ÎÀ¸À®¡¿²èÁü¤Îɽ¼¨¤ò¹Ô¤¤¤Þ¤¹¡£render() ¤È update_image() ¤Ë¤Ä¤¤¤Æ¤Ï LECTURE 20 Imlib ¤ò»È¤Ã¤¿²èÁüɽ¼¨ ¤ò»²¾È¤·¤Æ¤¯¤À¤µ¤¤¡£
- 251 ¡Á 259 ¹ÔÌÜ ( show_grayscale() )
¥°¥ì¡¼¥¹¥±¡¼¥ë²èÁü¤Îɽ¼¨¤ò¹Ô¤¦´Ø¿ô¤Ç¤¹¡£original ¤ÎÂå¤ï¤ê¤Ë grayscale ¤ò»²¾È¤·¤Æ¤¤¤ë°Ê³°¤Ï show_original() ¤ÈƱ¤¸¤Ç¤¹¡£
- 262 ¡Á 290 ¹ÔÌÜ ( filter_negative() )
¥Í¥¬¥Æ¥£¥Ö½èÍý¤ò¹Ô¤¤·ë²Ì²èÁü¤òɽ¼¨¤¹¤ë´Ø¿ô¤Ç¤¹¡£273 ¡Á 281 ¹ÔÌܤˤª¤¤¤Æ¡¢Á°½Ò¤Î¥Í¥¬¥Æ¥£¥Ö½èÍý¤ÎÀâÌÀÄ̤ê
ÊÑ´¹¸å¤ÎÃÍ = ÃͤκÇÂçÃÍ - ÊÑ´¹Á°¤ÎÃÍ
¤ò·×»»¤·¤Æ¿·¤·¤¤ÃͤȤ·¤Æ¤¤¤Þ¤¹¡£RGB ¤½¤ì¤¾¤ì unsigned char ¤È¤·¤Æ°·¤¦¤¿¤á¡¢³ÆÍ×ÁǤκÇÂçÃÍ¤Ï UCHAR_MAX ( limits.h ) ¤Ç¤¹¡£
ÊÑ´¹½ªÎ»¸å¤Î 286 ¡Á 289 ¹ÔÌÜ¤Ï show_original()/show_grayscale() ¤ÈƱ¤¸¤Ç¤¹¡£
- 293 ¡Á 305 ¹ÔÌÜ ( TIMER_DIFF() )
filter_edge() Æâ¤Ç½êÍÑ»þ´Ö¤òɽ¼¨¤·¤¿¤¤¤¿¤á¤ËÍÑ°Õ¤·¤¿¥Þ¥¯¥í¤Ç¤¹¡£struct timeval ·¿ÊÑ¿ô¤Ç¤¢¤ë start ¤È end ´Ö¤Î·Ð²á»þ´Ö¤ò·×»»¤·¤Æ¡¢Æ±¤¸¤¯ struct timeval ·¿ÊÑ¿ô¤Î diff ¤Ë³ÊǼ¤·¤Æ¤¤¤Þ¤¹¡£
- 307 ¡Á 378 ¹ÔÌÜ ( filter_edge() )
¥¨¥Ã¥¸¸¡½Ð½èÍý¤ò¹Ô¤¦´Ø¿ô¤Ç¤¹¡£310 ¡Á 322 ¹ÔÌÜ¤Ç xy Êý¸þ¤Î Sobel ¥ª¥Ú¥ì¡¼¥¿¤òÄêµÁ¤·¤Æ¤¤¤Þ¤¹¡£347 ¡Á 367 ¹ÔÌÜ¤Ë¤Æ xy Êý¸þ¤Îº¹Ê¬¤ò·×»»¤·¡¢¿·¤·¤¤Ãͤò
ÊÑ´¹¸å¤ÎÃÍ = sqrt( Δx * Δx + Δy * Δy );
¤È¤·¤ÆÀßÄꤷ¤Æ¤¤¤Þ¤¹¡£xy Êý¸þ¤Îº¹Ê¬·×»»¤Ï¼ÂºÝ¤Ë¤Ï process_filter() ¤È¤¤¤¦¼«ºî´Ø¿ô¤Ç¹Ô¤Ã¤Æ¤¤¤Þ¤¹¡£
ÊÑ´¹¸å¤Î 374 ¡Á 377 ¹ÔÌÜ¤Ï show_original()/show_grayscale()/filter_negative() ¤ÈƱ¤¸¤Ç¤¹¡£
- 383 ¡Á 462 ¹ÔÌÜ ( process_fileter() )
xy Êý¸þ¤Îº¹Ê¬¤ò¼ÂºÝ¤Ë·×»»¤¹¤ë´Ø¿ô¤Ç¤¹¡£
- 387 ¡Á420 ¹ÔÌÜ
Sobel ¥ª¥Ú¥ì¡¼¥¿¤ÎŬÍѤò¥ë¡¼¥×¤Ç½èÍý¤·¤Æ¤¤¤Þ¤¹¡£°ú¿ô¤Î t_row,t_col ¤¬º¹Ê¬·×»»ÂоݤǤ¢¤ë¥Ô¥¯¥»¥ë¤Î¹Ô¤ª¤è¤ÓÎó¤òɽ¤·¤Æ¤¤¤Þ¤¹¡£¥ª¥Ú¥ì¡¼¥¿¤Ï 3x3 ¤Î¹ÔÎó¤Ç¤¹¤¬¡¢i ¤Î¥ë¡¼¥×¤Ç¥ª¥Ú¥ì¡¼¥¿¤Î¹ÔÊý¸þ¡¢j ¤Î¥ë¡¼¥×¤Ç¥ª¥Ú¥ì¡¼¥¿¤ÎÎóÊý¸þ¤ò½èÍý¤·¤Æ¤¤¤Þ¤¹¡£i,j ¤È¥ª¥Ú¥ì¡¼¥¿¤Î³ÆÍ×ÁǤÎÂбþ¤Ï°Ê²¼¤ÎÍͤˤʤê¤Þ¤¹¡£
m1(i=-1,j=-1) m2(i=-1,j=0) m3(i=-1,j=1) m4(i=0,j=-1) m5(i=0,j=0) m6(i=0,j=1) m7(i=1,j=-1) m8(i=1,j=0) m9(i=1,j=1)
- 421 ¡Á 461 ¹ÔÌÜ
387 ¡Á 420 ¹ÔÌܤνèÍý¤Ç¤Ï¼«Ê¬¤Î´Ä¶¤Ç¤¢¤Þ¤ê¤Ë¤âÃÙ¤«¤Ã¤¿¤¿¤á¡¢¥ë¡¼¥×¤Ç¤Ï¤Ê¤¯Ä¾ÀÜ·×»»¤¹¤ë¥³¡¼¥É¤â½ñ¤¤¤Æ¤ß¤Þ¤·¤¿¡£´Ä¶¤Ë±þ¤¸¤¿·×»»Â®Å٤ΰ㤤¤Ë¤Ä¤¤¤Æ¤Ï ¤³¤Á¤é ¤Î¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à¤ÎľÁ°¤Ë·ÇºÜ¤·¤Æ¤¢¤ê¤Þ¤¹¡£·ë¹½°ã¤¤¤Þ¤¹¡£¤¿¤À¤· Zeon 3.60GHz ¤À¤ÈÂδ¶Åª¤Ë¤Ï¤¢¤Þ¤êº¹¤¬¤¢¤ê¤Þ¤»¤ó¤Ç¤·¤¿¤¬¡Ä
°Ê¾å¤Ç filter.c ¤Ë¤Ä¤¤¤Æ¤ÎÀâÌÀ¤Ï½ª¤ï¤ê¤Ç¤¹¡£·ë¹½ÌÌÇò¤¤¤Î¤Ç¡¢¿§¡¹¤Ê²èÁü¤Ç¤¼¤Ò»î¤·¤Æ¤ß¤Æ¤¯¤À¤µ¤¤¡£