Exemplo n.º 1
0
  public void readVidepFile_576v(String filePath) {
    RandomAccessFile videoFile = null;
    try {
      videoFile = new RandomAccessFile(filePath, "r");

      // byte[] buff = new byte[3*Main.h*Main.w];
      // videoFile.readFully(buff);

      for (int i = 0; i < noOfFrames; ++i) {
        ImageFile img = new ImageFile(height, width);
        frames.add(img);
        int buffid = 0;
        byte[] buff = new byte[3 * height * width];
        videoFile.readFully(buff);
        for (int m = 0; m < 3; ++m) {
          for (int y = 0; y < height; ++y) {
            System.arraycopy(buff, buffid, img.getData()[m][y], 0, width);
            buffid += width;
          }
        }
      }
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    } finally {
      try {
        if (videoFile != null) videoFile.close();
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
  }
Exemplo n.º 2
0
  private static void createFrames(final EmoticonImage icon, boolean layout) {
    if (!equals(icon.protocol, getCurrentSelectedProtocol())) return;

    if (icon.emoticon.frames.isDisposed()) return;

    boolean disposed = disposeAllChildren(icon.emoticon.frames);

    final ImageFile image;
    if (icon.image == null) image = icon.emoticon.icons.get(null).image;
    else image = icon.image;

    if (image == null) {
      if (disposed && layout) layout(icon.emoticon);
      return;
    }

    image.loadFrames();
    if (image.frames == null) {
      if (disposed && layout) layout(icon.emoticon);
      return;
    }

    Listener listener =
        new Listener() {
          public void handleEvent(Event e) {
            Button button = (Button) e.widget;

            Control[] children = icon.emoticon.frames.getChildren();
            for (int i = 0; i < children.length; i++) {
              Control child = children[i];
              if (e.widget != child
                  && child instanceof Button
                  && (child.getStyle() & SWT.TOGGLE) != 0) {
                ((Button) child).setSelection(false);
              } else if (child == button) {
                image.frame = i;
              }
            }
            button.setSelection(true);
          }
        };

    Image[] frames = image.frames;
    for (int j = 0; j < frames.length; j++) {
      Button button = new Button(icon.emoticon.frames, SWT.TOGGLE);
      button.setImage(frames[j]);
      if (j == image.frame) button.setSelection(true);
      button.addListener(SWT.Selection, listener);
    }

    if (layout) layout(icon.emoticon);
  }
Exemplo n.º 3
0
  @Override
  public void deleteImage(String path) {
    List<ImageFileImpl> imageFiles;
    // No file extension, should be a directory
    if (StringUtils.isEmpty(FilenameUtils.getExtension(path))) {
      if (!path.endsWith(SystemUtils.FILE_SEPARATOR)) {
        path = path + SystemUtils.FILE_SEPARATOR;
      }
      path = FilenameUtils.separatorsToUnix(path);
      imageFiles =
          this.entityManager
              .createQuery(
                  "SELECT i FROM IMAGE_FILE i WHERE i.filePath LIKE ?1", ImageFileImpl.class)
              .setParameter(1, path + "%")
              .getResultList();
    }
    // Path is file
    else {
      path = FilenameUtils.separatorsToUnix(path);
      imageFiles =
          this.entityManager
              .createQuery(
                  "SELECT i FROM IMAGE_FILE i WHERE i.absolutePath = ?1", ImageFileImpl.class)
              .setParameter(1, path)
              .getResultList();
    }

    // Delete old images
    if (imageFiles != null && !imageFiles.isEmpty()) {
      for (ImageFile imageFile : imageFiles) {
        Image image = imageFile.getImage();
        if (image != null) {
          this.entityManager.remove(image);
        } else {
          this.entityManager.remove(imageFile);
        }
      }
    }
  }
Exemplo n.º 4
0
 private FileInfo extractFileInfo(Cursor cur, int type) {
   FileInfo fileInfo = null;
   switch (type) {
     case TYPE_IMAGE:
       fileInfo = ImageFile.getInfo(cur);
       break;
     case TYPE_AUDIO:
       fileInfo = AudioFile.getInfo(cur);
       break;
     case TYPE_VIDEO:
       fileInfo = VideoFile.getInfo(cur);
       break;
   }
   return fileInfo;
 }
Exemplo n.º 5
0
  public static void readNextFrame_576v(ImageFile img, RandomAccessFile videoFile, int h, int w) {
    try {
      byte[] buff = new byte[3 * h * w];
      videoFile.readFully(buff);
      int buffid = 0;

      for (int m = 0; m < 3; ++m) {
        for (int y = 0; y < h; ++y) {
          System.arraycopy(buff, buffid, img.getData()[m][y], 0, w);
          buffid += w;
        }
      }
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 6
0
  @Override
  public void synchronizeImage(ImageFile imageFile) {
    // If the file already exist in DB, keep current Image, replace ImageFile
    List<ImageFileImpl> imageFiles =
        this.entityManager
            .createQuery(
                "SELECT i FROM IMAGE_FILE i WHERE i.absolutePath = ?1", ImageFileImpl.class)
            .setParameter(1, imageFile.getAbsolutePath())
            .getResultList();
    if (imageFiles != null && imageFiles.size() == 1) {
      imageFiles.get(0).getImage().setOriginalFile(imageFile);
    }

    // Delete old ImageFiles
    this.entityManager
        .createQuery("DELETE FROM IMAGE_FILE i WHERE i.absolutePath = ?1")
        .setParameter(1, imageFile.getAbsolutePath())
        .executeUpdate();

    // Merge/Persist Image/ImageFile into DB
    if (imageFile.getImage() != null) {
      this.entityManager.merge(imageFile.getImage());
    } else {
      // TODO: Should use factory here
      Image image = new ImageImpl();
      image.setOriginalFile(imageFile);
      image.setAlbum(
          FilenameUtils.getName(FilenameUtils.getFullPathNoEndSeparator(imageFile.getFilePath())));
      image.setTitle(FilenameUtils.removeExtension(imageFile.getFileName()));
      this.entityManager.merge(image);
    }

    // Delete empty Images
    this.entityManager
        .createQuery("DELETE FROM IMAGE i WHERE i.originalFile IS NULL")
        .executeUpdate();
  }
 protected void load(URL file) {
   super.load(file);
   makeSheet();
 }
Exemplo n.º 8
0
  public synchronized void initImage() {
    if (null == mImageCategory) {
      mImageCategory = new ConcurrentHashMap<String, Category>();
    }
    mImageCategory.clear();

    String volumeName = "external";
    Uri uri = Images.Media.getContentUri(volumeName);
    String[] columns =
        new String[] {
          BaseColumns._ID,
          MediaColumns.DATA,
          MediaColumns.DISPLAY_NAME,
          MediaColumns.SIZE,
          MediaColumns.DATE_ADDED,
          MediaColumns.DATE_MODIFIED,
          ImageColumns.BUCKET_DISPLAY_NAME,
          MediaColumns.MIME_TYPE
        };
    Cursor cur = null;
    try {
      cur =
          mContext
              .getContentResolver()
              .query(uri, columns, buildSelectionByCategory(TYPE_IMAGE), null, null);
      if (cur == null) {
        return;
      }

      if (!cur.moveToFirst()) {
        return;
      }

      do {
        ImageFile file = ImageFile.getInfo(cur);
        if (null == file) {
          continue;
        }
        // 取一张图片的路径,add by yangbing
        //				if (MediaOpenSettingConstants.sImagePath == null) {
        //					if (file.fullFilePath != null && !"".equals(file.fullFilePath)) {
        //						MediaOpenSettingConstants.sImagePath = file.fullFilePath;
        //					}
        //				}
        if (mImageCategory.containsKey(file.filePath)) {
          Category category = mImageCategory.get(file.filePath);
          category.addFile(file);
        } else {
          Category category = new Category();
          category.filePath = file.filePath;
          category.uri = category.filePath;
          category.alias = file.bucketName;
          category.init();
          category.addFile(file);
          mImageCategory.put(file.filePath, category);
        }
      } while (cur.moveToNext());
    } catch (SQLiteException e) {
      Log.e("FileEngine", "init image error");
    } finally {
      if (cur != null) {
        cur.close();
      }
    }
  }