unsigned char * ReturnDecodedLiveFrame(int webcam_id)
{
   /*
          THIS FRAME DECIDES IF THE VIDEO FORMAT NEEDS DECODING OR CAN BE RETURNED RAW FROM THE DEVICE
          SEE PixelFormats.cpp / PixelFormatConversions.cpp
   */

   if (VideoFormatNeedsDecoding(camera_feeds[webcam_id].input_pixel_format,camera_feeds[webcam_id].input_pixel_format_bitdepth)==1)
                                          {
                                            /*VIDEO COMES IN A FORMAT THAT NEEDS DECODING TO RGB 24*/
                                            if ( DecodePixels(webcam_id)==0 ) return empty_frame;

                                            return (unsigned char *) camera_feeds[webcam_id].decoded_pixels;
                                          } else
                                          {
                                            /* The frame is ready so we mark it as decoded*/
                                            camera_feeds[webcam_id].frame_decoded=1;

                                            if ( camera_feeds[webcam_id].frame == 0 )
                                               {
                                                   /*Handler for when the frame does not exist */
                                                   return empty_frame;
                                               }
                                            return (unsigned char *) camera_feeds[webcam_id].frame;
                                          }
   return empty_frame;
}
Example #2
0
        bool TImage::LoadData(size_t type, const size_t *offsets, IStream *pStream)
        {
            AD_FUNCTION_PERFORMANCE_TEST
            size_t packet_size = 1;
            if (info.depth > 8)
                packet_size++;
            std::vector<unsigned char> pixels((info.width + 256)*packet_size, 0);

            std::vector<unsigned char> compact_pixels;
            if (info.compression == RLECompression)
            {
                size_t length = 0;
                for (size_t y = 0; y < info.height; y++)
                {
                    if(length < offsets[y])
                        length = offsets[y];
                }
                compact_pixels.resize(length, 0);
            }
            for(size_t y = 0; y < info.height; y++)
            {        
                ULONG count = 0;  
                if (info.depth == 1)
                {

                    size_t length = (info.width + 7)/8;
                    if (info.compression != RLECompression)
                        pStream->Read(&pixels[0], (ULONG)length, &count);
                    else
                    {
                        pStream->Read(&compact_pixels[0], (ULONG)offsets[y], &count);
                        if ((size_t)count != offsets[y])
                            break;
                        count = (ULONG)DecodePixels(&compact_pixels[0], offsets[y], (size_t)123456, &pixels[0], length);
                    }
                    if ((size_t)count < length)
                        break;
                }
                else
                {
                    size_t length = packet_size*info.width;
                    if (info.compression != RLECompression)
                        pStream->Read(&pixels[0], (ULONG)length, &count);
                    else
                    {
                        pStream->Read(&compact_pixels[0], (ULONG)offsets[y], &count);
                        if ((size_t)count != offsets[y])
                            break;
                        count = (ULONG)DecodePixels(&compact_pixels[0], offsets[y], info.depth, &pixels[0], length);
                    }
                    if ((size_t)count < length)
                        break;
                }

                TPixel *q = &data[y*info.width];
                const unsigned char *p = &pixels[0];
                for (size_t x = 0; x < info.width; x++)
                {
                    unsigned char pixel;
                    if (packet_size == 1)
                        pixel = *p++;
                    else
                        pixel = ScaleShortToChar(ReadShort(p));
                    switch (type)
                    {
                    case 0:
                        q->red = pixel;
                        if (info.channels == 1)
                        {
                            q->green = q->red;
                            q->blue = q->red;
                            q->alpha = CHANNEL_MAX;
                        }
                        break;
                    case 1:
                        q->green = pixel;
                        break;
                    case 2:
                        q->blue = pixel;
                        if (info.channels == 3)
                            q->alpha = CHANNEL_MAX;
                        break;
                    case 3:
                        q->alpha = pixel;
                        break;
                    case 4:
                        q->alpha = pixel;
                        break;
                    default:
                        break;
                    }
                    q++;
                }
            }
            return true;
        }