Tema: Re: Q: reikia trenktų programerių pagalbos
Autorius: ejs
Data: 2009-04-17 02:42:35
sekantis klausimas:

MatLAB'e paprasta, ne taip kaip Java:

  % surankiojam parametrus
....
    % tile's width and height
    tmp = str2num(char(pl.getParameter('tiles')));
    tw=tmp(1); th=tmp(2);

% kiekvieną komponentą transformuojam į vektorių
  if (size(img,2) == 3)
        img_tmp(1,:) = reshape(img(:,:,1), 1,[]);
        img_tmp(2,:) = reshape(img(:,:,2), 1,[]);
        img_tmp(3,:) = reshape(img(:,:,3), 1,[]);
        ci = [1 2 3];
    else
        img_tmp = reshape(img, 1,[]);
        ci = 1;
    end

% pasidarom 'javaArray'
% ibo testinis vaizdelis j/b, užteks vieno komponento

% kokio tipo turi būti 'img_'???
% ir iš viso masyvas jis ar ne?
% java.lang.Vector ?
% jj2000.j2k.image.input.ImgReader ?
% jj2000.j2k.image.BlkImgDataSrc ?
% nuo 'Tiler' konstruktoriaus masyvo tikrai neėmiau :(

    img_ = javaArray('jj2000.j2k.image.input.ImgReader',size(img_tmp,2));
    for l=1:size(img_tmp,2)
       img_(l) = jj2000.j2k.image.input.ImgReader(img_tmp(1,l));
    end
    imgtiler = jj2000.j2k.image.Tiler(img_,refx,refy,trefx,trefy,tw,th);


architektūra pagal JavaDOC:
  * <ul>
  * <li>ImgReader</li>
  * <li>ImgDataJoiner (if multiple image readers)</li>
  * <li>ForwCompTransf</li>
  * <li>Tiler</li>
  * <li>ImgDataConverter</li>
  * <li>ForwardWT</li>
  * <li>Quantizer</li>
  * <li>ROIScaler</li>
  * <li>EntropyCoder</li>
  * <li>PostCompRateAllocator</li>
  * </ul>
  *
  * <P>The encoder uses a pull model. This means that the last module
  * (PostCompRateAllocator) requests data from its source 
(EntropyCoder),
  * ...


Java:

pasaka tęsiasi taip (atmetus catch()):

//skaitom iš PPM | PGM | PPX failų:
imreadervec = new Vector();
....
imreadervec.addElement(new ImgReaderPGM(infile));
// arba
imreadervec.addElement(new ImgReaderPPM(infile));
// arba
imreadervec.addElement(new ImgReaderPGX(infile));

imreader = new ImgReader[imreadervec.size()];
imreadervec.copyInto(imreader);
imreadervec.removeAllElements();
imreadervec = null;
imsigned = new boolean[ncomp];

// **** ImgDataJoiner (if needed) ****
if (ppminput || ncomp == 1) { // Just one input
     imgsrc = imreader[0];
     for (i=0; i<ncomp; i++) {
          imsigned[i] = imreader[0].isOrigSigned(i);
     }
  }
else { // More than one reader => join all readers into 1
     imgcmpidxs = new int[ncomp];
     for (i=0; i<ncomp; i++) {
         imsigned[i] = imreader[i].isOrigSigned(0);
     }
     imgsrc = new ImgDataJoiner(imreader,imgcmpidxs);
  }

// **** Tiler ****
// rankiojam parametrus
....
// Instantiate tiler
   imgtiler = new Tiler(imgsrc,refx,refy,trefx,trefy,tw,th);




  klasių medis:


public interface ImgData {
   ...

public interface BlkImgDataSrc extends ImgData {
   ...

public abstract class ImgReader implements BlkImgDataSrc {
   ...

public abstract class ImgDataAdapter implements ImgData {
   /** Index of the current tile */
   protected int tIdx = 0;
   /** The ImgData source */
   protected ImgData imgdatasrc;

// kitų konstruktorių čią nėrą
  protected ImgDataAdapter(ImgData src) {
         imgdatasrc = src;
     }



public class ImgDataJoiner implements BlkImgDataSrc {
     /** The list of input ImgData */
     private BlkImgDataSrc[] imageData;
     /** The component index associated with each ImgData */
     private int[] compIdx;

    // kitų konstruktorių čią nėrą
     public ImgDataJoiner(BlkImgDataSrc[] imD, int[] cIdx){
          int i;
          int maxW, maxH;

	 // Initializes
	 imageData = imD;
	 compIdx = cIdx;
          ...
public class Tiler extends ImgDataAdapter implements BlkImgDataSrc {
     /** The source of image data */
     private final BlkImgDataSrc src;
     private final int ax;
     private final int ay;
     private final int py;
     private final int nw;
     private final int nh;
  ...
     public Tiler(BlkImgDataSrc src,int ax,int ay,int px,int py,int 
nw,int nh) {
         super(src);

         int i,w,h;

         // Verify that input is not tiled
         if (src.getNumTiles() != 1) {
             throw new IllegalArgumentException("Source is tiled");
         }
         ...

-- 
  ejs