symba (779893), страница 41
Текст из файла (страница 41)
At the time of writing, these are: EGray256,EColor16M, EColor16MU andEColor16MA. Scaling bitmaps of othercolor modes involves color re-translation.6.6.3 Rotating BitmapsThe bitmap rotation API is quite similar to the scaling one as it has thesame design and usage patterns.It is a bit easier to use as it hasn’t got any additional setup parameters.It can do bitmap rotation in multiples of 90 degrees:MISCELLANEOUS APIS193void CSimpleBitmapRotationHandler::ConstructL(){iRotator = CBitmapRotator::NewL();CActiveScheduler::Add(this); // Add to scheduler}CSimpleBitmapRotationHandler::∼CSimpleBitmapRotationHandler(){// Cancel any request, if outstandingCancel();// Delete instance variables, if anydelete iRotator;}void CSimpleBitmapRotationHandler::BeginRotation(CFbsBitmap& aSource,CBitmapRotator::TRotationAngle aAngle){// begin rotationiRotator->Rotate(&iStatus, aSource, aAngle);// Tell scheduler a request is activeSetActive();}void CSimpleBitmapRotationHandler::RunL(){if (iStatus.Int() == KErrNone){// Do something with rotated bitmap}else{// Handle error}}The main input parameters to the bitmap rotation API are:• Rotation angle in multiples of 90 degrees.
CBitmapRotator::TRotationAngle defines the set of rotation options supported.• CBitmapRotator::Rotate() has two overloads: one using asingle bitmap as both destination and source and one using twobitmaps, which allows the application to keep the source bitmapintact. The single-bitmap option does not provide any memory saving,as the default implementation creates a destination bitmap internallyand then swaps bitmap handles.6.7 Miscellaneous APIsThere are several helper classes which can be used by an application toperform pixel-level operations on native bitmaps (see Figure 6.12). Theseclasses were designed as re-usable components for decoder plug-ins(as they do a fair amount of pixel operations), however since they arepublished APIs, they can be used by third-party applications as well.194IMAGE CONVERSION LIBRARY«factory»ImageProcessorUtility++NewImageProcessorL(CFbsBitmap &, TSize &, TDisplayMode, TBool) : CImageProcessor∗NewImageProcessorL(CFbsBitmap &, TInt, TDisplayMode, TBool) : CImageProcessor∗«instantiate»«interface»CImageProcessor+++++++++++FlushPixels() : TBoolPrepareL(CFbsBitmap &, TRect&) : voidPrepareL(CFbsBitmap &, TRect&, TSize&) : voidSetPixelBlock(TRgb ∗) : TBoolSetPos(TPoint&) : TBoolSetYPosIncrement(TInt) : voidSetLineRepeat(TInt) : voidSetPixelPadding(TInt) : voidSetPixel(TRgb) : TBoolSetPixelRun(TRgb, TInt) : TBoolSetPixels(TRgb ∗, TInt) : TBoolTImageBitmapUtilTColorConvertor+++++NewL(TDisplayMode) : TColorConvertor∗ColorIndex(TRgb) : TIntColor(TInt) : TRgbColorToIndex(TInt ∗, TRgb ∗, TInt) : voidRgbToMonochrome(TRgb) : TIntFigure 6.12++++++++TImageBitmapUtil() : voidBegin(TPoint&) : TBoolBegin() : voidEnd() : voidSetBitmapL(CFbsBitmap∗) : voidSetPixel(TUint32) : voidSetPixels(TUint32∗, TInt) : voidSetPos(TPoint&) : TBoolICL pixel-processing APIsThe CImageProcessor API is designed to serve as a universal pixeldata sink for an application which writes individual pixels directly, withadded support for on-the-fly scaling and color conversion.
The ImageProcessorUtility is a factory-like static class which can createimplementations of CImageProcessor which correspond to the destination bitmap type and input pixel data display mode. The CImageProcessor class supports on-the-fly pixel format conversion to thedestination bitmap color mode along with on-the-fly downscaling ofincoming pixel data.MISCELLANEOUS APIS195TImageBitmapUtil is a simple and lightweight utility class thatallows applications to write pixels and pixel blocks into a Symbian OSbitmap.The TColorConvertor utility class is an interface-based utility classwhich can be used as a universal color converter routine between aTRgb-based color representation and a color index value within a givencolor mode.All these classes may be used by an application wanting to applyspecial effects to individual pixels of a native Symbian OS bitmap.
In fact,the CImageProcessor implementations use TImageBitmapUtil andTColorConvertor to perform pixel processing.The following code uses CImageProcessor to implement a simpleeffect on a native bitmap. It reduces the size by half and reduces thebrightness to a quarter:CFbsBitmap* ImageProcessorUseL(CFbsBitmap& aSrcBitmap){const TInt KReductionFactor = 1; // Means 1/2 of the original size// Create the destination bitmap objectCFbsBitmap* destBitmap = new (ELeave) CFbsBitmap();CleanupStack::PushL(destBitmap);// Calculate the destination size using the defined reduction factorconst TSize srcSize( aSrcBitmap.SizeInPixels() );const TSize destSize(srcSize.iWidth >> KReductionFactor,srcSize.iHeight >> KReductionFactor);// Create the destination bitmap with the same color mode as sourceUser::LeaveIfError(destBitmap->Create(destSize,aSrcBitmap.DisplayMode()));// Create an instance of CImageProcessor with the given reduction// We are going to use EColor16M and do not want to use color dithering.CImageProcessor* processor;processor = ImageProcessorUtility::NewImageProcessorL(aSrcBitmap,KReductionFactor, ERgb, ETrue);CleanupStack::PushL(processor);// Create an image processor for the destination bitmap and use// the entire destination bitmap for placing the incoming pixel data.// NOTE: it is not a typo - PrepareL() expects unscaled coordinatesprocessor->PrepareL(*destBitmap, TRect(srcSize) );// Brightness reduction factorconst TInt KDimOutFactor = 2;// Iterate through all the source pixelsfor (TInt yPos = 0; yPos < srcSize.iHeight; yPos++){for (TInt xPos = 0; xPos < srcSize.iWidth; xPos++){TRgb pixel;aSrcBitmap.GetPixel(pixel, TPoint(xPos, yPos));TRgb newPixel;newPixel.SetRed( pixel.Red() >> KDimOutFactor );newPixel.SetGreen( pixel.Green() >> KDimOutFactor );newPixel.SetBlue( pixel.Blue() >> KDimOutFactor );processor->SetPixel( newPixel );}196IMAGE CONVERSION LIBRARY}// Write all the buffered pixels into the destination bitmapprocessor->FlushPixels();CleanupStack::PopAndDestroy(processor);CleanupStack::Pop(destBitmap);return destBitmap;}One thing to note is that this CImageProcessor example is not anexample of high-performance code.
Rather, we have made it as readableas possible. Well-designed code should never call a virtual function perpixel image, but instead should deal with pixel buffer methods. Also, themultiple calls to TRgb::SetRed() and others should be replaced withone single method. However, high-performance code is usually not veryreadable.7The Tuner APIThis chapter introduces the Tuner API which provides access to anFM/AM radio if radio hardware is present on the phone. It shows howto get started with the API and covers some common use cases withexamples. After reading this chapter, you should be able to write a simpleradio application and know where to find the SDK documentation formore advanced use cases.It also discusses related technologies such as digital radio (DAB) andmobile television and how they may be supported by Symbian OS in thefuture.7.1 IntroductionSince Symbian OS v9.1, there has been an API available for controllinga radio tuner on Symbian smartphones. However, it is important to note,that the Tuner API is currently only publicly available in the UIQ 3 SDKs.To date, the S60 3rd Edition SDK releases have excluded this componentand do not provide an alternative.
This means that you cannot writethird-party radio tuner applications for S60 phones.The first smartphone to use the Tuner API was the Sony Ericsson P990which featured an FM radio with RDS1 support. All smartphones based onUIQ 3.0 (which is built on Symbian OS v9.1) or later run applications builtagainst this API. If the device does not have radio hardware (for example,the Sony Ericsson M600i), the API reports an error at initialization time,which the application should handle gracefully.The Tuner API is separate from the other Symbian OS multimediacomponents. The underlying licensee implementations may make use ofDevSound and MMF for audio output and recording but this is transparent1 Radio Data System (RDS) is a standard for embedding information, such as the stationname, in FM broadcasts.198THE TUNER APIto the API user. No prior knowledge of the other Symbian OS multimediacomponents is required in order to use the Tuner API.Let’s take a look at what the Tuner API enables you to do at a highlevel.
Section 7.3 gives further detail and covers basic use cases. Formore specific details, you may also find it helpful to refer to the APIdocumentation in the Symbian Developer Library documentation in yourSDK or online at developer.symbian.com. The Symbian OS Referencehas a section on the tuner which should be useful when reading therest of this chapter. A shortcut to finding the documentation is simply tosearch the index for ’CMMTunerUtility’.The Tuner API allows you to:• query the capabilities of available tuners on the device (what frequency bands they support, whether they support RDS, or canrecord, etc.)• tune into a given frequency• scan automatically for the next frequency with a strong signal• play the received audio• record the received audio• use RDS features (only available on compatible FM tuners):• get metadata such as the name of the radio station and currentprogram• find alternative frequencies for the current radio station• automatically tune into news and traffic updates on other frequencies• get the current time.7.2 Getting StartedThe first thing you need to do when using the Tuner API is link totuner.lib by adding it to your application’s MMP file:LIBRARY tuner.libYou also need to include tuner.h in any source or header files thatuse the Tuner API:2#include <tuner/tuner.h>2 This assumes that you already have \epoc32\include as a SYSTEMINCLUDE pathin your MMP file.GETTING STARTED1997.2.1 InitializationThe Tuner API is structured around a central class, CMMTunerUtility,that takes care of initialization, de-initialization, basic tuner control, andaccess to a number of utility classes for more specialized functions:• CMMTunerAudioPlayerUtility allows you to play the audiobeing received.• CMMTunerAudioRecorderUtility allows you to record the audiobeing received.• CMMTunerScannerUtility can automatically scan through allavailable frequencies pausing at each station it finds.• CMMRdsTunerUtility allows you to access the RDS functionalityin FM broadcasts.These utility classes are covered in more detail in Section 7.3.In order to get started, you need to check how many tuners (if any)are available using the static method CMMTunerUtility::TunersAvailable().