00001 /* 00002 * PROPRIETARY INFORMATION. This software is proprietary to 00003 * Side Effects Software Inc., and is not to be reproduced, 00004 * transmitted, or disclosed in any way without written permission. 00005 * 00006 * Produced by: 00007 * Mark Elendt 00008 * Side Effects Software Inc 00009 * 477 Richmond Street West 00010 * Toronto, Ontario 00011 * Canada M5V 3E7 00012 * 416-504-9876 00013 * 00014 * NAME: IMG_RLEncode.h ( IMG Library, C++) 00015 * 00016 * COMMENTS: This class is a class which handles RLE encoding of character 00017 * data. It only works on a single channel at a time, meaning 00018 * that each channel in the image is encoded separately. 00019 * This is the mechanism used in Vertigo, Wavefront and several 00020 * other formats. 00021 */ 00022 00023 #ifndef __IMG_RLEncode__ 00024 #define __IMG_RLEncode__ 00025 00026 #include "IMG_API.h" 00027 class IMG_Plane; 00028 00029 class IMG_API IMG_RLEncode { 00030 public: 00031 IMG_RLEncode(); 00032 ~IMG_RLEncode(); 00033 00034 // This method will return a size (in chars) which is big enough to hold 00035 // any RLE scanline (in chars) 00036 int bytesPerChannel(int xres); 00037 00038 // This method should be called before you do any RLE encoding 00039 void allocEncodeBuffer(int xres); 00040 00041 // This method will rl encode the data into the buffer above. It returns 00042 // the buffer and returns the length of the encoded data in 00043 // "result_length". When encoding, you can skip N bytes by specifying a 00044 // stride. The stride should be greater than 0 to work. 00045 char *encode(const char *data, int data_length, 00046 int &result_length, int stride=4); 00047 00048 // This method returns 0 on failure, or the number of bytes read from the 00049 // data stream. 00050 int decode(char *result, int result_length, const char *data, 00051 int stride=4); 00052 00053 // This method will return: 00054 // > 0 = repeat of first pixel_size bytes 00055 // < 0 = -raw count of first pixel_size bytes 00056 // For example, if the pixel_size is 1: 00057 // 00000100 - will return 5 (indicating a repeat count of 5) 00058 // 01010111 - will return -5 (indicating a raw run of 5) 00059 static int getRepeatCount(const char *data, int pixel_size, 00060 int max_run = 128, int stride=4); 00061 00062 // 00063 // Encode a scanline into YUV format. The stat() is used to determine the 00064 // format of the rgb data as well as the length of the scanline. The YUV 00065 // buffer should be at least 3*stat.getXres() bytes long. 00066 // The return code is the length of the encoded YUV buffer. 00067 static int yuvEncode(unsigned char *yuvdata, const void *rgbdata, 00068 const IMG_Plane &plane, int xres); 00069 00070 // Decode is the opposite of encode. The YUV data is decoded into the RGB 00071 // data. 00072 static int yuvDecode(void *rgbdata, const unsigned char *yuvdata, 00073 const IMG_Plane &plane, int xres); 00074 00075 private: 00076 char *myData; 00077 }; 00078 00079 #endif
1.5.9