⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 imagetype.cpp

📁 Jpeg编解码器的源代码
💻 CPP
字号:
//
// Copyright (c) 1997,1998 Colosseum Builders, Inc.
// All rights reserved.
//
// Colosseum Builders, Inc. makes no warranty, expressed or implied
// with regards to this software. It is provided as is.
//
// See the README.TXT file that came with this software for restrictions
// on the use and redistribution of this file or send E-mail to
// info@colosseumbuilders.com
//

//
//  Title:  Image Type Functions
//
//  Author:  John M. Miano miano@colosseumbuilders.com
//
#include <fstream>
#include <cstdlib>

#include "imagetype.h"

#include "jpgdecoder.h"
#include "bmpdecoder.h"

using namespace std ;

namespace Colosseum
{

//
//  Description:
//
//    This function determines the type of image stored in a stream.
//
//  Parameters:
//    strm:  The image stream
//
//  Return Value:
//    An enumeration that identifies the stream type
//
ImageType GetStreamImageType (const std::string &filename)
{
  ImageType result = UnknownImage ;
  ifstream strm (filename.c_str (), ios::binary) ;
  if (! strm)
    return result ;

  char buffer [10] ;
  strm.read (buffer, sizeof (buffer)) ;
  if (strm.gcount () == sizeof (buffer))
  {
    if (memcmp (buffer, "\xFF\xD8\xFF\xE0", 4) == 0
             && memcmp (&buffer [6], "JFIF", 4) == 0)
    {
      result = JpegImage ;
    }
    else if (memcmp (buffer, "BM", 2) == 0)
    {
      result = BmpImage ;
    }
  }
  return result ;
}

ImageType ReadImage (const std::string &filename,
                BitmapImage &image,
                PROGRESSFUNCTION function,
                void *data)
{
  ImageType type = GetStreamImageType (filename) ;
  if (type == UnknownImage)
    return type ;

  BmpDecoder bmpdecoder ;
  JpegDecoder jpegdecoder ;
  BitmapImageDecoder *decoder ;
  switch (type)
  {
  case BmpImage:
    decoder = &bmpdecoder ;
    break ;
  case JpegImage:
    decoder = &jpegdecoder ;
    break ;
  }

  decoder->setProgressFunction (function, data) ;
  decoder->readImageFile (filename, image) ;
  return type ;
}
ImageType ReadImage2 (const std::string &filename,
                BitmapImage &image)
{
  ImageType type = GetStreamImageType (filename) ;
  if (type == UnknownImage)
    return type ;

  BmpDecoder bmpdecoder ;
  JpegDecoder jpegdecoder ;
  BitmapImageDecoder *decoder ;
  switch (type)
  {
  case BmpImage:
    decoder = &bmpdecoder ;
    break ;
  case JpegImage:
    decoder = &jpegdecoder ;
    break ;
  }

  //decoder->setProgressFunction (function, data) ;
  decoder->readImageFile (filename, image) ;
  return type ;
}


} // End Namespace Colosseum

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -