Panda3D
|
00001 // Filename: pnm-image-filter-core.cxx 00002 // Created by: 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 // We map X and Y to A and B, because we might change our minds about which 00016 // is dominant, and we map get/set functions for the channel in question to 00017 // GETVAL/SETVAL. 00018 00019 00020 static void 00021 FUNCTION_NAME(PNMImage &dest, const PNMImage &source, 00022 double width, FilterFunction *make_filter) { 00023 if (!dest.is_valid() || !source.is_valid()) { 00024 return; 00025 } 00026 00027 // First, set up a 2-d column-major matrix of StoreTypes, big enough to hold 00028 // the image xelvals scaled in the A direction only. This will hold the 00029 // adjusted xel data from our first pass. 00030 00031 typedef StoreType *StoreTypeP; 00032 StoreType **matrix = (StoreType **)PANDA_MALLOC_ARRAY(dest.ASIZE() * sizeof(StoreType *)); 00033 00034 int a, b; 00035 00036 for (a=0; a<dest.ASIZE(); a++) { 00037 matrix[a] = (StoreType *)PANDA_MALLOC_ARRAY(source.BSIZE() * sizeof(StoreType)); 00038 } 00039 00040 // Now, scale the image in the A direction. 00041 double scale = (double)dest.ASIZE() / (double)source.ASIZE(); 00042 00043 StoreType *temp_source = (StoreType *)PANDA_MALLOC_ARRAY(source.ASIZE() * sizeof(StoreType)); 00044 StoreType *temp_dest = (StoreType *)PANDA_MALLOC_ARRAY(dest.ASIZE() * sizeof(StoreType)); 00045 00046 WorkType *filter; 00047 double filter_width; 00048 00049 make_filter(scale, width, filter, filter_width); 00050 00051 for (b=0; b<source.BSIZE(); b++) { 00052 for (a=0; a<source.ASIZE(); a++) { 00053 temp_source[a] = (StoreType)(source_max * source.GETVAL(a, b)); 00054 } 00055 00056 filter_row(temp_dest, dest.ASIZE(), 00057 temp_source, source.ASIZE(), 00058 scale, 00059 filter, filter_width); 00060 00061 for (a=0; a<dest.ASIZE(); a++) { 00062 matrix[a][b] = temp_dest[a]; 00063 } 00064 } 00065 00066 PANDA_FREE_ARRAY(temp_source); 00067 PANDA_FREE_ARRAY(temp_dest); 00068 PANDA_FREE_ARRAY(filter); 00069 00070 // Now, scale the image in the B direction. 00071 scale = (double)dest.BSIZE() / (double)source.BSIZE(); 00072 00073 temp_dest = (StoreType *)PANDA_MALLOC_ARRAY(dest.BSIZE() * sizeof(StoreType)); 00074 00075 make_filter(scale, width, filter, filter_width); 00076 00077 for (a=0; a<dest.ASIZE(); a++) { 00078 00079 filter_row(temp_dest, dest.BSIZE(), 00080 matrix[a], source.BSIZE(), 00081 scale, 00082 filter, filter_width); 00083 00084 for (b=0; b<dest.BSIZE(); b++) { 00085 dest.SETVAL(a, b, (double)temp_dest[b]/(double)source_max); 00086 } 00087 } 00088 00089 PANDA_FREE_ARRAY(temp_dest); 00090 PANDA_FREE_ARRAY(filter); 00091 00092 // Now, clean up our temp matrix and go home! 00093 00094 for (a=0; a<dest.ASIZE(); a++) { 00095 PANDA_FREE_ARRAY(matrix[a]); 00096 } 00097 PANDA_FREE_ARRAY(matrix); 00098 } 00099