æ¬è³ªçã«ãJNGã¯MNG圢åŒã®ãµãã»ããã§ãïŒãã ããããããŒã«ç¬èªã®ããŒã«ãŒãããããããã®åœ¢åŒã®äž¡æ¹ãåºå¥ã§ããŸãïŒã ã«ã©ãŒããŒã¿ã¯JPEG圢åŒã§ä¿åãããŸãããã¢ã«ãã¡ã¯2ã€ã®ãªãã·ã§ã³ã®ããããã§ä¿åã§ããŸã-ã°ã¬ãŒã¹ã±ãŒã«ã®ç»åã®ããã«JPEGã䜿çšããŠå§çž®ããããPNGãšåãå§çž®ã䜿çšããŠå§çž®ããŸãã
JNGã¯ã©ãã§åœ¹ç«ã¡ãŸããïŒ ç§ã«ãšã£ãŠã¯ãã¢ãã€ã«ã²ãŒã ã§ãã¯ã¹ãã£ã¢ãã©ã¹ãä¿åããã®ã«æé©ã§ããã å°ããªäŸ-ã²ãŒã ã®å ã®ã°ã©ãã£ãã¯ã»ããã®ééã¯57ã¡ã¬ãã€ãã§ããã¹ãŠã®pngãjngã«çœ®ãæããåŸ-ã°ã©ãã£ãã¯ã»ããã®ééã¯15ã¡ã¬ãã€ãã«ãªããŸããã ã¢ãã€ã«ã²ãŒã ã«ãšã£ãŠã¯è¯ãåå©ã§ãã JNGãé©çšã§ããä»ã®é åã®æ€çŽ¢ã«ã€ããŠã¯èªè ã«ãä»»ãããŸãããJNGã€ã¡ãŒãžã®èŠæ¹ãäœææ¹æ³ãããã³ããŒãæ¹æ³ïŒC / C ++ã³ãŒãã®äŸã䜿çšïŒãããã³ãã®æ§é ã«é¢ããå°ãã®çè«ã«ã€ããŠèª¬æããŸãã
JNGç»åã衚瀺ããæ¹æ³ã¯ïŒ
-XnViewïŒhttp://www.xnview.com/ïŒ-ãã©ã°ã€ã³ã®ã€ã³ã¹ããŒã«åŸã«JNGãéãããšãã§ããŸãã
-IrfanViewïŒhttp://www.irfanview.com/ïŒ-ãã©ã°ã€ã³ãå¿ èŠã§ãïŒä»ã®ãã©ãŒããããšäžç·ã«ããã¯ã§æäŸãããŸãïŒã
JNG圢åŒã§ã°ã©ãã£ãã¯ãä¿åããæ¹æ³ã¯ïŒ
ãŸããPhotoshopã®ãã©ã°ã€ã³-download.fyxm.net/JNG-Format-8069.htmlããããŸã ã 圌ã¯ç¹ã«çºéããŠããªãããã§ãããããã§ã圌ã¯ä»äºãããŠããŸãã
第äºã«ãããªãæåãªãªãŒãã³ãœãŒã¹ãŠãŒãã£ãªãã£-ImageMagicïŒhttp://www.imagemagick.orgïŒã䜿çšã§ããŸãã
JNG圢åŒãæ±ã£ãŠãpngãjngã«å€æã§ããåçŽãªã³ã³ããŒã¿ãŒãäœæããŸãã-code.google.com/p/png2jng/downloads/list
ïŒã³ã³ããŒã¿ãŒã¯Windowsçšã«æ§ç¯ãããŠããŸããã<tchar.h>ããã®é¢æ°ã®çœ®ãæãã«é¢ããŠå°ãå¥ãããåŸãä»ã®ãã©ãããã©ãŒã çšã«æ§ç¯ã§ããŸãïŒã
ç§ã®ããã°ã©ã ã®ãã€ãã¹ïŒ
-16ãããpng / jngãçµäºããŸããã§ããïŒãã®ãããªããããã¹ããµããŒãããå¿ èŠã¯ãããŸããã§ããïŒã
-å§çž®åã«ã¢ã«ãã¡ãã£ãã«ããŒã¿ãã£ã«ã¿ãªã³ã°ã䜿çšããªãã§ãã ããã PNGãã£ã«ã¿ãŒã®ãµããŒããè¿œå ãããšãã¢ã«ãã¡ãã£ãã«ã®å§çž®çãåäžããå¯èœæ§ããããŸãã
JNGãããŒãããæ¹æ³ã¯ïŒ
libmng
libmng sourceforge.net/projects/libmngã䜿çšããŸã
é·æïŒ
-ããã¯éåžžã«ããååšããŸãã
-jngã ãã§ãªãã¢ãã¡ãŒã·ã§ã³åãããmngãããŒãã§ããŸãã
-mng / jngç»åãäœæããããã®ã³ãŒãããããŸãã
çæïŒ
-倧ãããŠéãã©ã€ãã©ãª
-ã¢ãã¡ãŒã·ã§ã³çšã«èšèšããããã°ã©ãã£ãã¯ãããŒãããããã®ãããããAPIã
-è¡ã®åçãèªã¿åãããšãã§ããªã;
-èšæ¶ããååã«å€§é£ãã
ãŸããlibmngã«ã¯jpeglibãšzlibãå¿ èŠã§ãã
libmngã䜿çšããããšã«ããå Žå-ããã䜿çšããŠã°ã©ãã£ãã¯ãããŒãããå°ããªäŸã次ã«ç€ºããŸãã
ãµã³ãã«ã®ãœãŒã¹ã³ãŒãå šäœã¯ã code.google.com / p / png2jng / source / browse / trunk / jngdump / jngdump.cpp ïŒpng2jngã®äžéšãšããŠïŒã«ãããŸãã
ããã§éèŠãªãã€ã³ãã«ã€ããŠèª¬æããŸãã
æåã®ã¹ãããã¯ãã©ã€ãã©ãªãåæåããå¿ èŠãªæå°éã®ã³ãŒã«ããã¯ãèšå®ããããšã§ãã
ã€ã¡ãŒãžãããŒãããã®ã«äŸ¿å©ãªããã«ãã³ãŒã«ããã¯ã«ãŠãŒã¶ãŒãã©ã¡ãŒã¿ãŒãæž¡ããããªæ§é ãå®çŸ©ããŸããã
struct mng_info { FILE* file;// mng_uint32 width; mng_uint32 height; mng_uint32 timer; unsigned char* pixels; };
ã ãã-libmngã®åæå
/* , mng_handle. , . â libmng , , ( â calloc, memset ). */ mng_handle hmng; mng_info mngInfo; mng_retcode retCode; hmng = mng_initialize(&mngInfo, mymngalloc, mymngfree, MNG_NULL); /* */ /* */ Mng_setcb_errorproc(hmng, mymngerror); /* . , .*/ mng_setcb_openstream(hmng, mymngopenstream); /* */ mng_setcb_closestream(hmng, mymngclosestream); /* */ mng_setcb_readdata(hmng, mymngreadstream); /* â , , */ mng_setcb_processheader(hmng, mymngprocessheader); /* libmng */ mng_setcb_getcanvasline(hmng, mymnggetcanvasline); /* . , , . â . */ mng_setcb_gettickcount(hmng, mymnggettickcount); /* . , . */ mng_setcb_settimer(hmng, mymngsettimer); /* libmng , . , getcanvasline , .*/ mng_setcb_refresh(hmng, mymngimagerefresh);
ã³ãŒã«ããã¯ã®ãã¡ãããã§æãé¢å¿ã®ãããã®ã®ã¿ã玹ä»ããŸã
/* */ static mng_bool mymngreadstream(mng_handle mng, mng_ptr buffer, mng_uint32 size, mng_uint32 *bytesread) { mng_info *mymng = (mng_info*)mng_get_userdata(mng); *bytesread = fread(buffer, 1, size, mymng->file); return MNG_TRUE; } mng_bool mymngprocessheader (mng_handle hHandle, mng_uint32 iWidth, mng_uint32 iHeight) { mng_info* mngInfo = (mng_info*)mng_get_userdata (hHandle); /* */ if (mng_set_canvasstyle (hHandle, MNG_CANVAS_RGBA8)) { /* */ return MNG_FALSE; } mngInfo->width = iWidth; mngInfo->height = iHeight; mngInfo->image = new unsigned char[iWidth * 4 * iHeight];// return MNG_TRUE; } mng_ptr mymnggetcanvasline(mng_handle hHandle, mng_uint32 iLinenr) { mng_info* mngInfo = (mng_info*)mng_get_userdata (hHandle); /* */ return mngInfo->image + mngInfo-> width * 4 * iLinenr; }
ç»åãããŠã³ããŒãããŸãã
/* .*/ /* mng */ retCode = mng_read(hmng); /* â JNG. MNG*/ if(mng_get_sigtype (hmng) != mng_it_jng) { /* â */ }
ããã§ãå®éã«ãã³ãŒãããããã¯ã»ã«ãååŸããå¿ èŠããããŸãã
ãããŸã§ããã¹ãŠã¯libngãjpeglibãªã©ã®ã©ã€ãã©ãªãããé£æ³ãããŠããŸããã
libmngã¯å ã ã¢ãã¡ãŒã·ã§ã³ç»åçšã«èšèšãããŠããããã次ã«æ ¹æ¬çãªéãããããŸãã
/* mng_display_resume libmng */ retCode = mng_display(hmng); while((retCode == MNG_NEEDTIMERWAIT) && (mngInfo.timer <= 1)) { retCode = mng_display_resume(hmng); } /* â pixels mng_info*/
æ®ã£ãŠããã®ã¯ãlibmngã«ãã£ãŠå²ãåœãŠããããªãœãŒã¹ãã¯ãªã¢ããããšã ãã§ã
mng_cleanup(&hmng);
ã¹ã¬ãããéããããã¡ã¢ãªã解æŸãããããããšãå¿ããªãã§ãã ããã
ã芧ã®ãšãããè€éãªããšã¯äœããããŸããã ããããç§ã®å Žåãlibmngã®æ©èœã®1ã€ãèŽåœçã§ããããšãå€æãããµã€ã¯ãªã³ã°ã«åå ãããããŸããã
å®éããã¯ãã£ããã³ãŒããããšããlibmngã¯ããèªäœã®å éšã«width * bpp * heightã«çãããããã¡ãå²ãåœãŠãŸãã ç§ã®å Žåããã¯ã¹ãã£2048x2048ããã©ãŒããã5551ã«ããŒãããå¿ èŠããããŸãããLibmngèªäœã¯ãã®ãã©ãŒãããããµããŒãããŠããŸããã ãŸãã2048 * 2048 * 4ã®ãããã¡ãŒãå²ãåœãŠãããã«ããŒãããŠããã2ãã€ã圢åŒã«è»¢éããå¿ èŠããããŸããã 32ã¡ã¬ãã€ãã®ãªãŒããŒãããã§ããããšãå€æããŸããïŒããã«ãã¢ãŒã«ã€ãããååŸããããããç»åãã¡ã€ã«èªäœã®ééãå ç®ãããŸãïŒã ããæç¹ã§ãã²ãŒã ã¯åã«ã¡ã¢ãªäžè¶³ã«ãªããŸããã libmngã®éåžžã«æ··ä¹±ããå éšãæãäžããŠãç§ã¯ãã®åé¡ãç°¡åã«å æã§ããªãããšã«æ°ä»ããèã«çœ®ãããšã«ããŸãã-ãããŠãlibmngã®å©ããªãã§ãç¹ã«ãã©ãŒãããèªäœãç¹ã«æãèŠããªãã£ãããããã§èªåã§åçãã¢ããããŒãã§ããªãå Žååæ§ã®ããªãã¯ãè¡ã£ãèšäºããããŸãããïŒæ®å¿µãªããæ¢ã«åé€ãããŠããŸããïŒããã©ãŠã¶ã®ã¿ã§ããã
libjng
ããã§ç§ã¯libjngïŒ code.google.com/p/libjng ïŒãèªçãããŸãã-jngã®ããŒãæ¹æ³ããç¥ããªãã·ã³ãã«ãªã©ã€ãã©ãªã§ãã ã©ã€ãã©ãªã倧ããããŸãã å®éã1ã€ã®ããããŒãã¡ã€ã«ãš1ã€ã®ãã¡ã€ã«ïŒCã®ãœãŒã¹ïŒã§æ§æãããŠããŸãã
é·æïŒ
-䜿ããããAPIã
-ã³ã³ãã¯ã-ããããŒãã¡ã€ã«ãå«ããœãŒã¹-74ãããã€ãïŒããå°ããã€ããªïŒ;
-ããããµã€ãºãå€æŽããã«ã¢ã«ãã¡ãã£ãã«ãããŠã³ããŒãã§ããŸãïŒ5551ãªã©ã®åœ¢åŒã§èªã¿èŸŒãå¿ èŠãããå Žåã«äŸ¿å©ã§ãïŒã
-ãããŠæãéèŠãªããš-libpngãjpeglibã®ããã«ããã¡ã€ã«ã1è¡ãã€ãã³ãŒãã§ããããã«ããŸãã
-ããŒã¿ãè€è£œããããšãªãããããã¡ãŒããçŽæ¥ç»åããã³ãŒãã§ããŸãããŸããã³ãŒã«ããã¯ãèšå®ããããšã«ãããã¹ããªãŒã ãããããã¯ãã¢ã³ããŒãã§ããŸãã
çæïŒ
-ãã£ãã«ããšã«16ãããã§ããŒã¿ãåºåããæ¹æ³ãããããŸããïŒçè«çã«ã¯ãJPEGããµã³ãã«ããšã«12ãããããŸãã¯ã¢ã«ãã¡ã16ãããã«ãªãå Žæã«jngãããŒãããŸã-åäœããã¯ãã§ãïŒ
-ãµãŒãããŒãã£ã®ã©ã€ãã©ãªã«ãäŸå-jpeglibãzlibã
ãªããžããªãŒå ã®ã©ã€ãã©ãªãŒãããå Žæã«ã¯ãjngãããŒãããŠãã¯ã»ã«ãtga圢åŒã«ãã³ãã§ããå°ããªäŸããããŸãïŒããã¯æãåçŽãªã°ã©ãã£ãã¯ã¹åœ¢åŒã§ããããïŒã
libjngã®ç°¡åãªäœ¿çšäŸïŒç»åå šäœãæ¢ã«ã¡ã¢ãªã«ããŒããããŠãããŠãŒã¹ã±ãŒã¹ïŒã
/* */ #include "jng_load.h" /* â */ void* my_jng_alloc(size_t size) { return malloc(size); } void my_jng_free(void* ptr) { free(ptr); } void my_jng_errorproc(jng_handle handle, int errorCode, unsigned long chunkName, unsigned long chunkSeq, const char* erorText) { printf("JNG error %d! chunk = %d, chunkSeq = %d, text = %s\r\n", errorCode, chunkName, chunkSeq, erorText); } /* imageSize â , imageBuffer â */ jng_handle handle; handle = jng_create_from_data(NULL, imageBuffer, imageSize, my_jng_alloc, my_jng_free, my_jng_errorproc, JNG_FLAG_CRC_CRITICAL);/* crc .*/ if(!handle) { /* â , . errorproc */ } /* . , , .*/ if(!jng_read(handle)) { jng_cleanup(handle); /* */ } /* */ imageWidth = jng_get_image_width(handle); imageHeight = jng_get_image_height(handle); /* , */ jng_set_out_alpha_channel_bits(handle, JNG_OUT_BITS_8); jng_set_out_color_channel_bits(handle, JNG_OUT_BITS_8); jng_set_out_color_space(handle, JNG_RGB); jng_set_color_jpeg_src_type(handle, JNG_JPEG_SRC_DEFAULT);/*, 8 12 jpeg â JNG */ /* â () jpeg png, */ if(!jng_start_decode(handle)) { jng_cleanup(handle); /**/ } /* */ colorBytesNum = jng_get_out_color_channel_bytes(handle); alphaBytesNum = jng_get_out_alpha_channel_bytes(handle); colorComponentsCount = jng_get_out_color_components_num(handle); if(!colorBytesNum || !colorComponentsCount) { jng_finish_decode(handle); jng_cleanup(handle); /* ?!*/ } /* bpp , .. * / pixelBytesNum = colorBytesNum * colorComponentsCount + alphaBytesNum; rowPitch = pixelBytesNum * imageWidth; pixelBufferSize = rowPitch * imageHeight;/* */ /* . , , 5551 32 â , . .*/ pixelBuffer = (unsigned char*)malloc(pixelBufferSize);
ç»åã®è¡åäœã®èªã¿åãïŒå®éã«ã¯è¡åäœ-ãªãŒããŒããããã4ã€ãŸãã¯5ã€ã®ãããã¡ããããè²ãšã¢ã«ãã¡ã®è¡ãä¿æã§ããŸãïŒã
unsigned char* imageLinePtr = (unsigned char*)pixelBuffer; for(currentLine = 0; currentLine < imageHeight; currentLine++) { if(!jng_read_scanline(handle, imageLinePtr)) { /* */ readRes = -1; break; } imageLinePtr += rowPitch; } /* */ jng_finish_decode(handle); jng_cleanup(handle); /*That's All, Folks!*/
èŠããã«ããããã©ã®ããã«æ©èœãããã
JNG圢åŒã¯ãMNGãšåæ§ã«ãäžé£ã®ãã£ã³ã¯ïŒããŒã¹ïŒã§æ§æãããŸãã åãã£ã³ã¯ã«ã¯ãããããŒ-4ãã€ã-ããŒã¿ãµã€ãºã4ãã€ã-ã¿ã€ãèå¥åããªãã·ã§ã³ããŒã¿ãããã³4ãã€ãã®çµãã-crcãå«ãŸããŸãã ã芧ã®ãšããããã®ãããªæ§é ãæžç®ããŠè§£æããããšã¯åºæ¬çãªã¿ã¹ã¯ã§ãã
ãã®ãããªãã£ã³ã¯ãå解ããå¿ èŠããããŸãã
JHDR-ãã¡ã€ã«ããããŒ-ç»åã®ãµã€ãºãå§çž®åœ¢åŒããããã¬ãŒããªã©ãèšè¿°ããŸãã
JDAT-ç»åã®è²ããŒã¿ãå«ããã£ã³ã¯ã éåžžã®JPEGïŒ16é²ãšãã£ã¿ã§ãã®ãããã¯ãåå¥ã®ãã¡ã€ã«ã«ããããšãã©ã®ãã¥ãŒã¢ã§ãå®å šã«éãããšãã§ããŸãïŒ;
JSEP-JDATãã£ã³ã¯ã«8ããããš12ãããã®JPEGã€ã¡ãŒãžãåæã«å«ãŸããŠããå ŽåïŒãã®ãããªãã£ã³ã¯ã®éã«ã¯JSEPã®ã¿ã衚瀺ãããŸãããä»ã®ããŒã¿ã¯è¡šç€ºãããŸããïŒãJDATãã£ã³ã¯ãåå²ããŸãã
JDAA-JPEGã§å§çž®ãããã¢ã«ãã¡ãã£ãã«-ãã¹ãŠã¯JDATãšåãã§ãããã°ã¬ãŒã·ã§ãŒãã®8ãããJPEGã¯1ã€ã ãã§ãã
IDATã¯ã¢ã«ãã¡ãã£ãã«ã§ãããPNGã®ãã¯ã»ã«ãããã¯ãããã®ãšåãæ¹æ³ã§ããã¯ãããŸãã
IEND-åçã®çµããã
ããŒã¿ã®è²éšåãšã¢ã«ãã¡ãã£ãã«ã®äž¡æ¹ãããã€ãã®ãã£ã³ã¯ã«åå²ã§ããŸãã ããããé çªã«èªã¿åã£ãŠããŒã¿ãæ¥çããã ãã§ãã
jpegã®ããŒã¿ã䜿çšãããšããã¹ãŠãç°¡åã«ãªããŸããããã§jpeglibãèšå®ããjpeglibãä»ããŠããŒã¿ã1è¡ãã€åé€ããŸãã IDATã¯ããå°ãè€éã§ãã libpngã¯åºå®ããŸããã ããã¯å®å šãªpngã§ã¯ãªããå®éã«ã¯pngã®ãã£ã³ã¯ã®1ã€ã ãã§ãã
IDATã®ããŒã¿èªäœã¯1è¡ãã€ã§ãããzlibã§å§çž®ãããŠããŸãã è¡ã¯ããã£ã«ã¿ãªã³ã°ã®ã¿ã€ãã瀺ããã€ãããŒã«ãŒã§å§ãŸãã次ã«ããŒã¿èªäœã瀺ããŸãã ãããã£ãŠããã³ãŒãã¯ãæååã解åãïŒzlib inflateïŒãæåã®ãã€ãããã§ãã¯ããããããã£ã«ã¿ãªã³ã°ãããšããäºå®ã«åæžãããŸãïŒããã¯ããªã倧ããªãããã¯ã§ãããæ°ã«ãã人-pngrutil.cãã¡ã€ã«ã®pnglibãé¢æ°png_read_filter_rowã®pnglibã®äžã調ã¹ãããšããå§ãããŸãïŒè€æ°ã®ãã¯ã»ã«ãããã¯ãããŸã-ããããå¥ã ã®ãã€ãã«ã¢ã³ããã¯ããå¿ èŠã«å¿ããŠããã€ããŸãã¯ã¯ãŒãã«æ¡åŒµããŸãã
äžéšã®ãã£ã«ã¿ãŒã§ã¯ãåã®è¡ã®ããŒã¿ãå¿ èŠã§ãããããã£ãŠããªãŒããŒãããã¯å¥ã®è¡ã«è¿œå ãããŸãã ãã ãããã£ã«ã¿ãªã³ã°ã¯ãã¯ã»ã«ã§ã¯ãªãããŒã¿ãã€ãã§å®è¡ãããããããã¯ã»ã«ãããã®ãããæ°ã8ãããæªæºã§ããã°ãã¢ã³ããã¯æã®ãªãŒããŒãããã¯å°ãããªããŸãã
ã·ã ãã¹ãŠã®ããã«-ç§ã¯ããã¹ããããªãã«ãšã£ãŠé¢çœããŠæçšã§ãã£ãããšãæã¿ãŸãã èŠããã«ãç§ã¯JNGã䜿çšããããšã®å¿çšé¢ã ãã§ãªãã奜å¥å¿ã®ããã«çè«ã«ãå°ã觊ããŸããã