BitmapStream.h

Go to the documentation of this file.
00001 /********************************************************************************
00002 /
00003 /      File:           BitmapStream.h
00004 /
00005 /      Description:    BPositionIO subclass to read/write bitmap format to/from 
00006 /                      BBitmap instance.
00007 /
00008 /      Copyright 1998, Be Incorporated, All Rights Reserved.
00009 /      Copyright 1995-1997, Jon Watte
00010 /
00011 ********************************************************************************/
00012 
00013 #if !defined(_BITMAP_STREAM_H)
00014 #define _BITMAP_STREAM_H
00015 
00016 #include <BeBuild.h>
00017 #include <TranslationDefs.h>
00018 #include <DataIO.h>
00019 #include <TranslatorFormats.h>
00020 
00021 
00022 class BBitmap;
00023 
00024 
00025 class BBitmapStream :
00026     public BPositionIO
00027 {
00028 public:
00029 
00030         //  This constructor serves two purposes.
00031         //
00032         //  If you don't pass a bitmap, "preferred" means the preferred color_space to
00033         //  use for BBitmaps created by this bitmap stream (if the built-in conversion
00034         //  can handle the I/O format specified in WriteAt() and your preferred format).
00035         //  If you DO pass a bitmap, the color space of the bitmap is assumed to be the
00036         //  preferred internal format and the "preferred" argument means the external
00037         //  format to convert to in ReadAt()/WriteAt().
00038         //
00039         //  As of 4.6, the only conversion supported is for B_RGB16 internal data format
00040         //  and RGB(A) 24/32 BIG/LITTLE external (WriteAt()/ReadAt()) formats.
00041         //  If there is no supported conversion, this constructor and the object so
00042         //  constructed will behave just like the bitmap-only constructor.
00043         //
00044         //  To import a RGB16 bitmap from a translator that only emits RGB32:
00045         //
00046         //  BBitmapStream strm(B_RGB16);
00047         //  roster->Translate(&file, 0, 0, &strm, B_TRANSLATOR_BITMAP);
00048         //  BBitmap * bm16bit;
00049         //  strm.DetachBitmap(&bm16bit);
00050         //  ASSERT(bm16bit->ColorSpace() == B_RGB16);
00051         //
00052         //  To export a RGB16 bitmap using a translator which only accepts RGB32:
00053         //
00054         //  ASSERT(bm16bit->ColorSpace() == B_RGB16);
00055         //  BBitmapStream strm(B_RGB32, bm16bit);
00056         //  roster->Translate(&strm, 0, 0, &file, 'JPEG');
00057         //  strm.DetachBitmap(&bm16bit);    //  else it will be deleted when the stream is
00058         //
00059         BBitmapStream(
00060                 color_space     preferred_space,
00061                 BBitmap *       map = NULL);
00062 
00063         BBitmapStream(
00064                 BBitmap *       map = NULL);
00065         ~BBitmapStream();
00066 
00067     /* Overrides from BPositionIO */
00068 
00069         ssize_t ReadAt(
00070                 off_t           pos,
00071                 void *          buffer,
00072                 size_t          size);
00073         ssize_t WriteAt(
00074                 off_t           pos,
00075                 const void *    data,
00076                 size_t          size);
00077         off_t Seek(
00078                 off_t           position,
00079                 uint32          whence);
00080         off_t Position() const;
00081         off_t Size() const;
00082         status_t SetSize(
00083                 off_t           size);
00084 
00085         status_t DetachBitmap(
00086                 BBitmap * *     outMap);    /*  not NULL    */
00087 
00088         color_space PreferredSpace() const;
00089         color_space IOSpace() const;
00090         color_space BitmapSpace() const;
00091 
00092 protected:
00093         TranslatorBitmap fHeader;
00094         BBitmap * fMap;
00095         size_t fPosition;       //  logical (external) units
00096         size_t fSize;           //  logical (external) units
00097         bool fDetached;
00098         bool fIsXlate;          //  is the mapping logical (external) <-> physical (memory) not 1:1?
00099         char fExternalSize;
00100         char fMemSize;
00101         color_space fPrefSpace; //  preferred internal color space
00102         void (BBitmapStream::*xlate_in)(const void * src, size_t src_size, void * dst);
00103         void (BBitmapStream::*xlate_out)(const void * src, void * dst, size_t dst_size);
00104 
00105         void SwapHeader(
00106                 const TranslatorBitmap *    source,
00107                 TranslatorBitmap *          destination);
00108 private:
00109 
00110 virtual void _ReservedBitmapStream1();
00111 virtual void _ReservedBitmapStream2();
00112 
00113         TranslatorBitmap * fSwappedHeader; /* always in big-endian format */
00114         long _reservedBitmapStream[2];
00115 
00116         void Init(
00117                 BBitmap *       bitmap,
00118                 color_space     preferred);
00119         bool init_xlation(
00120                 color_space     in_memory,
00121                 color_space     external);
00122 
00123         off_t mem_position(
00124                 off_t           ext_pos);
00125         size_t ext_position(
00126                 size_t          mem_pos);
00127         size_t mem_rowbytes(
00128                 size_t          ext_rowbytes);
00129         size_t ext_rowbytes(
00130                 size_t          mem_rowbytes);
00131 
00132         void xlate_in_15_rgb32_l(
00133                 const void *    src,
00134                 size_t          src_size,
00135                 void *          dst);
00136         void xlate_in_15_rgb24_l(
00137                 const void *    src,
00138                 size_t          src_size,
00139                 void *          dst);
00140         void xlate_in_15_rgb32_b(
00141                 const void *    src,
00142                 size_t          src_size,
00143                 void *          dst);
00144         void xlate_in_15_rgb24_b(
00145                 const void *    src,
00146                 size_t          src_size,
00147                 void *          dst);
00148 
00149         void xlate_out_15_rgb32_l(
00150                 const void *    src,
00151                 void *          dst,
00152                 size_t          dst_size);
00153         void xlate_out_15_rgb24_l(
00154                 const void *    src,
00155                 void *          dst,
00156                 size_t          dst_size);
00157         void xlate_out_15_rgb32_b(
00158                 const void *    src,
00159                 void *          dst,
00160                 size_t          dst_size);
00161         void xlate_out_15_rgb24_b(
00162                 const void *    src,
00163                 void *          dst,
00164                 size_t          dst_size);
00165 
00166         void xlate_in_16_rgb32_l(
00167                 const void *    src,
00168                 size_t          src_size,
00169                 void *          dst);
00170         void xlate_in_16_rgb24_l(
00171                 const void *    src,
00172                 size_t          src_size,
00173                 void *          dst);
00174         void xlate_in_16_rgb32_b(
00175                 const void *    src,
00176                 size_t          src_size,
00177                 void *          dst);
00178         void xlate_in_16_rgb24_b(
00179                 const void *    src,
00180                 size_t          src_size,
00181                 void *          dst);
00182 
00183         void xlate_out_16_rgb32_l(
00184                 const void *    src,
00185                 void *          dst,
00186                 size_t          dst_size);
00187         void xlate_out_16_rgb24_l(
00188                 const void *    src,
00189                 void *          dst,
00190                 size_t          dst_size);
00191         void xlate_out_16_rgb32_b(
00192                 const void *    src,
00193                 void *          dst,
00194                 size_t          dst_size);
00195         void xlate_out_16_rgb24_b(
00196                 const void *    src,
00197                 void *          dst,
00198                 size_t          dst_size);
00199 };
00200 
00201 #endif /* _BITMAP_STREAM_H */
00202 

Copyright 2005 by yellowTAB GmbH, Be Inc., Palm Source Inc. and their respective legal successors
All rights reserved.