This repository has been archived by the owner on May 16, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial commit. decode a gif. blocking
- Loading branch information
0 parents
commit 861d23d
Showing
6 changed files
with
250 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#include "ofMain.h" | ||
#include "testApp.h" | ||
#include "ofAppGlutWindow.h" | ||
|
||
//======================================================================== | ||
int main( ){ | ||
|
||
ofAppGlutWindow window; | ||
ofSetupOpenGL(&window, 1024,768, OF_WINDOW); // <-------- setup the GL context | ||
|
||
// this kicks off the running of my app | ||
// can be OF_WINDOW or OF_FULLSCREEN | ||
// pass in width and height too: | ||
ofRunApp( new testApp()); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#include "testApp.h" | ||
|
||
//-------------------------------------------------------------- | ||
void testApp::setup(){ | ||
|
||
dcd.decode("iana.gif"); | ||
for (int i = 0; i < dcd.pxs.size(); i++) { | ||
decodedImages.push_back(new ofImage(*dcd.pxs[i])); | ||
} | ||
|
||
} | ||
|
||
//-------------------------------------------------------------- | ||
void testApp::update(){ | ||
|
||
} | ||
|
||
//-------------------------------------------------------------- | ||
void testApp::draw(){ | ||
for(int i = 0; i < decodedImages.size() ; i++) { | ||
decodedImages[i]->draw(i*100,0, 100, 100); | ||
} | ||
} | ||
|
||
//-------------------------------------------------------------- | ||
void testApp::keyPressed(int key){ | ||
|
||
} | ||
|
||
//-------------------------------------------------------------- | ||
void testApp::keyReleased(int key){ | ||
switch (key) { | ||
case ' ': | ||
break; | ||
case 's': | ||
|
||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
|
||
//-------------------------------------------------------------- | ||
void testApp::mouseMoved(int x, int y ){ | ||
|
||
} | ||
|
||
//-------------------------------------------------------------- | ||
void testApp::mouseDragged(int x, int y, int button){ | ||
|
||
} | ||
|
||
//-------------------------------------------------------------- | ||
void testApp::mousePressed(int x, int y, int button){ | ||
|
||
} | ||
|
||
//-------------------------------------------------------------- | ||
void testApp::mouseReleased(int x, int y, int button){ | ||
|
||
} | ||
|
||
//-------------------------------------------------------------- | ||
void testApp::windowResized(int w, int h){ | ||
|
||
} | ||
|
||
//-------------------------------------------------------------- | ||
void testApp::gotMessage(ofMessage msg){ | ||
|
||
} | ||
|
||
//-------------------------------------------------------------- | ||
void testApp::dragEvent(ofDragInfo dragInfo){ | ||
|
||
} | ||
//-------------------------------------------------------------- | ||
void testApp::exit(){ | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#ifndef _TEST_APP | ||
#define _TEST_APP | ||
|
||
#include "ofMain.h" | ||
#include "ofxGifDecoder.h" | ||
|
||
|
||
class testApp : public ofBaseApp{ | ||
|
||
public: | ||
void setup(); | ||
void update(); | ||
void draw(); | ||
|
||
void keyPressed (int key); | ||
void keyReleased(int key); | ||
void mouseMoved(int x, int y ); | ||
void mouseDragged(int x, int y, int button); | ||
void mousePressed(int x, int y, int button); | ||
void mouseReleased(int x, int y, int button); | ||
void windowResized(int w, int h); | ||
void dragEvent(ofDragInfo dragInfo); | ||
void gotMessage(ofMessage msg); | ||
void exit(); | ||
|
||
ofxGifDecoder dcd; | ||
vector<ofImage *> decodedImages; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
// | ||
// ofxGifDecoder.cpp | ||
// gifPhasing | ||
// | ||
// Created by Jesus Gollonet on 5/14/11. | ||
// Copyright 2011 __MyCompanyName__. All rights reserved. | ||
// | ||
|
||
#include "ofxGifDecoder.h" | ||
// from ofimage | ||
//---------------------------------------------------- | ||
|
||
void ofxGifDecoder::putBmpIntoPixels(FIBITMAP * bmp, ofPixels &pix, bool swapForLittleEndian ){ | ||
// some images use a palette, or <8 bpp, so convert them to raster 8-bit channels | ||
FIBITMAP* bmpConverted = NULL; | ||
|
||
|
||
if(FreeImage_GetColorType(bmp) == FIC_PALETTE || FreeImage_GetBPP(bmp) < 8) { | ||
if(FreeImage_IsTransparent(bmp)) { | ||
bmpConverted = FreeImage_ConvertTo32Bits(bmp); | ||
} else { | ||
bmpConverted = FreeImage_ConvertTo24Bits(bmp); | ||
} | ||
bmp = bmpConverted; | ||
} | ||
|
||
unsigned int width = FreeImage_GetWidth(bmp); | ||
unsigned int height = FreeImage_GetHeight(bmp); | ||
unsigned int bpp = FreeImage_GetBPP(bmp); | ||
unsigned int channels = (bpp / sizeof(PixelType)) / 8; | ||
unsigned int pitch = FreeImage_GetPitch(bmp); | ||
|
||
// ofPixels are top left, FIBITMAP is bottom left | ||
FreeImage_FlipVertical(bmp); | ||
|
||
unsigned char* bmpBits = FreeImage_GetBits(bmp); | ||
if(bmpBits != NULL) { | ||
pix.setFromAlignedPixels(bmpBits, width, height, channels, pitch); | ||
} else { | ||
ofLogError() << "ofImage::putBmpIntoPixels() unable to set ofPixels from FIBITMAP"; | ||
} | ||
|
||
if(bmpConverted != NULL) { | ||
FreeImage_Unload(bmpConverted); | ||
} | ||
|
||
#ifdef TARGET_LITTLE_ENDIAN | ||
if(swapForLittleEndian) { | ||
pix.swapRgb(); | ||
} | ||
#endif | ||
} | ||
|
||
void ofxGifDecoder::decode(string fileName) { | ||
|
||
int width, height, bpp; | ||
fileName = ofToDataPath(fileName); | ||
bool bLoaded = false; | ||
FIMULTIBITMAP * multiBmp = NULL; | ||
|
||
|
||
FREE_IMAGE_FORMAT fif = FIF_UNKNOWN; | ||
fif = FreeImage_GetFileType(fileName.c_str(), 0); | ||
if(fif != FIF_UNKNOWN) { | ||
// or guess via filename | ||
fif = FreeImage_GetFIFFromFilename(fileName.c_str()); | ||
} | ||
if(fif == FIF_GIF) { | ||
|
||
multiBmp = FreeImage_OpenMultiBitmap(fif, fileName.c_str(), false, false,true, GIF_PLAYBACK);////(fif, fileName.c_str(), 0); | ||
if (multiBmp){ | ||
bLoaded = true; | ||
} | ||
} | ||
//----------------------------- | ||
|
||
if ( bLoaded ){ | ||
printf("loaded!!! "); | ||
int count = FreeImage_GetPageCount(multiBmp); | ||
printf ("we have %i num pages\n", count); | ||
//putBmpIntoPixels(bmp,pix); | ||
for (int i = 0; i < count; i++) { | ||
FIBITMAP * dib = FreeImage_LockPage(multiBmp, i); | ||
|
||
if(dib) { | ||
|
||
pxs.push_back(new ofPixels()); | ||
putBmpIntoPixels(dib, *pxs.back(), true); | ||
printf("we have dib!!\n"); | ||
FreeImage_UnlockPage(multiBmp, dib, false); | ||
} | ||
} | ||
} else { | ||
width = height = bpp = 0; | ||
} | ||
|
||
if (multiBmp != NULL){ | ||
FreeImage_CloseMultiBitmap(multiBmp, 0); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// | ||
// ofxGifDecoder.h | ||
// gifPhasing | ||
// | ||
// Created by Jesus Gollonet on 5/14/11. | ||
// Copyright 2011 __MyCompanyName__. All rights reserved. | ||
// | ||
#pragma once | ||
#include "ofMain.h" | ||
#include "FreeImage.h" | ||
|
||
// give it an animated gif and get a frame | ||
class ofxGifDecoder { | ||
public: | ||
void decode(string fileName); | ||
vector<ofPixels *> pxs; | ||
void putBmpIntoPixels(FIBITMAP * bmp, ofPixels &pix, bool swapForLittleEndian = true); | ||
|
||
}; |