Пример #1
0
void CImage::ReadFrameBuffer_BMP () {
    nx = param.x_resolution;
    ny = param.y_resolution;
    depth = 4;

    DisposeData ();
    data  = (unsigned char *) malloc (nx * ny * depth * sizeof (unsigned char));
    glReadBuffer (GL_FRONT);
    glReadPixels (0, 0, nx, ny, GL_BGRA, GL_UNSIGNED_BYTE, data);
}
Пример #2
0
bool CImage::LoadPng (const char *filepath, bool mirroring) {
    SDL_Surface *sdlImage;
    unsigned char *sdlData;

    sdlImage = IMG_Load (filepath);
    if (sdlImage == 0) {
        Message ("could not load image", filepath);
        return false;
    }

    nx    = sdlImage->w;
    ny    = sdlImage->h;
    depth = sdlImage->format->BytesPerPixel;
    pitch = sdlImage->pitch;
    DisposeData ();
    data  = (unsigned char *) malloc (pitch * ny * sizeof (unsigned char));

    if (SDL_MUSTLOCK (sdlImage)) {
        if (SDL_LockSurface (sdlImage) < 0) {
            Message ("mustlock error");
            return false;
        };
    }

    sdlData = (unsigned char *) sdlImage->pixels;

    if (mirroring) {
        for (int y=0; y<ny; y++) {
            for (int x=0; x<pitch; x++) {
                data [y * pitch + x] = sdlData [(ny-1-y) * pitch + x];
            }
        }
    } else {
        for (int y=0; y<ny; y++) {
            for (int x=0; x<pitch; x++) {
                data [y * pitch + x] = sdlData [y * pitch + x];
            }
        }
    }

    if (SDL_MUSTLOCK (sdlImage)) SDL_UnlockSurface (sdlImage);
    SDL_FreeSurface (sdlImage);
    return true;
}
Пример #3
0
bool CImage::ReadFrameBuffer_PPM () {
    int viewport[4];
    glGetIntegerv (GL_VIEWPORT, viewport);

    nx = viewport[2];
    ny = viewport[3];
    depth = 3;

    DisposeData ();
    data  = (unsigned char *) malloc (nx * ny * depth * sizeof (unsigned char));

    glReadBuffer (GL_FRONT);

    for (int i=0; i<viewport[3]; i++) {
        glReadPixels (viewport[0], viewport[1] + viewport[3] - 1 - i,
                      viewport[2], 1, GL_RGB, GL_UNSIGNED_BYTE, data + viewport[2] * i * 3);
    }

    return true;
}
Пример #4
0
/**
 * Function: main
 * --------------
 * Serves as the entry point of the full RSS News Feed Aggregator.
 * 
 * @param argc the number of tokens making up the shell command invoking the
 *             application.  It should be either 1 or 2--2 when the used wants to
 *             specify what flat text file should be used to source all of the 
 *             RSS feeds.
 * @param argv the array of one of more tokens making up the command line invoking
 *             the application.  The 0th token is ignored, and the 1st one, if present,
 *             is taken to be the path identifying where the list of RSS feeds is.
 * @return always 0 if it main returns normally (although there might be exit(n) calls
 *         within the code base that end the program abnormally)
 */
int main(int argc, char **argv)
{
  const char *feedsFileURL = (argc == 1) ? kDefaultFeedsFileURL : argv[1];
 
  Welcome(kWelcomeTextURL);
 
  rssFeedData data;
  CreateDataStructure(&data);
  
  LoadStopWords(kDefaultStopWordsURL,&data.stopWords);
  
  BuildIndices(feedsFileURL, &data);
  // tests
  // HashSetMap(&data.stopWords, StringMap, NULL);
  // HashSetMap(&data.articles, ArticleMap, NULL);
  // HashSetMap(&data.indices, IndexMap, NULL);
  
  QueryIndices(&data);
  
  DisposeData(&data);
  return 0;
}
Пример #5
0
MovieEncoder::~MovieEncoder()
{
	DisposeData();
}
Пример #6
0
// When this is running, no member variable should be accessed
// from other threads
status_t
MovieEncoder::_EncoderThread()
{	
	int32 framesLeft = fFileList->CountItems();
	int32 framesWritten = 0;
	
	if (framesLeft <= 0) {
		DisposeData();
		BMessage message(kEncodingFinished);
		message.AddInt32("status", (int32)B_ERROR);
		fMessenger.SendMessage(&message);
		return B_ERROR;
	}
	
	// Create movie
	entry_ref movieRef;
	get_ref_for_path(fOutputFile.Path(), &movieRef);
		
	BitmapEntry* entry = fFileList->ItemAt(0);
	BBitmap* bitmap = entry->Bitmap();
	BRect sourceFrame = bitmap->Bounds();
	delete bitmap;
		
	if (!fDestFrame.IsValid())
		fDestFrame = sourceFrame.OffsetToCopy(B_ORIGIN);
	
	// Calc the average time difference between the first 100 frames,
	// and use it to calculate the framerate.
	// TODO: Actually we could just calculate the number of frames and
	// the time difference between the first and the last one.
	/*int32 maxTimeStampNum = std::min((int32)100, fFileList->CountItems());	
	bigtime_t previousFrameTime = entry->TimeStamp();
	bigtime_t diffSum = 0;
	for (int32 i = 0; i < maxTimeStampNum; i++) {
		BitmapEntry* entry = fFileList->ItemAt(i);
		bigtime_t currentFrameTime = entry->TimeStamp();
		diffSum += currentFrameTime - previousFrameTime;		
		previousFrameTime = currentFrameTime;
	}
	
	float medianDiffTime = diffSum / maxTimeStampNum;
	*/
	int32 numFrames = fFileList->CountItems();
	BitmapEntry* firstEntry = fFileList->ItemAt(0);
	BitmapEntry* lastEntry = fFileList->ItemAt(numFrames - 1);
	int frameSeconds = (1000000 * numFrames) / (lastEntry->TimeStamp() - firstEntry->TimeStamp());
	media_format inputFormat = fFormat;
	inputFormat.u.raw_video.field_rate = frameSeconds;
	
	status_t status = _CreateFile(movieRef, fFileFormat, inputFormat, fCodecInfo);
	if (status < B_OK) {
		DisposeData();
		BMessage message(kEncodingFinished);
		message.AddInt32("status", (int32)status);
		fMessenger.SendMessage(&message);		
		return status;
	}
		
	// Bitmap and view used to convert the source bitmap
	// to the correct size and depth	
	BBitmap* destBitmap = new BBitmap(fDestFrame, fColorSpace, true);
	BView* destDrawer = new BView(fDestFrame, "drawing view", B_FOLLOW_NONE, 0);
	if (destBitmap->Lock()) {
		destBitmap->AddChild(destDrawer);
		destBitmap->Unlock();
	}
	
	const uint32 keyFrameFrequency = 10;
		// TODO: Make this tunable
	
	BMessage progressMessage(B_UPDATE_STATUS_BAR);
	progressMessage.AddFloat("delta", 1.0);
	
	destBitmap->Bounds().PrintToStream();
	PrintMediaFormat(inputFormat);
	
	status = B_OK;
	while (BitmapEntry* entry = const_cast<FileList*>(fFileList)->Pop()) {
		if (fKillThread)
			break;
	
		bool keyFrame = (framesWritten % keyFrameFrequency == 0);
		BBitmap* frame = entry->Bitmap();
		if (frame == NULL) {
			// TODO: What to do here ? Exit with an error ?
			std::cerr << "Error while loading bitmap entry" << std::endl;
			delete entry;
			continue;
		}
						
		// Draw scaled
		if (status == B_OK) {
			destBitmap->Lock();
			destDrawer->DrawBitmap(frame, frame->Bounds(), destDrawer->Bounds());
			destDrawer->Sync();
			destBitmap->Unlock();
		}
		
		delete frame;
		delete entry;
			
		if (status == B_OK)
			status = _WriteFrame(destBitmap, keyFrame);
		
		if (status != B_OK)
			break;

		framesWritten++;

		if (fMessenger.IsValid())
			fMessenger.SendMessage(new BMessage(progressMessage));
		else {
			// BMessenger is no longer valid. This means that the application
			// has been closed or it has crashed.
			break;
		}
	}

	delete destBitmap;
	
	DisposeData();
	
	if (fMessenger.IsValid()) {
		BMessage message(kEncodingFinished);
		message.AddInt32("status", (int32)status);
		message.AddInt32("frames", (int32)framesWritten);
		fMessenger.SendMessage(&message);
	}
		
	return status;
}
Пример #7
0
status_t
MovieEncoder::Encode()
{
	int32 framesLeft = fFileList->CountItems();
	int32 framesWritten = 0;
	
	if (framesLeft <= 0) {
		DisposeData();
		BMessage message(kEncodingFinished);
		message.AddInt32("status", (int32)B_ERROR);
		fMessenger.SendMessage(&message);
		return B_ERROR;
	}
	
	// Create movie
	char movieName[B_FILE_NAME_LENGTH];
	MakeUniqueName(fOutputFile.Path(), movieName, B_FILE_NAME_LENGTH);
	entry_ref movieRef;
	get_ref_for_path(movieName, &movieRef);
	
	media_file_format fileFormat;
	if (!GetMediaFileFormat(fFamily, fileFormat)) {
		BMessage message(kEncodingFinished);
		message.AddInt32("status", (int32)B_ERROR);
		fMessenger.SendMessage(&message);
		return B_ERROR;
	}
	
	BBitmap* bitmap = BTranslationUtils::GetBitmapFile(fFileList->ItemAt(0));
	BRect sourceFrame = bitmap->Bounds();
	delete bitmap;
		
	if (!fDestFrame.IsValid())
		fDestFrame = sourceFrame.OffsetToCopy(B_ORIGIN);
				
	BitmapMovie* movie = new BitmapMovie(fDestFrame.IntegerWidth() + 1,
					fDestFrame.IntegerHeight() + 1, fColorSpace);
				
	status_t error = movie->CreateFile(movieRef, fileFormat, fFormat, fCodecInfo);
	if (error < B_OK) {
		delete movie;
		DisposeData();
		BMessage message(kEncodingFinished);
		message.AddInt32("status", (int32)error);
		fMessenger.SendMessage(&message);		
		return error;
	}
		
	// Bitmap and view used to convert the source bitmap
	// to the correct size and depth	
	BBitmap* destBitmap = new BBitmap(fDestFrame, fColorSpace, true);
	BView* destDrawer = new BView(fDestFrame, "drawing view", B_FOLLOW_NONE, 0);
	if (destBitmap->Lock()) {
		destBitmap->AddChild(destDrawer);
		destBitmap->Unlock();
	}
	
	const uint32 keyFrameFrequency = 10;
	
	BMessage progressMessage(B_UPDATE_STATUS_BAR);
	progressMessage.AddFloat("delta", 1.0);
	bool keyFrame = true;		
	for (int32 i = 0; i < fFileList->CountItems(); i++) {
		if (framesWritten % keyFrameFrequency == 0)
			keyFrame = true;
		const char* fileName = fFileList->ItemAt(i);
		BBitmap* frame = BTranslationUtils::GetBitmapFile(fileName);
		if (frame == NULL)
			continue;
						
		// Draw scaled
		if (error == B_OK) {
			destBitmap->Lock();
			destDrawer->DrawBitmap(frame, frame->Bounds(), destDrawer->Bounds());
			destDrawer->Sync();
			destBitmap->Unlock();
		}
		
		delete frame;
			
		if (error == B_OK)
			error = movie->WriteFrame(destBitmap, keyFrame);
		
		if (error == B_OK) {
			framesWritten++;
			keyFrame = false;				
		} else {
			printf("%s\n", strerror(error));
			break;
		}
		
		if (fMessenger.IsValid())
			fMessenger.SendMessage(new BMessage(progressMessage));		
	}
	
	//printf("%ld frames written\n", framesWritten);
		
	delete movie;
	delete destBitmap;
	//delete cursor;
	
	DisposeData();
	
	BMessage message(kEncodingFinished);
	message.AddInt32("status", (int32)B_OK);
	fMessenger.SendMessage(&message);
		
	return B_OK;
}
Пример #8
0
status_t
MovieEncoder::Encode()
{	
	int32 framesLeft = fFileList->CountItems();
	int32 framesWritten = 0;
	
	if (framesLeft <= 0) {
		DisposeData();
		BMessage message(kEncodingFinished);
		message.AddInt32("status", (int32)B_ERROR);
		fMessenger.SendMessage(&message);
		return B_ERROR;
	}
	
	// Create movie
	char movieName[B_FILE_NAME_LENGTH];
	MakeUniqueName(fOutputFile.Path(), movieName, B_FILE_NAME_LENGTH);
	entry_ref movieRef;
	get_ref_for_path(movieName, &movieRef);
	
	BBitmap* bitmap = BTranslationUtils::GetBitmapFile(fFileList->ItemAt(0));
	BRect sourceFrame = bitmap->Bounds();
	delete bitmap;
		
	if (!fDestFrame.IsValid())
		fDestFrame = sourceFrame.OffsetToCopy(B_ORIGIN);
				
	BitmapMovie* movie = new BitmapMovie(fDestFrame.IntegerWidth() + 1,
					fDestFrame.IntegerHeight() + 1, fColorSpace);
				
	status_t status = movie->CreateFile(movieRef, fFileFormat, fFormat, fCodecInfo);
	if (status < B_OK) {
		delete movie;
		DisposeData();
		BMessage message(kEncodingFinished);
		message.AddInt32("status", (int32)status);
		fMessenger.SendMessage(&message);		
		return status;
	}
		
	// Bitmap and view used to convert the source bitmap
	// to the correct size and depth	
	BBitmap* destBitmap = new BBitmap(fDestFrame, fColorSpace, true);
	BView* destDrawer = new BView(fDestFrame, "drawing view", B_FOLLOW_NONE, 0);
	if (destBitmap->Lock()) {
		destBitmap->AddChild(destDrawer);
		destBitmap->Unlock();
	}
	
	const uint32 keyFrameFrequency = 10;
		// TODO: Make this tunable
	
	BMessage progressMessage(B_UPDATE_STATUS_BAR);
	progressMessage.AddFloat("delta", 1.0);
	
	status = B_OK;
	for (int32 i = 0; i < fFileList->CountItems(); i++) {
		bool keyFrame = (framesWritten % keyFrameFrequency == 0);
		const char* fileName = fFileList->ItemAt(i);
		BBitmap* frame = BTranslationUtils::GetBitmapFile(fileName);
		if (frame == NULL) {
			// TODO: What to do here ? Exit with an error ?
			continue;
		}
						
		// Draw scaled
		if (status == B_OK) {
			destBitmap->Lock();
			destDrawer->DrawBitmap(frame, frame->Bounds(), destDrawer->Bounds());
			destDrawer->Sync();
			destBitmap->Unlock();
		}
		
		delete frame;
			
		if (status == B_OK)
			status = movie->WriteFrame(destBitmap, keyFrame);
		
		if (status != B_OK)
			break;

		framesWritten++;

		if (fMessenger.IsValid())
			fMessenger.SendMessage(new BMessage(progressMessage));		
	}

	delete movie;
	delete destBitmap;
	
	DisposeData();
	
	if (fMessenger.IsValid()) {
		BMessage message(kEncodingFinished);
		message.AddInt32("status", (int32)status);
		message.AddInt32("frames", (int32)framesWritten);
		fMessenger.SendMessage(&message);
	}
		
	return status;
}
Пример #9
0
CImage::~CImage () {
    DisposeData ();
}