Esempio n. 1
0
/*
==================
ImageFromFunction

Images that are procedurally generated are allways specified
with a callback which must work at any time, allowing the OpenGL
system to be completely regenerated if needed.
==================
*/
idImage *idImageManager::ImageFromFunction( const char *_name, void (*generatorFunction)( idImage *image ) ) {

	// strip any .tga file extensions from anywhere in the _name
	idStr name = _name;
	name.Replace( ".tga", "" );
	name.BackSlashesToSlashes();

	// see if the image already exists
	int hash = name.FileNameHash();
	for ( int i = imageHash.First( hash ); i != -1; i = imageHash.Next( i ) ) {
		idImage * image = images[i];
		if ( name.Icmp( image->GetName() ) == 0 ) {
			if ( image->generatorFunction != generatorFunction ) {
				common->DPrintf( "WARNING: reused image %s with mixed generators\n", name.c_str() );
			}
			return image;
		}
	}

	// create the image and issue the callback
	idImage	* image = AllocImage( name );

	image->generatorFunction = generatorFunction;

	// check for precompressed, load is from the front end
	image->referencedOutsideLevelLoad = true;
	image->ActuallyLoadImage( false );

	return image;
}
Esempio n. 2
0
/*
========================
idImage::Resize
========================
*/
void idImage::Resize( int width, int height ) {
	if ( opts.width == width && opts.height == height ) {
		return;
	}
	opts.width = width;
	opts.height = height;
	AllocImage();
}
Esempio n. 3
0
/*
========================
idImageManager::ScratchImage
========================
*/
idImage * idImageManager::ScratchImage( const char *_name, idImageOpts *imgOpts, textureFilter_t filter, textureRepeat_t repeat, textureUsage_t usage ) {
	if ( !_name || !_name[0] ) {
		idLib::FatalError( "idImageManager::ScratchImage called with empty name" );
	}

	if ( imgOpts == NULL ) {
		idLib::FatalError( "idImageManager::ScratchImage called with NULL imgOpts" );
	}

	idStr name = _name;

	//
	// see if the image is already loaded, unless we
	// are in a reloadImages call
	//
	int hash = name.FileNameHash();
	for ( int i = imageHash.First( hash ); i != -1; i = imageHash.Next( i ) ) {
		idImage	* image = images[i];
		if ( name.Icmp( image->GetName() ) == 0 ) {
			// the built in's, like _white and _flat always match the other options
			if ( name[0] == '_' ) {
				return image;
			}

			if ( image->filter != filter || image->repeat != repeat ) {
				// we might want to have the system reset these parameters on every bind and
				// share the image data
				continue;
			}
			if ( image->usage != usage ) {
				// If an image is used differently then we need 2 copies of it because usage affects the way it's compressed and swizzled
				continue;
			}

			image->usage = usage;
			image->levelLoadReferenced = true;
			image->referencedOutsideLevelLoad = true;
			return image;
		}
	}

	// clamp is the only repeat mode that makes sense for cube maps, but
	// some platforms let them stay in repeat mode and get border seam issues
	if ( imgOpts->textureType == TT_CUBIC && repeat != TR_CLAMP ) {
		repeat = TR_CLAMP;
	}

	//
	// create a new image
	//
	idImage* newImage = AllocImage( name );
	if ( newImage != NULL ) {	
		newImage->AllocImage( *imgOpts, filter, repeat );
	}
	return newImage;
}
Esempio n. 4
0
void ChromaKeyOSD::Reinit(int i)
{
    // Make sure the buffer is the right size...
    QSize new_res(vf[i].width, vf[i].height);
    if (new_res != videoOutput->display_visible_rect.size())
    {
        FreeImage(i);
        AllocImage(i);
    }

    uint key = videoOutput->xv_colorkey;
    uint bpl = img[i]->bytes_per_line;

    // create chroma key line
    char *cln = (char*)av_malloc(bpl + 128);
    bzero(cln, bpl);
    int j  = max(videoOutput->display_video_rect.left() -
                 videoOutput->display_visible_rect.left(), 0);
    int ej = min(videoOutput->display_video_rect.left() +
                 videoOutput->display_video_rect.width(), vf[i].width);
    for (; j < ej; ++j)
        ((uint*)cln)[j] = key;

    // boboff assumes the smallest interlaced resolution is 480 lines - 5%
    int boboff = (int) round(
        ((double)videoOutput->display_video_rect.height()) / 456 - 0.00001);
    boboff = (videoOutput->m_deinterlacing &&
              videoOutput->m_deintfiltername == "bobdeint") ? boboff : 0;

    // calculate beginning and end of chromakey
    int cstart = min(max(videoOutput->display_video_rect.top() + boboff, 0),
                     vf[i].height - 1);
    int cend   = min(max(videoOutput->display_video_rect.top() +
                         videoOutput->display_video_rect.height(), 0),
                     vf[i].height);

    // Paint with borders and chromakey
    char *buf = shm_infos[i].shmaddr;
    int ldispy = min(max(videoOutput->display_visible_rect.top(), 0),
                     vf[i].height - 1);

    VERBOSE(VB_PLAYBACK, LOC + "cstart: "<<cstart<<"  cend: "<<cend);
    VERBOSE(VB_PLAYBACK, LOC + "ldispy: "<<ldispy<<" height: "<<vf[i].height);

    if (cstart > ldispy)
        bzero(buf + (ldispy * bpl), (cstart - ldispy) * bpl);
    for (j = cstart; j < cend; ++j)
        memcpy(buf + (j*bpl), cln, bpl);
    if (cend < vf[i].height)
        bzero(buf + (cend * bpl), (vf[i].height - cend) * bpl);

    av_free(cln);
}
Esempio n. 5
0
csImageMemory::csImageMemory (int width, int height, const void* buffer,
                              int format, const csRGBpixel *palette) :
  scfImplementationType(this)
{
  ConstructWHDF (width, height, 1, format);
  AllocImage();
  size_t size = csImageTools::ComputeDataSize (this);
  memcpy (databuf->GetData (), buffer, size);

  if (Palette)
    memcpy (Palette, palette, sizeof (csRGBpixel) * 256);
}
Esempio n. 6
0
void csImageMemory::ConstructSource (iImage* source)
{
  ConstructWHDF (source->GetWidth(), source->GetHeight(), source->GetDepth(),
    source->GetFormat());

  AllocImage();
  size_t size = csImageTools::ComputeDataSize (this);
  memcpy (databuf->GetData (), source->GetImageData (), size);

  if (Alpha)
    memcpy (Alpha, source->GetAlpha(), Width * Height);
  if (Palette)
    memcpy (Palette, source->GetPalette(), sizeof (csRGBpixel) * 256);
}
Esempio n. 7
0
/***********************************************************************
 *
 * FUNCTION:    ThumbnailViewHandleEvent
 *
 * DESCRIPTION: This routine is the event handler for the "Thumbnail View"
 *              of the Record application.
 *
 * PARAMETERS:  event  - a pointer to an EventType structure
 *
 * RETURNED:    true if the event was handled and should not be passed
 *              to a higher level handler.
 *
 ***********************************************************************/
Boolean ThumbnailViewHandleEvent (EventPtr event) {
  FormPtr frm = NULL;
  Boolean handled = false;

  switch (event->eType) {
  case keyDownEvent:
    /* Hardware button pressed? */
    if (TxtCharIsHardKey(event->data.keyDown.modifiers, event->data.keyDown.chr)) {
      if (!(event->data.keyDown.modifiers & poweredOnKeyMask))
    ThumbnailViewNextCategory();
      handled = true;
    } else if (EvtKeydownIsVirtual(event)) {
      switch (event->data.keyDown.chr) {
      case vchrPageUp:
      case vchrRockerUp:
    if (d.fiveWayNavigation) {
      /* Deselect previous item */
      ToggleButton(d.thumbnailX, d.thumbnailY, false);
      
      /* Select new item, scroll if necessary */
      if (ThumbnailViewMoveCursorUp())
        ThumbnailViewScroll(-1);
      UpdateButtonAndIndex();
    } else {
      ThumbnailViewPageScroll(winUp);
    }
    handled = true;
    break;

      case vchrPageDown:
      case vchrRockerDown:
    if (d.fiveWayNavigation) {
      /* Deselect previous item */
      ToggleButton(d.thumbnailX, d.thumbnailY, false);
      
      /* Select new item, scroll if necessary */
      if (ThumbnailViewMoveCursorDown())
        ThumbnailViewScroll(1);
      UpdateButtonAndIndex();
    } else {
      ThumbnailViewPageScroll(winDown);
    }
    handled = true;
    break;
    
    /* Treo 600 5-way navigation */
      case vchrRockerCenter:
    handled = ThumbnailViewHandleFiveWayNavSelect();
    break;
      case vchrRockerLeft:
    handled = ThumbnailViewHandleFiveWayNavLeft();
    break;
      case vchrRockerRight:
    handled = ThumbnailViewHandleFiveWayNavRight();
    break;

    /* Tungsten 5-way navigation */
      case vchrNavChange:
    if (NavDirectionPressed(event, Left))
      handled = ThumbnailViewHandleFiveWayNavLeft();
    else if (NavDirectionPressed(event, Right))
      handled = ThumbnailViewHandleFiveWayNavRight();
    else if (NavSelectPressed(event))
      handled = ThumbnailViewHandleFiveWayNavSelect();
    break;

/*       case vchrSendData: */
/*  ThumbnailViewDoCommand(ThumbnailRecordBeamCategoryCmd); */
/*  handled = true; */
/*  break; */

      default:
    /* ignore */
      }
    }
    break;

  case ctlSelectEvent:
    switch (event->data.ctlSelect.controlID) {
    case NewButton:
      /* Create new sketch after all existing ones */
      p.dbI = DmNumRecords(d.dbR);

      AllocImage();
      FrmGotoForm(p.flags & PFLAGS_WITH_TITLEBAR ? DiddleTForm : DiddleForm);
      handled = true;
      break;

    case CategoryPop:
      ThumbnailViewSelectCategory();
      handled = true;
      break;

    case TextListButton:
      FrmGotoForm(DiddleListForm);
      handled = true;
      break;

    case ThumbnailDetailListButton:
      FrmGotoForm(DiddleThumbnailDetailForm);
      handled = true;
      break;
    }
    break;

  case frmGotoEvent:
    p.dbI = event->data.frmGoto.recordNum;
    SwitchCategoryForGoto();
    FrmGotoForm(p.flags & PFLAGS_WITH_TITLEBAR ? DiddleTForm : DiddleForm);
    event->eType = dbOpenRecordFieldEvent;
    EvtAddEventToQueue(event);

    handled = true;
    break;

  case menuEvent:
    {
      Char chr = 0;

      switch(event->data.menu.itemID) {
      case menuitemID_CmdAbout:
    DoAboutDialog();
    handled = true;
    break;

      case menuitemID_CmdSecurity:
    ThumbnailDoCmdSecurity();
    handled = true;
    break;

      case menuitemID_CmdSortByAlarm:      
      case menuitemID_CmdSortByName:
    if (event->data.menu.itemID == menuitemID_CmdSortByAlarm)
      DmInsertionSort(d.dbR, &SortByAlarmTime, 0);
    else
      DmInsertionSort(d.dbR, &SortByName, 0);

        SetTopVisibleRecord(0);
    ThumbnailViewLoadRecords(FrmGetActiveForm());
    handled = true;
    break;

      case menuitemID_CmdPref: chr=cmdPref; break;
      case menuitemID_CmdExtPref: chr=cmdExtPref; break;
      case menuitemID_CmdHWPref: chr=cmdHWPref; break;
      case menuitemID_CmdAlarmPref: chr=cmdAlarmPref; break;
      case menuitemID_CmdHelp: chr=cmdHelp; break;
      }

      if (!handled)
    handled = KeyDown(chr);
    }
    break;

  case frmOpenEvent:
    frm = FrmGetActiveForm();
    ThumbnailViewInit(frm);
    FrmDrawForm(frm);

    /* Disable 5-way navigation initially */
    d.fiveWayNavigation = false;

    /* Clean up */
    if (d.record_name) MemHandleFree(d.record_name);
    d.record_name = NULL;
    if (d.record_note) MemHandleFree(d.record_note);
    d.record_note = NULL;

    handled = true;
    break;

  case frmUpdateEvent:
    handled = ThumbnailViewUpdateDisplay(event->data.frmUpdate.updateCode);
    break;

  case menuCmdBarOpenEvent:
    MenuCmdBarAddButton(menuCmdBarOnLeft, BarSecureBitmap,
            menuCmdBarResultMenuItem, menuitemID_CmdSecurity, 0);

    /* Tell the field package to not add buttons automatically; */
    /* we've done it all ourselves.                             */
    event->data.menuCmdBarOpen.preventFieldButtons = true;

    /* don't set handled to true; this event must fall through to the system. */
    break;

  case sclRepeatEvent:
    ThumbnailViewScroll (event->data.sclRepeat.newValue - event->data.sclRepeat.value);
    break;

  case dbNonKeyCommandEvent:
    handled = HandleNonKeyCommandCode(event->data.menu.itemID);
    break;

/*   case frmObjectFocusTakeEvent: */
/*     { */
/*       RectangleType r; */
/*       FormType* frm = FrmGetFormPtr(event->data.frmObjectFocusTake.formID); */
/*       const UInt16 id = event->data.frmObjectFocusTake.objectID; */
/*       const UInt16 idx = FrmGetObjectIndex(frm, id); */

/*       if (id >= Thumb1 && id <= Thumb30) { */
/*  FrmGetObjectBounds(frm, idx, &r); */
/*  FrmSetFocus(frm, idx); */
/*  HsNavDrawFocusRing(frm, id, hsNavFocusRingNoExtraInfo, &r, */
/*             hsNavFocusRingStyleObjectTypeDefault, false); */
/*  handled = true; */
/*       } */
/*     } */
/*     break; */

  default:
    /* do nothing */
  }

  return handled;
}
Esempio n. 8
0
/*
===============
ImageFromFile

Finds or loads the given image, always returning a valid image pointer.
Loading of the image may be deferred for dynamic loading.
==============
*/
idImage	*idImageManager::ImageFromFile( const char *_name, textureFilter_t filter, 
						 textureRepeat_t repeat, textureUsage_t usage, cubeFiles_t cubeMap ) {

	if ( !_name || !_name[0] || idStr::Icmp( _name, "default" ) == 0 || idStr::Icmp( _name, "_default" ) == 0 ) {
		declManager->MediaPrint( "DEFAULTED\n" );
		return globalImages->defaultImage;
	}
	if ( idStr::Icmpn( _name, "fonts", 5 ) == 0 || idStr::Icmpn( _name, "newfonts", 8 ) == 0 ) {
		usage = TD_FONT;
	}
	if ( idStr::Icmpn( _name, "lights", 6 ) == 0 ) {
		usage = TD_LIGHT;
	}

	// strip any .tga file extensions from anywhere in the _name, including image program parameters
	idStrStatic< MAX_OSPATH > name = _name;
	name.Replace( ".tga", "" );
	name.BackSlashesToSlashes();

	//
	// see if the image is already loaded, unless we
	// are in a reloadImages call
	//
	int hash = name.FileNameHash();
	for ( int i = imageHash.First( hash ); i != -1; i = imageHash.Next( i ) ) {
		idImage	* image = images[i];
		if ( name.Icmp( image->GetName() ) == 0 ) {
			// the built in's, like _white and _flat always match the other options
			if ( name[0] == '_' ) {
				return image;
			}
			if ( image->cubeFiles != cubeMap ) {
				common->Error( "Image '%s' has been referenced with conflicting cube map states", _name );
			}

			if ( image->filter != filter || image->repeat != repeat ) {
				// we might want to have the system reset these parameters on every bind and
				// share the image data
				continue;
			}
			if ( image->usage != usage ) {
				// If an image is used differently then we need 2 copies of it because usage affects the way it's compressed and swizzled
				continue;
			}

			image->usage = usage;
			image->levelLoadReferenced = true;

			if ( ( !insideLevelLoad  || preloadingMapImages ) && !image->IsLoaded() ) {
				image->referencedOutsideLevelLoad = ( !insideLevelLoad && !preloadingMapImages );
				image->ActuallyLoadImage( false );	// load is from front end
				declManager->MediaPrint( "%ix%i %s (reload for mixed referneces)\n", image->GetUploadWidth(), image->GetUploadHeight(), image->GetName() );
			}
			return image;
		}
	}

	//
	// create a new image
	//
	idImage	* image = AllocImage( name );
	image->cubeFiles = cubeMap;
	image->usage = usage;
	image->filter = filter;
	image->repeat = repeat;

	image->levelLoadReferenced = true;

	// load it if we aren't in a level preload
	if ( !insideLevelLoad || preloadingMapImages ) {
		image->referencedOutsideLevelLoad = ( !insideLevelLoad && !preloadingMapImages );
		image->ActuallyLoadImage( false );	// load is from front end
		declManager->MediaPrint( "%ix%i %s\n", image->GetUploadWidth(), image->GetUploadHeight(), image->GetName() );
	} else {
		declManager->MediaPrint( "%s\n", image->GetName() );
	}

	return image;
}
Esempio n. 9
0
void csImageMemory::EnsureImage()
{
  if (databuf == 0 && (Palette == 0) && (Alpha == 0))
    AllocImage();
}