#ifndef JDECAPP_HPP_ #define JDECAPP_HPP_ #include "classes.hpp" #include "fstream.hpp" #include "jdecoder.hpp" #include "pixels.hpp" /////////////////////////////////////////////////////////////////////////////// class JDecForm : public MainForm { Pixels pix_; protected: //! coerrided void doPaint( PAINTSTRUCT *ps ) { if (! pix_.pixels) return; BITMAPINFOHEADER bmi = { sizeof( BITMAPINFOHEADER ), pix_.getWidth(), pix_.getHeight(), 1, // WORD biPlanes pix_.getDepth(), BI_RGB, 0, // DWORD biSizeImage 0, // LONG biXPelsPerMeter 0, // LONG biYPelsPerMeter 0, // DWORD biClrUsed 0 // DWORD biClrImportant }; int r = ::SetDIBitsToDevice ( ps->hdc, 0, 0, pix_.getWidth(), pix_.getHeight(), 0, 0, 0, pix_.getHeight(), pix_.pixels, (CONST BITMAPINFO *)&bmi, DIB_RGB_COLORS ); if (r == 0) { static char buf[256]; printf( "SetDIBitsToDevice error %d\n", ::GetLastError() ); setCaption( buf ); //MessageBox( windowHandle, buf, "error", 0 ); } } //! overrided void doDropFiles( HDROP hDrop ) { static char cap[256]; unsigned char *image = 0; char filename[256]; ::DragQueryFile( hDrop, 0, filename, 255 ); try { unsigned char *line_ptr; int line_size; FileInputStream fis( filename ); JPEG::Decoder jpeg( &fis ); sprintf( cap, "展開中 %d x %d, %d bit(s)", jpeg.getWidth(), jpeg.getHeight(), jpeg.getDepth() ); setCaption( cap) ; pix_.setSize( jpeg.getWidth(), jpeg.getHeight() ); line_size = pix_.getBPL(); if (jpeg.getBPL() < line_size) line_size = jpeg.getBPL(); int y = 0; while ( (y = jpeg.getScanLine( (void**)&line_ptr )) >= 0 ) { if (pix_.scanPixel( y )) memcpy( pix_.scanPixel( y ), line_ptr, line_size ); if (((y + 1) & 0xf) == 0) update(); } sprintf( cap, "%d x %d, %d bit(s)", jpeg.getWidth(), jpeg.getHeight(), jpeg.getDepth() ); } catch(const char *e) { strcpy( cap, "エラー" ); puts( e ); } catch(...) { strcpy( cap, "エラー" ); puts( "exception!" ); } setCaption( cap ); update(); ::DragFinish( hDrop ); } public: bool create( int x, int y, int w, int h ) { if (MainForm::create( x, y, w, h )) { ::DragAcceptFiles( windowHandle, TRUE ); return true; } return false; } }; /////////////////////////////////////////////////////////////////////////////// class JDecApplication : public Application { protected: bool initialize( LPSTR cline, int showCmd ) { mainForm = new JDecForm(); if (! mainForm->create( 10, 10, 400, 300 )) return false; mainForm->show( showCmd ); return true; } public: JDecForm *mainForm; JDecApplication() { mainForm = 0; } ~JDecApplication() { delete mainForm; } }; // main.cpp からの include 以外は全て extern 宣言する -> インスタンスは一つのみ #ifndef MAIN_CPP_ extern #endif JDecApplication application; #endif // JDECAPP_APP_