Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | RSS feed

  1. /*
  2.  * Copyright (c) 2005, Hervé Drolon, FreeImage Team
  3.  * Copyright (c) 2006, Mónica Díez García, Image Processing Laboratory, University of Valladolid, Spain
  4.  * All rights reserved.
  5.  *
  6.  * Redistribution and use in source and binary forms, with or without
  7.  * modification, are permitted provided that the following conditions
  8.  * are met:
  9.  * 1. Redistributions of source code must retain the above copyright
  10.  *    notice, this list of conditions and the following disclaimer.
  11.  * 2. Redistributions in binary form must reproduce the above copyright
  12.  *    notice, this list of conditions and the following disclaimer in the
  13.  *    documentation and/or other materials provided with the distribution.
  14.  *
  15.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
  16.  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  18.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  19.  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  20.  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  21.  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  22.  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  23.  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  24.  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  25.  * POSSIBILITY OF SUCH DAMAGE.
  26.  */
  27.  
  28. #ifdef _WIN32
  29. #include <windows.h>
  30. #endif /* _WIN32 */
  31.  
  32. #include "opj_includes.h"
  33. #define JP3D_VERSION "1.3.0"
  34. /* ---------------------------------------------------------------------- */
  35. #ifdef _WIN32
  36. #ifndef OPJ_STATIC
  37. BOOL APIENTRY
  38. DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
  39.         switch (ul_reason_for_call) {
  40.                 case DLL_PROCESS_ATTACH :
  41.                         break;
  42.                 case DLL_PROCESS_DETACH :
  43.                         break;
  44.                 case DLL_THREAD_ATTACH :
  45.                 case DLL_THREAD_DETACH :
  46.                         break;
  47.     }
  48.  
  49.     return TRUE;
  50. }
  51. #endif /* OPJ_STATIC */
  52. #endif /* _WIN32 */
  53.  
  54. /* ---------------------------------------------------------------------- */
  55.  
  56. const char* OPJ_CALLCONV opj_version() {
  57.     return JP3D_VERSION;
  58. }
  59. opj_dinfo_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT format) {
  60.         opj_dinfo_t *dinfo = (opj_dinfo_t*)opj_malloc(sizeof(opj_dinfo_t));
  61.         if(!dinfo) return NULL;
  62.         dinfo->is_decompressor = true;
  63.         switch(format) {
  64.                 case CODEC_J3D:
  65.                 case CODEC_J2K:
  66.                         /* get a J3D decoder handle */
  67.                         dinfo->j3d_handle = (void*)j3d_create_decompress((opj_common_ptr)dinfo);
  68.                         if(!dinfo->j3d_handle) {
  69.                                 opj_free(dinfo);
  70.                                 return NULL;
  71.                         }
  72.                         break;
  73.                 default:
  74.                         opj_free(dinfo);
  75.                         return NULL;
  76.         }
  77.  
  78.         dinfo->codec_format = format;
  79.  
  80.         return dinfo;
  81. }
  82.  
  83. void OPJ_CALLCONV opj_destroy_decompress(opj_dinfo_t *dinfo) {
  84.         if(dinfo) {
  85.                 /* destroy the codec */
  86.                 if(dinfo->codec_format != CODEC_UNKNOWN) {
  87.                         j3d_destroy_decompress((opj_j3d_t*)dinfo->j3d_handle);
  88.                 }
  89.                 /* destroy the decompressor */
  90.                 opj_free(dinfo);
  91.         }
  92. }
  93.  
  94. void OPJ_CALLCONV opj_set_default_decoder_parameters(opj_dparameters_t *parameters) {
  95.         if(parameters) {
  96.                 memset(parameters, 0, sizeof(opj_dparameters_t));
  97.                 /* default decoding parameters */
  98.                 parameters->cp_layer = 0;
  99.                 parameters->cp_reduce[0] = 0;
  100.                 parameters->cp_reduce[1] = 0;
  101.                 parameters->cp_reduce[2] = 0;
  102.                 parameters->bigendian = 0;
  103.  
  104.                 parameters->decod_format = -1;
  105.                 parameters->cod_format = -1;
  106.         }
  107. }
  108.  
  109. void OPJ_CALLCONV opj_setup_decoder(opj_dinfo_t *dinfo, opj_dparameters_t *parameters) {
  110.         if(dinfo && parameters) {
  111.                 if (dinfo->codec_format != CODEC_UNKNOWN) {
  112.                         j3d_setup_decoder((opj_j3d_t*)dinfo->j3d_handle, parameters);
  113.                 }
  114.         }
  115. }
  116.  
  117. opj_volume_t* OPJ_CALLCONV opj_decode(opj_dinfo_t *dinfo, opj_cio_t *cio) {
  118.         if(dinfo && cio) {
  119.                 if (dinfo->codec_format != CODEC_UNKNOWN) {
  120.                         return j3d_decode((opj_j3d_t*)dinfo->j3d_handle, cio);
  121.                 }
  122.         }
  123.  
  124.         return NULL;
  125. }
  126.  
  127. opj_cinfo_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT format) {
  128.         opj_cinfo_t *cinfo = (opj_cinfo_t*)opj_malloc(sizeof(opj_cinfo_t));
  129.         if(!cinfo) return NULL;
  130.         cinfo->is_decompressor = false;
  131.         switch(format) {
  132.                 case CODEC_J3D:
  133.                 case CODEC_J2K:
  134.                         /* get a J3D coder handle */
  135.                         cinfo->j3d_handle = (void*)j3d_create_compress((opj_common_ptr)cinfo);
  136.                         if(!cinfo->j3d_handle) {
  137.                                 opj_free(cinfo);
  138.                                 return NULL;
  139.                         }
  140.                         break;
  141.                 default:
  142.                         opj_free(cinfo);
  143.                         return NULL;
  144.         }
  145.  
  146.         cinfo->codec_format = format;
  147.  
  148.         return cinfo;
  149. }
  150.  
  151. void OPJ_CALLCONV opj_destroy_compress(opj_cinfo_t *cinfo) {
  152.         if(cinfo) {
  153.                 /* destroy the codec */
  154.                 if (cinfo->codec_format != CODEC_UNKNOWN) {
  155.                                 j3d_destroy_compress((opj_j3d_t*)cinfo->j3d_handle);
  156.                 }
  157.                 /* destroy the decompressor */
  158.                 opj_free(cinfo);
  159.         }
  160. }
  161.  
  162. void OPJ_CALLCONV opj_set_default_encoder_parameters(opj_cparameters_t *parameters) {
  163.         if(parameters) {
  164.                 memset(parameters, 0, sizeof(opj_cparameters_t));
  165.                 /* default coding parameters */
  166.                 parameters->numresolution[0] = 3;
  167.                 parameters->numresolution[1] = 3;
  168.                 parameters->numresolution[2] = 1;
  169.                 parameters->cblock_init[0] = 64;
  170.                 parameters->cblock_init[1] = 64;
  171.                 parameters->cblock_init[2] = 64;
  172.                 parameters->prog_order = LRCP;
  173.                 parameters->roi_compno = -1;            /* no ROI */
  174.                 parameters->atk_wt[0] = 1;                              /* 5-3 WT */
  175.                 parameters->atk_wt[1] = 1;                              /* 5-3 WT */
  176.                 parameters->atk_wt[2] = 1;                              /* 5-3 WT */
  177.                 parameters->irreversible = 0;
  178.                 parameters->subsampling_dx = 1;
  179.                 parameters->subsampling_dy = 1;
  180.                 parameters->subsampling_dz = 1;
  181.  
  182.                 parameters->decod_format = -1;
  183.                 parameters->cod_format = -1;
  184.                 parameters->encoding_format = ENCOD_2EB;
  185.                 parameters->transform_format = TRF_2D_DWT;
  186.         }
  187. }
  188.  
  189. void OPJ_CALLCONV opj_setup_encoder(opj_cinfo_t *cinfo, opj_cparameters_t *parameters, opj_volume_t *volume) {
  190.         if(cinfo && parameters && volume) {
  191.                 if (cinfo->codec_format != CODEC_UNKNOWN) {
  192.                         j3d_setup_encoder((opj_j3d_t*)cinfo->j3d_handle, parameters, volume);
  193.                 }
  194.         }
  195. }
  196.  
  197. bool OPJ_CALLCONV opj_encode(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_volume_t *volume, char *index) {
  198.         if(cinfo && cio && volume) {
  199.                 if (cinfo->codec_format != CODEC_UNKNOWN) {
  200.                         return j3d_encode((opj_j3d_t*)cinfo->j3d_handle, cio, volume, index);
  201.                 }
  202.         }
  203.  
  204.         return false;
  205. }
  206.  
  207.  
  208.