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

📄 imagedlg.c

📁 这个是boot gui的程序
💻 C
字号:
/*
 *  Start of Zoran Standard Header
 *  Copyright (c) 2005, 2006 Zoran Corporation
 *  
 *  
 *  All rights reserved.  Proprietary and confidential.
 *  
 *  DESCRIPTION for imagedlg.c
 *      Photo image selection and printing dialog
 *  
 *  NEW HISTORY COMMENT (description must be followed by a blank line)
 *  <Enter change description here>

 *  ===== HISTORY of changes in //depot/imgeng/sw/se_gw/gui/imagedlg.c
 *  
 *  26/Jan/06 #6  dstrauss   When switching back to the main menu because of
 *                           a setting key, go directly to that setting.
 *  24/Jan/06 #5  dstrauss   (1) If a print error occurs, allow the user to 
 *                           restart the job by pressing the "select" key.
 *                           (2) Switch back to the main menu if any of the 
 *                           settings keys is pressed.
 *                           (3) "select" starts a color print.
 *   5/Jan/06 #4  dstrauss   Don't try to print if there are no images.
 *  20/Dec/05 #3  dstrauss   Deal with the case where there are no images
 *                           on the card.
 *  15/Dec/05 #2  dstrauss   Added code to display thumbnail previews.
 *  13/Dec/05 #1  dstrauss   Created.
 *  
 *
 *  End of Zoran Standard Header
 */
#include "standard.h"
#include "ifs.h"
#include "vopu.h"
#include "jpegdecoder.h"
#include "memmgr.h"
#include "ts.h"

#include "guigraphics.h"
#include "guievents.h"
#include "dialogs.h"
#include "guiproperties.h"
#include "guistatus.h"
#include "guiactions.h"

#include "uitypes.h"
#include "uigdi.h"

/* Row for image number */
#define IMAGENUMROW 4

/* Row for image LABEL */
#define IMAGELABELROW (VopuHeight() - (36 + 38))
#define IMAGEROW 36

static int currentImageNumber;

static void displayImage(int erase)
{
  void *file_handle;
  int retval;
  IFSResultType ifs_res;
  Uint32 native_image_width;
  Uint32 native_image_height;
  Uint32 native_image_colors;
  Uint32 native_image_bpc;
  static int lastHeight;
  static int lastWidth;
  int height;
  int width;
  int current_line;
  unsigned char *framebuf;
  unsigned char *bandbuf;
  IFSThumbNailType thumbType;

  if (erase || currentImageNumber == 0) {
    GUIEraseRectangle((VopuWidth() - lastWidth)/2, IMAGEROW, 
                      lastWidth, lastHeight);
    return;
  }

  thumbType = GetThumbType (currentImageNumber);
  if (thumbType != IFS_TN_JPEG) {
    int height;
    int width;
    /* this file doesn't have a thumbnail */
    static const char *ptr = "No Thumbnail";
    height = GUITextHeight(ptr);
    width = GUITextWidth(ptr);
    GUIText((VopuWidth() - width)/2, (VopuHeight() - height)/2, ptr, FALSE);
    lastWidth = width;
    lastHeight = (VopuHeight()/2) + (height/2) - IMAGEROW;
    return;
  }

  IFSSetUseThumbNailForJpeg(currentImageNumber, TRUE);

  ifs_res = GetExtents(currentImageNumber,
                       &native_image_width,
                       &native_image_height,
                       &native_image_colors,
                       &native_image_bpc);

  if (ifs_res != IFS_OK ) {
    PSPRINTF("DisplayJpegJob -- can't get image extents (error %d)\n",
             ifs_res);
    IFSSetUseThumbNailForJpeg(currentImageNumber, FALSE);
    return;
  } else {
    PSPRINTF("DisplayJpeg: width %d height %d\n",
             native_image_width, native_image_height);
  }

  /* this is how many lines we have available for the image */
  height = IMAGELABELROW - IMAGEROW;
  lastHeight = height;          /* remember height for erasing */

  /* adjust for non-square pixels */
  height = (height * 3)/2;

  /* We want to preserve the aspect ratio of the original */
  width = (native_image_width * height) / native_image_height;
  lastWidth = width;            /* remember width for erasing */

  file_handle = jpeg_open((void *)currentImageNumber);
  if (!file_handle) {
    PSPRINTF("DisplayJpeg -- can't open jpeg image %d\n",
             currentImageNumber);
    IFSSetUseThumbNailForJpeg(currentImageNumber, FALSE);
    return;
  }
  retval = jpeg_set_image(file_handle, width, height, width);

  if (retval != 0) {
    PSPRINTF("DisplayJpeg -- can't set image output size (error %d)\n",
             retval);
    jpeg_close(file_handle);
    IFSSetUseThumbNailForJpeg(currentImageNumber, FALSE);
    return;
  }

  retval = 
    jpeg_set_selection(file_handle, 
                       0, 0, native_image_height-1, native_image_width-1);
  if (retval != 0) {
    PSPRINTF("DisplayJpeg -- can't set image extents (error %d)\n",
             retval);
    jpeg_close(file_handle);
    IFSSetUseThumbNailForJpeg(currentImageNumber, FALSE);
    return;
  }

  retval = jpeg_output_ycc(file_handle);
  if (retval != 0) {
    PSPRINTF("DisplayJpeg -- can't set output format (error %d)\n",
             retval);
    jpeg_close(file_handle);
    IFSSetUseThumbNailForJpeg(currentImageNumber, FALSE);
    return;
  }

  retval = jpeg_set_rotation(file_handle, JPEG_ROTATE_0);
  if (retval != 0) {
    PSPRINTF("DisplayJpeg -- can't set output rotation (error %d)\n",
             retval);
    jpeg_close(file_handle);
    IFSSetUseThumbNailForJpeg(currentImageNumber, FALSE);
    return;
  }

  framebuf = (unsigned char *)malloc_locked(height * width * 3);
  if (!framebuf) {
    PSPRINTF("DisplayJpeg -- can't get band buffer\n");
    jpeg_close(file_handle);
    IFSSetUseThumbNailForJpeg(currentImageNumber, FALSE);
    return;
  }

  for (current_line = 0; current_line < height; ) {
    int lines;

    bandbuf = framebuf + (current_line * width * 3);

    lines = height - current_line;
    /* just do 10 lines at a time */
    if (lines > 10) {
      lines = 10;
    }
    retval = jpeg_dec_band(file_handle, lines, (char *)bandbuf);
    if (retval < 0) {
      PSPRINTF("DisplayJpeg -- can't decode band (error %d)\n",
               retval);
      jpeg_close(file_handle);
      IFSSetUseThumbNailForJpeg(currentImageNumber, FALSE);
      free(framebuf);
      return;
    }
    TASKYIELD();
    current_line += lines;
  }

  GUIDisplayYUVImage((VopuWidth() - width)/2, IMAGEROW, 
                     width, height, framebuf);

  jpeg_close(file_handle);
  IFSSetUseThumbNailForJpeg(currentImageNumber, FALSE);
  free(framebuf);

#ifdef MEMMGR_DEBUG
  memmgr_print_file_high_waters();
  memmgr_reset_high_waters();
#endif
}


static void displayImageNumber(int erase)
{
  if (erase) {
    int height;

    height = GUITextHeight("X") - 2;
    GUIEraseRectangle(VopuWidth()/2, IMAGENUMROW, VopuWidth()/2, height);
  } else {
    char buf[36];
    int textSize;

    sprintf(buf, "%d of %d", currentImageNumber, GetNumberOfImages());
    textSize = GUITextWidth((const char *)buf);

    GUIText(VopuWidth() - textSize - 8, IMAGENUMROW, buf, erase);
  }
}

static void displayImageLabel(int erase)
{
  if (erase) {
    int height;
    height = GUITextHeight("X");
    GUIEraseRectangle(0, IMAGELABELROW, VopuWidth(), height-2);
  } else {
    char buf[64];
    int textSize;
    IFSResultType ifs_result;
    if (currentImageNumber == 0) {
      strcpy(buf, "No Images");
    } else {
      ifs_result = GetLabel(currentImageNumber, buf);
      if (ifs_result != IFS_OK) {
        strcpy(buf, "Bad Image");
      } else {
        // remove the file extension
        char* ptr;
        ptr = buf + strlen(buf) - 1;
        while( ptr > buf ) {
          if( *ptr == '.') {
            *ptr = 0;
            break;
          }
          ptr--;
        }
      }
    }
    textSize = GUITextWidth((const char *)buf);
    GUIText((VopuWidth() - textSize)/2, IMAGELABELROW, buf, erase);
  }
}


/* main dialog entrypoint */
void * ImageSelectDialog(unsigned int event)
{
  int imageCount;
  int itemID;


  switch (event) {
  case GUIEVENT_REPAINT:
    if (GetNumberOfImages() > 0) {
      currentImageNumber = 1;
    } else {
      currentImageNumber = 0;
    }
    displayImageNumber(FALSE);
    displayImageLabel(FALSE);
    displayImage(FALSE);
    break;

  case GUIEVENT_KEY_SELECT_DOWN:    /* the "select" key has been pressed */
    if (GUIGetStatus() == GStatusPrinting) {
      /* restart a job if it's stalled because of an error */
      GUIActionRestartJob();
    } else if (GetNumberOfImages() > 0) {
      /* start a color print */
      GUIActionStartPhoto(currentImageNumber, TRUE);
    }
    break;

  case GUIEVENT_KEY_COPIES_DOWN:
    itemID = GPID_COPIES;
    goto handleGotoItem;

  case GUIEVENT_KEY_SCALE_DOWN:
    itemID = GPID_SCALE;
    goto handleGotoItem;

  case GUIEVENT_KEY_BRIGHTNESS_DOWN:
    itemID = GPID_BRIGHTNESS;
    goto handleGotoItem;

  case GUIEVENT_KEY_PAPERTYPE_DOWN:
    itemID = GPID_PAPERTYPE;
    goto handleGotoItem;

  case GUIEVENT_KEY_QUALITY_DOWN:
    itemID = GPID_QUALITY;
    goto handleGotoItem;

  case GUIEVENT_KEY_MODE_DOWN:
    itemID = GPID_MODE;
    goto handleGotoItem;

  handleGotoItem:
    /* switch back to the appropriate item on the main menu */
    GUIActionMainMenuGotoItem(itemID);
    /* flow through */
  case GUIEVENT_KEY_MENU_DOWN:
    displayImageNumber(TRUE); /* erase image from screen */
    displayImageLabel(TRUE);
    displayImage(TRUE);
    return ((void *)MainDialog);

  case GUIEVENT_KEY_CANCEL_DOWN:    /* the "cancel" key has been pressed */
    if (GUIGetStatus() == GStatusPrinting) {
      int didCancel;
      didCancel = GUIActionCancelJob();
      if (didCancel) {
        GUISetStatus(GStatusCanceling);
      }
    } else {
      displayImageNumber(TRUE); /* erase image number from screen */
      displayImageLabel(TRUE);
      displayImage(TRUE);
      return ((void *)MainDialog);
    }
    break;

  case GUIEVENT_KEY_LEFT_DOWN:    /* the "left" key has been pressed */
    displayImageNumber(TRUE);   /* erase the current image number and label */
    displayImageLabel(TRUE);
    displayImage(TRUE);
    currentImageNumber--;
    if (currentImageNumber <= 0) {
      currentImageNumber = GetNumberOfImages();
    }
    displayImageNumber(FALSE);  /* display the new image number and label */
    displayImageLabel(FALSE);
    displayImage(FALSE);
    break;

  case GUIEVENT_KEY_RIGHT_DOWN:    /* the "left" key has been pressed */
    displayImageNumber(TRUE); /* erase the current image number and label */
    displayImageLabel(TRUE);
    displayImage(TRUE);
    imageCount = GetNumberOfImages();
    if (imageCount > 0) {
      currentImageNumber++;
    } else {
      currentImageNumber = 0;
    }
    if (currentImageNumber > imageCount) {
      currentImageNumber = 1;
    }
    displayImageNumber(FALSE);  /* display the new image number and label */
    displayImageLabel(FALSE);
    displayImage(FALSE);
    break;

  case GUIEVENT_KEY_MONOPHOTO_DOWN: /* mono photoprint key */
    if (GetNumberOfImages() > 0) {
      GUIActionStartPhoto(currentImageNumber, FALSE);
    }
    break;

  case GUIEVENT_KEY_COLORPHOTO_DOWN: /* color photoprint key */
    if (GetNumberOfImages() > 0) {
      GUIActionStartPhoto(currentImageNumber, TRUE);
    }
    break;

  case GUIEVENT_KEY_COLORCOPY_DOWN: /* the "color copy" key has been pressed */
    GUIActionCopyJobColor();
    break;

  case GUIEVENT_KEY_MONOCOPY_DOWN: /* the "color copy" key has been pressed */
    GUIActionCopyJobMono();
    break;

  case GUIEVENT_TICK:
    GUIUpdateStatus();
    if (!GUIMemcardReady()) {
      displayImageNumber(TRUE); /* erase image number and label from screen */
      displayImageLabel(TRUE);
      displayImage(TRUE);
      return ((void *)MainDialog);
    }
    break;

  default:                  /* ignore events not explicitly handled */
    break;
  }

  return (NULL);
}

⌨️ 快捷键说明

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