added OCR capability
[meviz.git] / src / main / java / eu / svjatoslav / meviz / encoder / FormatsRegistry.java
1 /*
2  * Meviz - Various tools collection to work with multimedia.
3  * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of version 2 of the GNU General Public License
7  * as published by the Free Software Foundation.
8  */
9
10 package eu.svjatoslav.meviz.encoder;
11
12 import java.util.ArrayList;
13 import java.util.List;
14
15 import eu.svjatoslav.meviz.encoder.converters.AbstractConverter;
16 import eu.svjatoslav.meviz.encoder.converters.AvconvAudio;
17 import eu.svjatoslav.meviz.encoder.converters.AvconvVideo;
18 import eu.svjatoslav.meviz.encoder.converters.Convert;
19 import eu.svjatoslav.meviz.encoder.converters.Ffmpeg2theora;
20 import eu.svjatoslav.meviz.encoder.converters.Flac;
21 import eu.svjatoslav.meviz.encoder.converters.Midi2Wav;
22 import eu.svjatoslav.meviz.encoder.converters.Ocr;
23 import eu.svjatoslav.meviz.encoder.converters.Ogg2Wav;
24
25 public class FormatsRegistry {
26
27         public ArrayList<AbstractConverter> encoders = new ArrayList<AbstractConverter>();
28
29         public FormatsRegistry() {
30                 // video conversion
31                 registerEncoder(new Ffmpeg2theora());
32                 registerEncoder(new AvconvVideo());
33
34                 // image conversion
35                 registerEncoder(new Convert());
36
37                 // image to text (OCR)
38                 registerEncoder(new Ocr());
39
40                 // audio conversion
41                 registerEncoder(new Ogg2Wav());
42                 registerEncoder(new Flac());
43                 registerEncoder(new AvconvAudio());
44                 registerEncoder(new Midi2Wav());
45         }
46
47         public List<AbstractConverter> getEncoders(final String sourceFormat,
48                         final String targetFormat) {
49
50                 final String sourceFormatLowerCase = sourceFormat.toLowerCase();
51                 final String targetFormatLowerCase = targetFormat.toLowerCase();
52
53                 final ArrayList<AbstractConverter> encoders = new ArrayList<AbstractConverter>();
54
55                 for (final AbstractConverter encoder : this.encoders)
56                         if (encoder.supportsSource(sourceFormatLowerCase))
57                                 if (encoder.supportsTarget(targetFormatLowerCase)) {
58                                         encoders.add(encoder);
59                                         return encoders;
60                                 }
61
62                 return encoders;
63         }
64
65         public void registerEncoder(final AbstractConverter encoder) {
66                 encoders.add(encoder);
67         }
68
69 }