Lines Matching refs:cube_info
438 const CubeInfo *cube_info,const Quantum *pixel,DoublePixelInfo *alpha_pixel) in AssociateAlphaPixel() argument
443 if ((cube_info->associate_alpha == MagickFalse) || in AssociateAlphaPixel()
459 static inline void AssociateAlphaPixelInfo(const CubeInfo *cube_info, in AssociateAlphaPixelInfo() argument
465 if ((cube_info->associate_alpha == MagickFalse) || in AssociateAlphaPixelInfo()
481 static inline size_t ColorToNodeId(const CubeInfo *cube_info, in ColorToNodeId() argument
490 if (cube_info->associate_alpha != MagickFalse) in ColorToNodeId()
495 static MagickBooleanType AssignImageColors(Image *image,CubeInfo *cube_info, in AssignImageColors() argument
506 if ((cube_info->quantize_info->colorspace != UndefinedColorspace) && in AssignImageColors()
507 (cube_info->quantize_info->colorspace != CMYKColorspace)) in AssignImageColors()
508 (void) TransformImageColorspace(image,cube_info->quantize_info->colorspace, in AssignImageColors()
513 if (AcquireImageColormap(image,cube_info->colors,exception) == MagickFalse) in AssignImageColors()
517 cube_info->transparent_pixels=0; in AssignImageColors()
518 cube_info->transparent_index=(-1); in AssignImageColors()
519 (void) DefineImageColormap(image,cube_info,cube_info->root); in AssignImageColors()
523 if (cube_info->quantize_info->dither_method != NoDitherMethod) in AssignImageColors()
524 (void) DitherImage(image,cube_info,exception); in AssignImageColors()
562 cube=(*cube_info); in AssignImageColors()
644 if (cube_info->quantize_info->measure_error != MagickFalse) in AssignImageColors()
646 if ((cube_info->quantize_info->number_colors == 2) && in AssignImageColors()
647 (cube_info->quantize_info->colorspace == GRAYColorspace)) in AssignImageColors()
671 if ((cube_info->quantize_info->colorspace != UndefinedColorspace) && in AssignImageColors()
672 (cube_info->quantize_info->colorspace != CMYKColorspace)) in AssignImageColors()
738 static inline void SetAssociatedAlpha(const Image *image,CubeInfo *cube_info) in SetAssociatedAlpha() argument
745 if ((cube_info->quantize_info->number_colors == 2) && in SetAssociatedAlpha()
746 (cube_info->quantize_info->colorspace == GRAYColorspace)) in SetAssociatedAlpha()
748 cube_info->associate_alpha=associate_alpha; in SetAssociatedAlpha()
751 static MagickBooleanType ClassifyImageColors(CubeInfo *cube_info, in ClassifyImageColors() argument
786 SetAssociatedAlpha(image,cube_info); in ClassifyImageColors()
787 if ((cube_info->quantize_info->colorspace != UndefinedColorspace) && in ClassifyImageColors()
788 (cube_info->quantize_info->colorspace != CMYKColorspace)) in ClassifyImageColors()
790 cube_info->quantize_info->colorspace,exception); in ClassifyImageColors()
811 if (cube_info->nodes > MaxNodes) in ClassifyImageColors()
816 PruneLevel(cube_info,cube_info->root); in ClassifyImageColors()
817 cube_info->depth--; in ClassifyImageColors()
833 AssociateAlphaPixel(image,cube_info,p,&pixel); in ClassifyImageColors()
837 node_info=cube_info->root; in ClassifyImageColors()
844 id=ColorToNodeId(cube_info,&pixel,index); in ClassifyImageColors()
854 node_info->child[id]=GetNodeInfo(cube_info,id,level,node_info); in ClassifyImageColors()
863 cube_info->colors++; in ClassifyImageColors()
872 if (cube_info->associate_alpha != MagickFalse) in ClassifyImageColors()
879 cube_info->root->quantize_error+=node_info->quantize_error; in ClassifyImageColors()
889 if (cube_info->associate_alpha != MagickFalse) in ClassifyImageColors()
897 if (cube_info->colors > cube_info->maximum_colors) in ClassifyImageColors()
899 PruneToCubeDepth(cube_info,cube_info->root); in ClassifyImageColors()
918 if (cube_info->nodes > MaxNodes) in ClassifyImageColors()
923 PruneLevel(cube_info,cube_info->root); in ClassifyImageColors()
924 cube_info->depth--; in ClassifyImageColors()
940 AssociateAlphaPixel(image,cube_info,p,&pixel); in ClassifyImageColors()
944 node_info=cube_info->root; in ClassifyImageColors()
945 for (level=1; level <= cube_info->depth; level++) in ClassifyImageColors()
951 id=ColorToNodeId(cube_info,&pixel,index); in ClassifyImageColors()
961 node_info->child[id]=GetNodeInfo(cube_info,id,level,node_info); in ClassifyImageColors()
969 if (level == cube_info->depth) in ClassifyImageColors()
970 cube_info->colors++; in ClassifyImageColors()
979 if (cube_info->associate_alpha != MagickFalse) in ClassifyImageColors()
986 cube_info->root->quantize_error+=node_info->quantize_error; in ClassifyImageColors()
996 if (cube_info->associate_alpha != MagickFalse) in ClassifyImageColors()
1010 if ((cube_info->quantize_info->colorspace != UndefinedColorspace) && in ClassifyImageColors()
1011 (cube_info->quantize_info->colorspace != CMYKColorspace)) in ClassifyImageColors()
1090 static void ClosestColor(const Image *image,CubeInfo *cube_info, in ClosestColor() argument
1102 number_children=cube_info->associate_alpha == MagickFalse ? 8UL : 16UL; in ClosestColor()
1105 ClosestColor(image,cube_info,node_info->child[i]); in ClosestColor()
1126 q=(&cube_info->target); in ClosestColor()
1129 if (cube_info->associate_alpha != MagickFalse) in ClosestColor()
1136 if (distance <= cube_info->distance) in ClosestColor()
1140 if (distance <= cube_info->distance) in ClosestColor()
1144 if (distance <= cube_info->distance) in ClosestColor()
1146 if (cube_info->associate_alpha != MagickFalse) in ClosestColor()
1151 if (distance <= cube_info->distance) in ClosestColor()
1153 cube_info->distance=distance; in ClosestColor()
1154 cube_info->color_number=node_info->color_number; in ClosestColor()
1237 static size_t DefineImageColormap(Image *image,CubeInfo *cube_info, in DefineImageColormap() argument
1249 number_children=cube_info->associate_alpha == MagickFalse ? 8UL : 16UL; in DefineImageColormap()
1252 (void) DefineImageColormap(image,cube_info,node_info->child[i]); in DefineImageColormap()
1267 if (cube_info->associate_alpha == MagickFalse) in DefineImageColormap()
1306 if (node_info->number_unique > cube_info->transparent_pixels) in DefineImageColormap()
1308 cube_info->transparent_pixels=node_info->number_unique; in DefineImageColormap()
1309 cube_info->transparent_index=(ssize_t) image->colors; in DefineImageColormap()
1340 static void DestroyCubeInfo(CubeInfo *cube_info) in DestroyCubeInfo() argument
1350 nodes=cube_info->node_queue->next; in DestroyCubeInfo()
1351 cube_info->node_queue->nodes=(NodeInfo *) RelinquishMagickMemory( in DestroyCubeInfo()
1352 cube_info->node_queue->nodes); in DestroyCubeInfo()
1353 cube_info->node_queue=(Nodes *) RelinquishMagickMemory( in DestroyCubeInfo()
1354 cube_info->node_queue); in DestroyCubeInfo()
1355 cube_info->node_queue=nodes; in DestroyCubeInfo()
1356 } while (cube_info->node_queue != (Nodes *) NULL); in DestroyCubeInfo()
1357 if (cube_info->memory_info != (MemoryInfo *) NULL) in DestroyCubeInfo()
1358 cube_info->memory_info=RelinquishVirtualMemory(cube_info->memory_info); in DestroyCubeInfo()
1359 cube_info->quantize_info=DestroyQuantizeInfo(cube_info->quantize_info); in DestroyCubeInfo()
1360 cube_info=(CubeInfo *) RelinquishMagickMemory(cube_info); in DestroyCubeInfo()
1467 static inline ssize_t CacheOffset(CubeInfo *cube_info, in CacheOffset() argument
1481 if (cube_info->associate_alpha != MagickFalse) in CacheOffset()
1486 static MagickBooleanType FloydSteinbergDither(Image *image,CubeInfo *cube_info, in FloydSteinbergDither() argument
1543 cube=(*cube_info); in FloydSteinbergDither()
1677 static void Riemersma(Image *image,CacheView *image_view,CubeInfo *cube_info, in Riemersma() argument
1685 (void) RiemersmaDither(image,image_view,cube_info,EastGravity, in Riemersma()
1687 (void) RiemersmaDither(image,image_view,cube_info,SouthGravity, in Riemersma()
1689 (void) RiemersmaDither(image,image_view,cube_info,WestGravity, in Riemersma()
1695 (void) RiemersmaDither(image,image_view,cube_info,WestGravity, in Riemersma()
1697 (void) RiemersmaDither(image,image_view,cube_info,NorthGravity, in Riemersma()
1699 (void) RiemersmaDither(image,image_view,cube_info,EastGravity, in Riemersma()
1705 (void) RiemersmaDither(image,image_view,cube_info,SouthGravity, in Riemersma()
1707 (void) RiemersmaDither(image,image_view,cube_info,EastGravity, in Riemersma()
1709 (void) RiemersmaDither(image,image_view,cube_info,NorthGravity, in Riemersma()
1715 (void) RiemersmaDither(image,image_view,cube_info,NorthGravity, in Riemersma()
1717 (void) RiemersmaDither(image,image_view,cube_info,WestGravity, in Riemersma()
1719 (void) RiemersmaDither(image,image_view,cube_info,SouthGravity, in Riemersma()
1731 Riemersma(image,image_view,cube_info,level-1,NorthGravity, in Riemersma()
1733 (void) RiemersmaDither(image,image_view,cube_info,EastGravity, in Riemersma()
1735 Riemersma(image,image_view,cube_info,level-1,WestGravity, in Riemersma()
1737 (void) RiemersmaDither(image,image_view,cube_info,SouthGravity, in Riemersma()
1739 Riemersma(image,image_view,cube_info,level-1,WestGravity, in Riemersma()
1741 (void) RiemersmaDither(image,image_view,cube_info,WestGravity, in Riemersma()
1743 Riemersma(image,image_view,cube_info,level-1,SouthGravity, in Riemersma()
1749 Riemersma(image,image_view,cube_info,level-1,SouthGravity, in Riemersma()
1751 (void) RiemersmaDither(image,image_view,cube_info,WestGravity, in Riemersma()
1753 Riemersma(image,image_view,cube_info,level-1,EastGravity, in Riemersma()
1755 (void) RiemersmaDither(image,image_view,cube_info,NorthGravity, in Riemersma()
1757 Riemersma(image,image_view,cube_info,level-1,EastGravity, in Riemersma()
1759 (void) RiemersmaDither(image,image_view,cube_info,EastGravity, in Riemersma()
1761 Riemersma(image,image_view,cube_info,level-1,NorthGravity, in Riemersma()
1767 Riemersma(image,image_view,cube_info,level-1,WestGravity, in Riemersma()
1769 (void) RiemersmaDither(image,image_view,cube_info,SouthGravity, in Riemersma()
1771 Riemersma(image,image_view,cube_info,level-1,NorthGravity, in Riemersma()
1773 (void) RiemersmaDither(image,image_view,cube_info,EastGravity, in Riemersma()
1775 Riemersma(image,image_view,cube_info,level-1,NorthGravity, in Riemersma()
1777 (void) RiemersmaDither(image,image_view,cube_info,NorthGravity, in Riemersma()
1779 Riemersma(image,image_view,cube_info,level-1,EastGravity, in Riemersma()
1785 Riemersma(image,image_view,cube_info,level-1,EastGravity, in Riemersma()
1787 (void) RiemersmaDither(image,image_view,cube_info,NorthGravity, in Riemersma()
1789 Riemersma(image,image_view,cube_info,level-1,SouthGravity, in Riemersma()
1791 (void) RiemersmaDither(image,image_view,cube_info,WestGravity, in Riemersma()
1793 Riemersma(image,image_view,cube_info,level-1,SouthGravity, in Riemersma()
1795 (void) RiemersmaDither(image,image_view,cube_info,SouthGravity, in Riemersma()
1797 Riemersma(image,image_view,cube_info,level-1,WestGravity, in Riemersma()
1807 CubeInfo *cube_info,const unsigned int direction,ExceptionInfo *exception) in RiemersmaDither() argument
1824 p=cube_info; in RiemersmaDither()
1840 AssociateAlphaPixel(image,cube_info,q,&pixel); in RiemersmaDither()
1846 if (cube_info->associate_alpha != MagickFalse) in RiemersmaDither()
1852 if (cube_info->associate_alpha != MagickFalse) in RiemersmaDither()
1854 i=CacheOffset(cube_info,&pixel); in RiemersmaDither()
1869 id=ColorToNodeId(cube_info,&pixel,index); in RiemersmaDither()
1889 if (cube_info->quantize_info->measure_error == MagickFalse) in RiemersmaDither()
1894 if (cube_info->associate_alpha != MagickFalse) in RiemersmaDither()
1904 AssociateAlphaPixelInfo(cube_info,image->colormap+index,&color); in RiemersmaDither()
1908 if (cube_info->associate_alpha != MagickFalse) in RiemersmaDither()
1925 static MagickBooleanType DitherImage(Image *image,CubeInfo *cube_info, in DitherImage() argument
1940 if (cube_info->quantize_info->dither_method != RiemersmaDitherMethod) in DitherImage()
1941 return(FloydSteinbergDither(image,cube_info,exception)); in DitherImage()
1945 (void) ResetMagickMemory(cube_info->error,0,ErrorQueueLength* in DitherImage()
1946 sizeof(*cube_info->error)); in DitherImage()
1947 cube_info->x=0; in DitherImage()
1948 cube_info->y=0; in DitherImage()
1954 cube_info->offset=0; in DitherImage()
1955 cube_info->span=(MagickSizeType) image->columns*image->rows; in DitherImage()
1958 Riemersma(image,image_view,cube_info,depth-1,NorthGravity,exception); in DitherImage()
1959 status=RiemersmaDither(image,image_view,cube_info,ForgetGravity,exception); in DitherImage()
2002 *cube_info; in GetCubeInfo() local
2017 cube_info=(CubeInfo *) AcquireMagickMemory(sizeof(*cube_info)); in GetCubeInfo()
2018 if (cube_info == (CubeInfo *) NULL) in GetCubeInfo()
2020 (void) ResetMagickMemory(cube_info,0,sizeof(*cube_info)); in GetCubeInfo()
2021 cube_info->depth=depth; in GetCubeInfo()
2022 if (cube_info->depth > MaxTreeDepth) in GetCubeInfo()
2023 cube_info->depth=MaxTreeDepth; in GetCubeInfo()
2024 if (cube_info->depth < 2) in GetCubeInfo()
2025 cube_info->depth=2; in GetCubeInfo()
2026 cube_info->maximum_colors=maximum_colors; in GetCubeInfo()
2030 cube_info->root=GetNodeInfo(cube_info,0,0,(NodeInfo *) NULL); in GetCubeInfo()
2031 if (cube_info->root == (NodeInfo *) NULL) in GetCubeInfo()
2033 cube_info->root->parent=cube_info->root; in GetCubeInfo()
2034 cube_info->quantize_info=CloneQuantizeInfo(quantize_info); in GetCubeInfo()
2035 if (cube_info->quantize_info->dither_method == NoDitherMethod) in GetCubeInfo()
2036 return(cube_info); in GetCubeInfo()
2041 cube_info->memory_info=AcquireVirtualMemory(length,sizeof(*cube_info->cache)); in GetCubeInfo()
2042 if (cube_info->memory_info == (MemoryInfo *) NULL) in GetCubeInfo()
2044 cube_info->cache=(ssize_t *) GetVirtualMemoryBlob(cube_info->memory_info); in GetCubeInfo()
2048 (void) ResetMagickMemory(cube_info->cache,(-1),sizeof(*cube_info->cache)* in GetCubeInfo()
2056 cube_info->weights[ErrorQueueLength-i-1]=PerceptibleReciprocal(weight); in GetCubeInfo()
2064 weight+=cube_info->weights[i]; in GetCubeInfo()
2068 cube_info->weights[i]/=weight; in GetCubeInfo()
2069 sum+=cube_info->weights[i]; in GetCubeInfo()
2071 cube_info->weights[0]+=1.0-sum; in GetCubeInfo()
2072 return(cube_info); in GetCubeInfo()
2103 static NodeInfo *GetNodeInfo(CubeInfo *cube_info,const size_t id, in GetNodeInfo() argument
2109 if (cube_info->free_nodes == 0) in GetNodeInfo()
2124 nodes->next=cube_info->node_queue; in GetNodeInfo()
2125 cube_info->node_queue=nodes; in GetNodeInfo()
2126 cube_info->next_node=nodes->nodes; in GetNodeInfo()
2127 cube_info->free_nodes=NodesInAList; in GetNodeInfo()
2129 cube_info->nodes++; in GetNodeInfo()
2130 cube_info->free_nodes--; in GetNodeInfo()
2131 node_info=cube_info->next_node++; in GetNodeInfo()
2490 static void PruneChild(CubeInfo *cube_info,const NodeInfo *node_info) in PruneChild() argument
2504 number_children=cube_info->associate_alpha == MagickFalse ? 8UL : 16UL; in PruneChild()
2507 PruneChild(cube_info,node_info->child[i]); in PruneChild()
2518 cube_info->nodes--; in PruneChild()
2546 static void PruneLevel(CubeInfo *cube_info,const NodeInfo *node_info) in PruneLevel() argument
2557 number_children=cube_info->associate_alpha == MagickFalse ? 8UL : 16UL; in PruneLevel()
2560 PruneLevel(cube_info,node_info->child[i]); in PruneLevel()
2561 if (node_info->level == cube_info->depth) in PruneLevel()
2562 PruneChild(cube_info,node_info); in PruneLevel()
2591 static void PruneToCubeDepth(CubeInfo *cube_info,const NodeInfo *node_info) in PruneToCubeDepth() argument
2602 number_children=cube_info->associate_alpha == MagickFalse ? 8UL : 16UL; in PruneToCubeDepth()
2605 PruneToCubeDepth(cube_info,node_info->child[i]); in PruneToCubeDepth()
2606 if (node_info->level > cube_info->depth) in PruneToCubeDepth()
2607 PruneChild(cube_info,node_info); in PruneToCubeDepth()
2644 *cube_info; in QuantizeImage() local
2702 cube_info=GetCubeInfo(quantize_info,depth,maximum_colors); in QuantizeImage()
2703 if (cube_info == (CubeInfo *) NULL) in QuantizeImage()
2706 status=ClassifyImageColors(cube_info,image,exception); in QuantizeImage()
2713 if (cube_info->colors > cube_info->maximum_colors) in QuantizeImage()
2714 ReduceImageColors(image,cube_info); in QuantizeImage()
2716 cube_info->quantize_info->dither_method=NoDitherMethod; in QuantizeImage()
2717 status=AssignImageColors(image,cube_info,exception); in QuantizeImage()
2719 DestroyCubeInfo(cube_info); in QuantizeImage()
2757 *cube_info; in QuantizeImages() local
2817 cube_info=GetCubeInfo(quantize_info,depth,maximum_colors); in QuantizeImages()
2818 if (cube_info == (CubeInfo *) NULL) in QuantizeImages()
2830 status=ClassifyImageColors(cube_info,image,exception); in QuantizeImages()
2845 ReduceImageColors(images,cube_info); in QuantizeImages()
2851 status=AssignImageColors(image,cube_info,exception); in QuantizeImages()
2863 DestroyCubeInfo(cube_info); in QuantizeImages()
2900 static size_t QuantizeErrorFlatten(const CubeInfo *cube_info, in QuantizeErrorFlatten() argument
2910 if (offset >= (ssize_t) cube_info->nodes) in QuantizeErrorFlatten()
2914 number_children=cube_info->associate_alpha == MagickFalse ? 8UL : 16UL; in QuantizeErrorFlatten()
2917 n+=QuantizeErrorFlatten(cube_info,node_info->child[i],offset+n, in QuantizeErrorFlatten()
2947 static void Reduce(CubeInfo *cube_info,const NodeInfo *node_info) in Reduce() argument
2958 number_children=cube_info->associate_alpha == MagickFalse ? 8UL : 16UL; in Reduce()
2961 Reduce(cube_info,node_info->child[i]); in Reduce()
2962 if (node_info->quantize_error <= cube_info->pruning_threshold) in Reduce()
2963 PruneChild(cube_info,node_info); in Reduce()
2970 cube_info->colors++; in Reduce()
2971 if (node_info->quantize_error < cube_info->next_threshold) in Reduce()
2972 cube_info->next_threshold=node_info->quantize_error; in Reduce()
3046 static void ReduceImageColors(const Image *image,CubeInfo *cube_info) in ReduceImageColors() argument
3059 cube_info->next_threshold=0.0; in ReduceImageColors()
3060 if (cube_info->colors > cube_info->maximum_colors) in ReduceImageColors()
3068 quantize_error=(double *) AcquireQuantumMemory(cube_info->nodes, in ReduceImageColors()
3072 (void) QuantizeErrorFlatten(cube_info,cube_info->root,0, in ReduceImageColors()
3074 qsort(quantize_error,cube_info->nodes,sizeof(double), in ReduceImageColors()
3076 if (cube_info->nodes > (110*(cube_info->maximum_colors+1)/100)) in ReduceImageColors()
3077 cube_info->next_threshold=quantize_error[cube_info->nodes-110* in ReduceImageColors()
3078 (cube_info->maximum_colors+1)/100]; in ReduceImageColors()
3082 for (span=cube_info->colors; cube_info->colors > cube_info->maximum_colors; ) in ReduceImageColors()
3084 cube_info->pruning_threshold=cube_info->next_threshold; in ReduceImageColors()
3085 cube_info->next_threshold=cube_info->root->quantize_error-1; in ReduceImageColors()
3086 cube_info->colors=0; in ReduceImageColors()
3087 Reduce(cube_info,cube_info->root); in ReduceImageColors()
3088 offset=(MagickOffsetType) span-cube_info->colors; in ReduceImageColors()
3090 cube_info->maximum_colors+1); in ReduceImageColors()
3130 *cube_info; in RemapImage() local
3146 cube_info=GetCubeInfo(quantize_info,MaxTreeDepth, in RemapImage()
3148 if (cube_info == (CubeInfo *) NULL) in RemapImage()
3151 status=ClassifyImageColors(cube_info,remap_image,exception); in RemapImage()
3157 cube_info->quantize_info->number_colors=cube_info->colors; in RemapImage()
3158 status=AssignImageColors(image,cube_info,exception); in RemapImage()
3160 DestroyCubeInfo(cube_info); in RemapImage()
3198 *cube_info; in RemapImages() local
3224 cube_info=GetCubeInfo(quantize_info,MaxTreeDepth, in RemapImages()
3226 if (cube_info == (CubeInfo *) NULL) in RemapImages()
3229 status=ClassifyImageColors(cube_info,remap_image,exception); in RemapImages()
3235 cube_info->quantize_info->number_colors=cube_info->colors; in RemapImages()
3239 status=AssignImageColors(image,cube_info,exception); in RemapImages()
3244 DestroyCubeInfo(cube_info); in RemapImages()