00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057 #include <stdio.h>
00058 #include <stdlib.h>
00059 #include <string.h>
00060 #include <errno.h>
00061
00062 #include "gwlib/gwlib.h"
00063 #include "OTAbitmap.h"
00064
00065
00066
00067
00068
00069 OTAbitmap *OTAbitmap_create_empty(void)
00070 {
00071 OTAbitmap *new;
00072
00073 new = gw_malloc(sizeof(OTAbitmap));
00074 memset(new, 0, sizeof(OTAbitmap));
00075 return new;
00076 }
00077
00078 void OTAbitmap_delete(OTAbitmap *pic)
00079 {
00080 gw_free(pic->ext_fields);
00081 gw_free(pic->main_image);
00082 if (pic->animated_image) {
00083 int i;
00084 for(i=0; i < pic->animimg_count; i++)
00085 gw_free(pic->animated_image[i]);
00086 gw_free(pic->animated_image);
00087 }
00088 gw_free(pic);
00089 }
00090
00091 OTAbitmap *OTAbitmap_create(int width, int height, int depth,
00092 Octet *data, int flags)
00093 {
00094 OTAbitmap *new;
00095 int i, j, siz, osiz;
00096 Octet val;
00097
00098 new = OTAbitmap_create_empty();
00099
00100 if (width > 255 || height > 255)
00101 new->infofield = 0x10;
00102 else
00103 new->infofield = 0x00;
00104
00105 new->width = width;
00106 new->height = height;
00107
00108 siz = (width * height + 7)/8;
00109
00110 new->main_image = gw_malloc(siz);
00111 osiz = (width+7)/8 * height;
00112 for(i=j=0; i<osiz; i++, j+=8) {
00113 val = data[i];
00114 if (flags & REVERSE) val = reverse_octet(val);
00115 if (flags & NEGATIVE) val = ~val;
00116
00117 if (i > 0 && i % ((width+7)/8) == 0 && width % 8 > 0)
00118 j -= 8 + width % 8;
00119
00120 if (j % 8 == 0) {
00121 new->main_image[j/8] = val;
00122 }
00123 else {
00124 new->main_image[j/8] |= val >> (j % 8);
00125 new->main_image[j/8 + 1] = val << (8 - j % 8);
00126 }
00127 }
00128
00129
00130 return new;
00131 }
00132
00133
00134
00135
00136
00137 int OTAbitmap_create_stream(OTAbitmap *pic, Octet **stream)
00138 {
00139 Octet tmp_header[10];
00140 int hdr_len;
00141 int pic_size;
00142
00143 if (pic->infofield & 0x10) {
00144 sprintf(tmp_header, "%c%c%c%c%c%c", pic->infofield, pic->width/256,
00145 pic->width%256, pic->height/256, pic->height%256, pic->depth);
00146 hdr_len = 6;
00147 } else {
00148 sprintf(tmp_header, "%c%c%c%c", pic->infofield,
00149 pic->width, pic->height, pic->depth);
00150 hdr_len = 4;
00151 }
00152
00153 pic_size = (pic->width * pic->height + 7)/8;
00154
00155 *stream = gw_malloc(pic_size+pic_size);
00156 memcpy(*stream, tmp_header, hdr_len);
00157 memcpy(*stream + hdr_len, pic->main_image, pic_size);
00158
00159 debug("util", 0, "picture %d x %d, stream length %d",
00160 pic->width, pic->height, hdr_len + pic_size);
00161
00162 return (hdr_len + pic_size);
00163 }
See file LICENSE for details about the license agreement for using,
modifying, copying or deriving work from this software.