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

📄 kdu_show.cpp

📁 该源码是JPEG2000的c++源代码,希望对研究JPEG2000标准以及编解码的朋友们有用.
💻 CPP
📖 第 1 页 / 共 5 页
字号:
BOOL CKdu_showApp::InitInstance(){  AfxEnableControlContainer();#ifdef _AFXDLL  Enable3dControls(); // Call this when using MFC in a shared DLL#else  Enable3dControlsStatic(); // Call this when linking to MFC statically#endif  SetRegistryKey(_T("Kakadu"));  LoadStdProfileSettings(4);  frame = new CMainFrame;  m_pMainWnd = frame;  child = frame->get_child();  child->set_app(this);  frame->LoadFrame(IDR_MAINFRAME,                   WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU |                   WS_THICKFRAME | WS_MINIMIZEBOX,                   NULL,NULL);  frame->ShowWindow(SW_SHOW);  frame->UpdateWindow();  frame->set_app(this);  frame->DragAcceptFiles(TRUE);  kdu_customize_errors(&err_stream,50,kdu_error_callback);  kdu_customize_warnings(&warn_stream,50,kdu_warning_callback);  char *filename = m_lpCmdLine;  while ((*filename != '\0') && ((*filename == ' ') || (*filename == '\t')))    filename++;  if (*filename != '\0')    {      if (*filename == '\"')        {          char *ch = strrchr(filename+1,'\"');          if (ch != NULL)            {              filename++;              *ch = '\0';            }        }      open_file(filename);    }  return TRUE;}/******************************************************************************//*                          CKdu_showApp::open_file                           *//******************************************************************************/void  CKdu_showApp::open_file(char *filename){  close_file();  try {      kdu_compressed_source *input;      char *suffix = strrchr(filename,'.');      if ((suffix != NULL) && ((suffix[1] == 'j') || (suffix[1] == 'J')) &&          ((suffix[2] == 'p') || (suffix[2] == 'P')) &&          ((suffix[3] == '2') || (suffix[3] == 'x') || (suffix[3] == 'X')))        { jp2_input.open(filename); input = &jp2_input; }      else        { file_input.open(filename); input = &file_input; }      codestream.create(input);      tiles_loaded = false;      total_components = codestream.get_num_components();      transpose = vflip = hflip = false;      discard_levels = 0;      max_discard_levels = -1; // We don't yet know how many levels there are.      max_display_layers = 1<<16;      find_channel_mapping();      single_component = -1;      configure_reference();      expansion = min_expansion;      codestream.set_persistent();      if (fast)        codestream.set_fast();      if (resilient || resilient_sop)        codestream.set_resilient(resilient_sop);      if (fussy)        codestream.set_fussy();      initialize_regions();      char title[256];      strcpy(title,"Kakadu show: ");      char *delim = strrchr(filename,'\\');      if ((delim == NULL) || (delim[1] == '\0'))        delim = filename-1;      strncat(title,delim+1,255-strlen(title));      m_pMainWnd->SetWindowText(title);    }  catch (int)    {      close_file();    }}/******************************************************************************//*                      CKdu_showApp::find_channel_mapping                    *//******************************************************************************/void  CKdu_showApp::find_channel_mapping(){  int c;  channels.clear();  if (jp2_input.exists())    { // JP2 file should guide the channel mapping      channels.colour = jp2_input.access_colour();      jp2_channels chnl = jp2_input.access_channels();      jp2_palette palette = jp2_input.access_palette();      channels.num_channels = chnl.get_num_colours();      for (c=0; c < channels.num_channels; c++)        {          int plt_comp;          chnl.get_colour_mapping(c,channels.source_components[c],plt_comp);          if (plt_comp >= 0)            { // Set up palette lookup table              int i, num_entries = palette.get_num_entries();              assert(num_entries <= 1024);              int palette_bits = 1;              while ((1<<palette_bits) < num_entries)                palette_bits++;              channels.palette_bits = palette_bits;              channels.palette[c] = new kdu_sample16[1<<palette_bits];              palette.get_lut(plt_comp,channels.palette[c]);              for (i=num_entries; i < (1<<palette_bits); i++)                (channels.palette[c])[i] = (channels.palette[c])[num_entries-1];            }        }    }  else    { // Raw code-stream input.      channels.num_channels = (total_components >= 3)?3:1;      kdu_coords ref_subs; codestream.get_subsampling(0,ref_subs);      for (c=0; c < channels.num_channels; c++)        {          channels.source_components[c] = c;          kdu_coords subs; codestream.get_subsampling(c,subs);          if (subs != ref_subs)            break;        }      if (c < channels.num_channels)        channels.num_channels = 1;    }}/******************************************************************************//*                      CKdu_showApp::configure_reference                     *//******************************************************************************/void  CKdu_showApp::configure_reference(){  reference_component = single_component;  min_expansion = kdu_coords(1,1);  if (reference_component >= 0)    return;  reference_component = channels.source_components[0];  kdu_coords ref_subs;  codestream.get_subsampling(reference_component,ref_subs);  kdu_coords min_subs = ref_subs;  int c;  for (c=0; c < channels.num_channels; c++)    {      kdu_coords subs;      codestream.get_subsampling(channels.source_components[c],subs);      if (subs.x < min_subs.x)        min_subs.x = subs.x;      if (subs.y < min_subs.y)        min_subs.y = subs.y;    }  min_expansion.x = ref_subs.x / min_subs.x;  min_expansion.y = ref_subs.y / min_subs.y;  for (c=0; c < channels.num_channels; c++)    {      kdu_coords subs;      codestream.get_subsampling(channels.source_components[c],subs);      if ((((subs.x * min_expansion.x) % ref_subs.x) != 0) ||          (((subs.y * min_expansion.y) % ref_subs.y) != 0))        {          kdu_warning w; w << "The supplied JP2 file contains colour channels "          "whose sub-sampling factors are not integer multiples of one "          "another.  Although this is legal, it makes rendering the image "          "impossible without non-integer interpolation of one or more "          "components.  It is highly inadvisable to construct compressed "          "representations of this form, since few applications are likely "          "to support them.  The current application will proceed to display "          "only the first component, by default.";          channels.num_channels = 1;          channels.colour = jp2_colour(NULL);          min_expansion = kdu_coords(1,1);        }    }}/******************************************************************************//*                          CKdu_showApp::close_file                          *//******************************************************************************/void  CKdu_showApp::close_file(){  if (processing)    {      processing = false;      decompressor.finish();    }  if (codestream.exists())    codestream.destroy();  file_input.close();  jp2_input.close();  if (buffer != NULL)    delete[] buffer;  buffer = NULL;  buffer_extent = kdu_coords(0,0);  channels.clear();  expansion = min_expansion = kdu_coords(0,0);  image_dims.pos = image_dims.size = kdu_coords(0,0);  view_dims = buffer_dims = image_dims;  if (child != NULL)    {      child->set_max_view_size(kdu_coords(20000,20000));      if (child->GetSafeHwnd() != NULL)        child->Invalidate();    }  view_centre_known = false;}/******************************************************************************//*                 CKdu_showApp::calculate_max_discard_levels                 *//******************************************************************************/void  CKdu_showApp::calculate_max_discard_levels(){   if (processing)    {      processing = false;      if (!decompressor.finish())        {          close_file();          return;        }    }  try { // We may be parsing the code-stream for the first time      max_discard_levels = -1;      codestream.apply_input_restrictions(0,0,0,0,NULL);      kdu_dims valid_tiles; codestream.get_valid_tiles(valid_tiles);      kdu_coords idx;      for (idx.y=0; idx.y < valid_tiles.size.y; idx.y++)        for (idx.x=0; idx.x < valid_tiles.size.x; idx.x++)          {            kdu_tile tile = codestream.open_tile(valid_tiles.pos+idx);            for (int c=0; c < total_components; c++)              {                kdu_tile_comp tc = tile.access_component(c);                int num_levels = tc.get_num_resolutions()-1;                if ((max_discard_levels < 0) ||                    (num_levels < max_discard_levels))                  max_discard_levels = num_levels;              }            tile.close();          }      tiles_loaded = true;    }  catch (int)    {      close_file();    }}/******************************************************************************//*                      CKdu_showApp::initialize_regions                      *//******************************************************************************/void  CKdu_showApp::initialize_regions(){  // First make sure that there is no processing going on.  if (processing)    {      processing = false;      if (!decompressor.finish())        {          close_file();          return;        }    }  // Next destroy any existing buffering.  if (buffer != NULL)    delete[] buffer;  buffer = NULL;  buffer_extent = kdu_coords(0,0);  // Now find the image region by expanding the reference component.  assert(codestream.exists());  codestream.apply_input_restrictions(0,0,discard_levels,0,NULL);  codestream.change_appearance(transpose,vflip,hflip);  configure_reference();  if ((expansion.x < min_expansion.x) || (expansion.y < min_expansion.y))    expansion = min_expansion;  codestream.get_dims(reference_component,image_dims);  assert((expansion.x >= min_expansion.x) && (expansion.y >= min_expansion.y));  image_dims.size.x *= expansion.x;  image_dims.pos.x = (image_dims.pos.x * expansion.x) - ((expansion.x-1)>>1);  image_dims.size.y *= expansion.y;  image_dims.pos.y = (image_dims.pos.y * expansion.y) - ((expansion.y-1)>>1);  // Reset the buffer and view dimensions to zero size.  valid_dims.pos = buffer_dims.pos = view_dims.pos = image_dims.pos;  valid_dims.size = buffer_dims.size = view_dims.size = kdu_coords(0,0);  // Send a message to the child view window identifying the  // maximum allowable image dimensions.  We expect to hear back (possibly  // after some windows message processing) concerning  // the actual view dimensions via the `set_view_size' function.  child->set_max_view_size(image_dims.size);}/******************************************************************************//*                    CKdu_showApp::calculate_view_centre                     *//******************************************************************************/void  CKdu_showApp::calculate_view_centre(){  if ((!codestream) || (!image_dims))    return;  view_centre_known = true;  view_centre_x =    (float)(view_dims.pos.x + view_dims.size.x/2 - image_dims.pos.x) /      ((float) image_dims.size.x);  view_centre_y =    (float)(view_dims.pos.y + view_dims.size.y/2 - image_dims.pos.y) /      ((float) image_dims.size.y);}/******************************************************************************//*                        CKdu_showApp::set_view_size                         *//******************************************************************************/void  CKdu_showApp::set_view_size(kdu_coords size){  if (!codestream)    return;  // Set view region to the largest subset of the image region consistent with  // the size of the new viewing region.  kdu_dims new_view_dims = view_dims;

⌨️ 快捷键说明

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