c - 如何使用LibRaw(c++)获取CR2图像的原始数据

标签 c sdk dcraw libraw

LibRaw 是一个用于从数码相机读取 RAW 文件的库(CRW/CR2、NEF、RAF、DNG、MOS、KDC、DCR 等;几乎支持所有 RAW 格式)。 我想知道如何使用LibRaw获取佳能CR2图像的原始数据。

typedef struct
{
  ushort                      (*image)[4] ;
  libraw_image_sizes_t        sizes;
  libraw_iparams_t            idata;
  libraw_lensinfo_t           lens;
  libraw_makernotes_t         makernotes;
  libraw_shootinginfo_t       shootinginfo;
  libraw_output_params_t      params;
  unsigned int                progress_flags;
  unsigned int                process_warnings;
  libraw_colordata_t          color;
  libraw_imgother_t           other;
  libraw_thumbnail_t          thumbnail;
  libraw_rawdata_t            rawdata;
  void                *parent_class;
} libraw_data_t;
typedef struct
{
  void          *raw_alloc;
  ushort        *raw_image;
  ushort        (*color4_image)[4] ;
  ushort        (*color3_image)[3];
  float         *float_image;
  float         (*float3_image)[3];
  float         (*float4_image)[4];
  short  (*ph1_cblack)[2];//
  short  (*ph1_rblack)[2];//
  libraw_iparams_t  iparams;//
  libraw_image_sizes_t sizes;//
  libraw_internal_output_params_t ioparams;//
  libraw_colordata_t color;//
} libraw_rawdata_t;

这是RAW数据的数据结构,我不知道最原始的数据存储在哪个结构中。

最佳答案

我已经得到了答案,现在下载如下,希望能帮助到有需要的人。

    int i,ret,verbose = 0,output_thumbs = 0;
    char outfn [1024],thumbfn [1024];

    //Create object
    LibRaw RawProcessor;
    putenv((char *)"TZ = UTC+8");
    //
#define P1 RawProcessor.imgdata.idata
#define S RawProcessor.imgdata.sizes
#define C RawProcessor.imgdata.color
#define T RawProcessor.imgdata.thumbnail
#define P2 RawProcessor.imgdata.other
#define OUT RawProcessor.imgdata.params
    OUT.output_tiff = 0; //
    OUT.no_auto_scale=1;//
    OUT.no_auto_bright=1;//
    OUT.output_bps=16;//16bit
    OUT.output_color=0;//RAW

    //openfile
    if((ret = RawProcessor.open_file(szFile))!= LIBRAW_SUCCESS)
    {
        fprintf(stderr,"Can not open%s:%s\n",szFile,libraw_strerror(ret));
        RawProcessor.recycle();
        return FALSE;
    }


    //RAW size
    int height=S.raw_height;
    int width=S.raw_width;




    //image info
    memset(LinsnData.imgdata.make,0,64*sizeof(char));
    memset(LinsnData.imgdata.model,0,64*sizeof(char));
    memcpy(LinsnData.imgdata.make,P1.make,strlen(P1.make));
    memcpy(LinsnData.imgdata.model,P1.model,strlen(P1.model));
    LinsnData.imgdata.aperture=P2.aperture;
    LinsnData.imgdata.iso_speed=P2.iso_speed;
    LinsnData.imgdata.shutter=P2.shutter;
    char timestamp[64]= {0};
    tm* local = localtime(&P2.timestamp); //
    strftime(LinsnData.imgdata.timestamp, 64, "%Y-%m-%d %H:%M:%S", local);
    /***************************************************************************************************/
    //
    if((ret = RawProcessor.unpack())!= LIBRAW_SUCCESS)
    {
        fprintf(stderr,"Can not unpack_thumb%s:%s\n",szFile,libraw_strerror(ret));
        //if(LIBRAW_FATAL_ERROR(ret))
        goto end;
    }

    WORD *bmpData=RawProcessor.imgdata.rawdata.raw_image;

    int nWidth  = width/2;
    int nHeight = height/2;
    WORD *m_bmpDataR = new WORD[nWidth*nHeight];
    WORD *m_bmpDataG = new WORD[nWidth*nHeight]; 
    WORD *m_bmpDataB = new WORD[nWidth*nHeight];

    //
    for(int i=0;i<nHeight;i++)     
    {
        for(int j=0;j<nWidth;j++)
        {                                                                                                   
            m_bmpDataB[i*nWidth+j]  = bmpData[i*nWidth*4+nWidth*2+j*2+1];                                   
            m_bmpDataG[i*nWidth+j]  = ((bmpData[i*nWidth*4+nWidth*2+j*2]+bmpData[i*nWidth*4+j*2+1])>>1);    
            m_bmpDataR[i*nWidth+j]  = bmpData[i*nWidth*4+j*2];                                              
        }
    }

关于c - 如何使用LibRaw(c++)获取CR2图像的原始数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51319494/

相关文章:

java - 我可以在没有 IDE 的情况下开发 Android 应用程序吗?

android - Android 4.2(及以上)修改AIRPLANE_MODE_ON

python - Python中的RAW图像处理

c - 添加 0xff 对按位运算的影响

c - 时钟为什么不走?它停留在 0.000000000。

c - linux下按ctrl+c时如何避免内存泄漏?

iphone - iOS;如何(永久)缩放 UIimageView 然后 move 它

c++ - 原始图像和 C++ 中的 DCRaw

c - dcraw的gamma_curve实现的算法叫什么名字?

c - 单个字符的strtok