int main(int ac,char *av[]) { png.Decode(av[1]); png.Flip(); // Need to flip upside down because glDrawPixels draws y=0 bottom. auxInitDisplayMode(AUX_DOUBLE|AUX_RGB); auxInitPosition(0,0,png.wid+2,png.hei+2); auxInitWindow(NULL); winWid=png.wid; winHei=png.hei; glViewport(0,0,png.wid,png.hei); int viewport[4]; glGetIntegerv(GL_VIEWPORT,viewport); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.0,(double)viewport[2],(double)viewport[3],0.0,-1.0,1.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glDisable(GL_DEPTH_TEST); auxReshapeFunc(ReshapeFunc); auxMainLoop(DisplayFunc); return 0; }
YSRESULT YsBitmap::LoadPng(FILE *fp) { YsRawPngDecoder pngDec; if(pngDec.Decode(fp)==YSOK) { MoveFrom(pngDec); return YSOK; } return YSERR; }
YSRESULT YsBitmap::LoadPng(const char fn[]) { YsRawPngDecoder pngDec; if(pngDec.Decode(fn)==YSOK) { MoveFrom(pngDec); return YSOK; } return YSERR; }
YSRESULT YsBitmap::LoadPng(size_t nByte,const unsigned char binaryData[]) { YsRawPngDecoder pngDec; YsPngBinaryMemoryStream inStream(nByte,binaryData); if(pngDec.Decode(inStream)==YSOK) { MoveFrom(pngDec); return YSOK; } return YSERR; }
void makegif::initial(YsRawPngDecoder &image2, TextString &str ,int num,int hLTx, int hLTy, int hRBx, int hRBy) { str.Set("GIF1/1.png"); if(YSOK==image2.Decode(str.GetPointer())) { picWidth=image2.wid; picHeight=image2.hei; } else { printf("Read Error!\n"); } timeCounter=0; pictureNum=num; FsGetWindowSize(winWidth,winHeight); startX=winWidth/2; startY=winHeight/2; picLTx=startX; picLTy=startY-picHeight; picRBx=startX+picWidth; picRBy=startY; headLTx=hLTx; headLTy=hLTy; headRBx=hRBx; headRBy=hRBy; }
void makegif::choose(YsRawPngDecoder &image2, TextString &str) { if(timeCounter%pictureNum==0) { str.Set("GIF1/1.png"); } else if(timeCounter%pictureNum==1) { str.Set("GIF1/2.png"); } else if(timeCounter%pictureNum==2) { str.Set("GIF1/3.png"); } else if(timeCounter%pictureNum==3) { str.Set("GIF1/4.png"); } else if(timeCounter%pictureNum==4) { str.Set("GIF1/5.png"); } else if(timeCounter%pictureNum==5) { str.Set("GIF1/6.png"); } else if(timeCounter%pictureNum==6) { str.Set("GIF1/7.png"); } else if(timeCounter%pictureNum==7) { str.Set("GIF1/8.png"); } else if(timeCounter%pictureNum==8) { str.Set("GIF1/9.png"); } else if(timeCounter%pictureNum==9) { str.Set("GIF1/10.png"); } else if(timeCounter%pictureNum==10) { str.Set("GIF1/11.png"); } else if(timeCounter%pictureNum==11) { str.Set("GIF1/12.png"); } if(YSOK==image2.Decode(str.GetPointer())) { } else { printf("Read Error!\n"); } }
void makegif::setImage1(YsRawPngDecoder &image1,char image1String[]) { if(YSOK==image1.Decode(image1String)) { //image1.Flip(); } else { printf("Read Error!\n"); } }
void makegif::copyRGBA(YsRawPngDecoder &image1,YsRawPngDecoder &image2,TextString &str) { dat=new unsigned char[48*picHeight*picWidth]; unsigned char *dat2; dat2=new unsigned char[4*image1.wid*image1.hei]; int position1[4]; int position2[4]; position1[0]=image1HeadLTx; position1[1]=image1HeadLTy; position1[2]=image1HeadRBx; position1[3]=image1HeadRBy; position2[0]=headLTx; position2[1]=headLTy; position2[2]=headRBx; position2[3]=headRBy; for(int y=0; y<image1.hei; ++y) { for(int x=0; x<image1.wid; ++x) { unsigned char *pix1=image1.rgba+(image1.wid*y+x)*4; dat2[(image1.wid*y+x)*4]=pix1[0]; dat2[(image1.wid*y+x)*4+1]=pix1[1]; dat2[(image1.wid*y+x)*4+2]=pix1[2]; dat2[(image1.wid*y+x)*4+3]=pix1[3]; pix1=NULL; delete pix1; } } for(int i=0; i<12; i++) { choose(image2,str); warpImage(image1,image2,position1,position2,0.0); image2.Flip(); for(int y=0; y<picHeight; ++y) { for(int x=0; x<picWidth; ++x) { unsigned char *pix=image2.rgba+(picWidth*y+x)*4; dat[4*picWidth*picHeight*timeCounter+(picWidth*y+x)*4]=pix[0]; dat[4*picWidth*picHeight*timeCounter+(picWidth*y+x)*4+1]=pix[1]; dat[4*picWidth*picHeight*timeCounter+(picWidth*y+x)*4+2]=pix[2]; dat[4*picWidth*picHeight*timeCounter+(picWidth*y+x)*4+3]=pix[3]; } } for(int y=0; y<image1.hei; ++y) { for(int x=0; x<image1.wid; ++x) { unsigned char *pix3=dat2+(image1.wid*y+x)*4; image1.rgba[(image1.wid*y+x)*4]=pix3[0]; image1.rgba[(image1.wid*y+x)*4+1]=pix3[1]; image1.rgba[(image1.wid*y+x)*4+2]=pix3[2]; image1.rgba[(image1.wid*y+x)*4+3]=pix3[3]; pix3=NULL; delete pix3; } } image2.Flip(); timerFired(); } delete [] dat2; }
_bitmap _imageFile::readBitmap( _optValue<_u32> page ) { // Check if not-existing if( !this->isExisting() ) return _bitmap(); _mimeType mimeType = this->getRealMime(); if( mimeType == _mime::image_png ) { if( this->bufferedImage ) return *bufferedImage; _bitmap result; YsRawPngDecoder* pngDecoder = new YsRawPngDecoder; pngDecoder->Decode( this->filename.c_str() ); if( pngDecoder->wid > 0 && pngDecoder->hei > 0 && pngDecoder->rgba != NULL ) { // Allocate bitmap result = _bitmap( pngDecoder->wid , pngDecoder->hei ); // Get size of Data (in bytes)(every pixel consists of u8 red, u8 green, u8 blue, u8 alpha) _u32 size = pngDecoder->wid * pngDecoder->hei; _pixelArray base = result.getBitmap(); _u8* source = pngDecoder->rgba; do { _u8 r = *source++; _u8 g = *source++; _u8 b = *source++; bool a = *source++ > 127; *base++ = _color::fromRGB8(r,g,b,a); } while( --size > 0 ); } // Delete the decoder delete pngDecoder; if( this->buffer ) { this->bufferedImage = new _bitmap( move(result) ); return *this->bufferedImage; } return move(result); } else if( mimeType == _mime::image_jpeg ) { if( this->bufferedImage ) return *bufferedImage; _bitmap result; _u32 size = this->getSize(); _byte* data = new _byte[size]; this->read( data , size ); Jpeg::Decoder* jpgDecoder = new Jpeg::Decoder( data , size ); if ( jpgDecoder->GetResult() == Jpeg::Decoder::OK ) { result = _bitmap( jpgDecoder->GetWidth() , jpgDecoder->GetHeight() ); if( jpgDecoder->IsColor() ) { _u32 size = jpgDecoder->GetImageSize(); _u8* rgb = jpgDecoder->GetImage(); _pixelArray dest = result.getBitmap(); do { _u8 r = *rgb++; _u8 g = *rgb++; _u8 b = *rgb++; *dest++ = _color::fromRGB8(r,g,b); size -= 3; } while( size > 0 ); } else { _u32 size = jpgDecoder->GetImageSize(); _u8* rgb = jpgDecoder->GetImage(); _pixelArray dest = result.getBitmap(); do { *dest++ = _color::fromBW8( *rgb++ ); } while( --size > 0 ); } } delete[] data; delete jpgDecoder; if( this->buffer ) { this->bufferedImage = new _bitmap( move(result) ); return *this->bufferedImage; } return move(result); } else if( mimeType == _mime::image_bmp ) { if( this->bufferedImage ) return *bufferedImage; _bitmap result; _u32 size = this->getSize(); _byte* data = new _byte[size]; this->read( data , size ); _u32 width; _u32 height; _pixelArray pixeldata = GenericBMPDecoder::decode( data , size , width , height ); if ( pixeldata != nullptr ) { result = _bitmap( width , height ); memcpy16( result.getBitmap() , pixeldata , width * height ); delete[] pixeldata; } delete[] data; if( this->buffer ) { this->bufferedImage = new _bitmap( move(result) ); return *this->bufferedImage; } return move(result); } else if( mimeType == _mime::image_ico ) { _byte* data; if( this->bufferedData ) data = this->bufferedData; else { _u32 size = this->getSize(); data = new _byte[size]; this->read( data , size ); } _u32 width; _u32 height; _bitmap result; _u8* pixeldata = GenericIcoDecoder::decode( data , width , height , page ); if ( pixeldata != nullptr ) { // Allocate bitmap result = _bitmap( width , height ); // Get size of Data (in bytes)(every pixel consists of u8 red, u8 green, u8 blue, u8 alpha) _u32 size = width * height; _pixelArray base = result.getBitmap(); _u8* source = pixeldata; do { _u8 r = *source++; _u8 g = *source++; _u8 b = *source++; bool a = *source++ > 127; *base++ = _color::fromRGB8(r,g,b,a); } while( --size > 0 ); delete[] pixeldata; } if( !this->buffer ) delete[] data; else this->bufferedData = data; return result; } else if( mimeType == _mime::image_gif ) { gif_animation* gifAnim; gif_result statusCode = GIF_OK; // Allocate Decoder if( this->bufferedGif ) gifAnim = this->bufferedGif; else { // Read file content to buffer _u32 size = this->getSize(); _byte* data = new _byte[size]; this->read( data , size ); // Allocate Decoder gifAnim = new gif_animation; // Initialize Decoder gif_create( gifAnim ); // Partly Decode the gif do { statusCode = gif_initialise( gifAnim , size , data ); if (statusCode != GIF_OK && statusCode != GIF_WORKING) { _imageFile::outputGifWarning( "gif_initialise" , statusCode); break; } } while( statusCode != GIF_OK ); } if( !this->bufferedGifBitmap ) this->bufferedGifBitmap = new _bitmap( gifAnim->width , gifAnim->height , _color::transparent ); // Limit Page Number if( gifAnim->frame_count <= page ) page = gifAnim->frame_count -1; // Decode... statusCode = gif_decode_frame(gifAnim, page); // ... and Check if everything went ok if (statusCode != GIF_OK) _imageFile::outputGifWarning( "gif_decode_frame" , statusCode ); // Get destination bitmap _pixelArray dest = this->bufferedGifBitmap->getBitmap(); // Get Source bitmap _u8* source = (_u8*)gifAnim->frame_image; // Copy source bitmap to destination _length numPixels = gifAnim->height * gifAnim->width; do { *dest++ = _color::fromRGB8( source[0] , source[1] , source[2] , source[3] ); source += 4; } while( --numPixels > 0 ); // Clean temps if( this->buffer ) this->bufferedGif = gifAnim; else { delete[] gifAnim->gif_data; delete gifAnim; } return *this->bufferedGifBitmap; } return _bitmap(); }