Kannel: Open Source WAP and SMS gateway  svn-r5335
OTAbitmap.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "gwlib/gwlib.h"
#include "OTAbitmap.h"

Go to the source code of this file.

Functions

OTAbitmapOTAbitmap_create_empty (void)
 
void OTAbitmap_delete (OTAbitmap *pic)
 
OTAbitmapOTAbitmap_create (int width, int height, int depth, Octet *data, int flags)
 
int OTAbitmap_create_stream (OTAbitmap *pic, Octet **stream)
 

Function Documentation

◆ OTAbitmap_create()

OTAbitmap* OTAbitmap_create ( int  width,
int  height,
int  depth,
Octet data,
int  flags 
)

Definition at line 91 of file OTAbitmap.c.

References NEGATIVE, OTAbitmap_create_empty(), REVERSE, and reverse_octet().

93 {
94  OTAbitmap *new;
95  int i, j, siz, osiz;
96  Octet val;
97 
98  new = OTAbitmap_create_empty();
99 
100  if (width > 255 || height > 255)
101  new->infofield = 0x10; /* set bit */
102  else
103  new->infofield = 0x00;
104 
105  new->width = width;
106  new->height = height;
107 
108  siz = (width * height + 7)/8;
109 
110  new->main_image = gw_malloc(siz);
111  osiz = (width+7)/8 * height;
112  for(i=j=0; i<osiz; i++, j+=8) {
113  val = data[i];
114  if (flags & REVERSE) val = reverse_octet(val);
115  if (flags & NEGATIVE) val = ~val;
116 
117  if (i > 0 && i % ((width+7)/8) == 0 && width % 8 > 0)
118  j -= 8 + width % 8;
119 
120  if (j % 8 == 0) {
121  new->main_image[j/8] = val;
122  }
123  else {
124  new->main_image[j/8] |= val >> (j % 8);
125  new->main_image[j/8 + 1] = val << (8 - j % 8);
126  }
127  }
128  /* no palette nor animated images, yet */
129 
130  return new;
131 }
#define NEGATIVE
Definition: OTAbitmap.h:94
#define REVERSE
Definition: OTAbitmap.h:95
Octet reverse_octet(Octet source)
Definition: utils.c:511
OTAbitmap * OTAbitmap_create_empty(void)
Definition: OTAbitmap.c:69
unsigned char Octet
Definition: utils.h:75

◆ OTAbitmap_create_empty()

OTAbitmap* OTAbitmap_create_empty ( void  )

Definition at line 69 of file OTAbitmap.c.

Referenced by OTAbitmap_create().

70 {
71  OTAbitmap *new;
72 
73  new = gw_malloc(sizeof(OTAbitmap));
74  memset(new, 0, sizeof(OTAbitmap));
75  return new;
76 }

◆ OTAbitmap_create_stream()

int OTAbitmap_create_stream ( OTAbitmap pic,
Octet **  stream 
)

Definition at line 137 of file OTAbitmap.c.

References debug(), OTA_bitmap::depth, OTA_bitmap::height, OTA_bitmap::infofield, OTA_bitmap::main_image, and OTA_bitmap::width.

138 {
139  Octet tmp_header[10];
140  int hdr_len;
141  int pic_size;
142 
143  if (pic->infofield & 0x10) {
144  sprintf(tmp_header, "%c%c%c%c%c%c", pic->infofield, pic->width/256,
145  pic->width%256, pic->height/256, pic->height%256, pic->depth);
146  hdr_len = 6;
147  } else {
148  sprintf(tmp_header, "%c%c%c%c", pic->infofield,
149  pic->width, pic->height, pic->depth);
150  hdr_len = 4;
151  }
152 
153  pic_size = (pic->width * pic->height + 7)/8;
154 
155  *stream = gw_malloc(pic_size+pic_size);
156  memcpy(*stream, tmp_header, hdr_len);
157  memcpy(*stream + hdr_len, pic->main_image, pic_size);
158 
159  debug("util", 0, "picture %d x %d, stream length %d",
160  pic->width, pic->height, hdr_len + pic_size);
161 
162  return (hdr_len + pic_size);
163 }
int height
Definition: OTAbitmap.h:76
int depth
Definition: OTAbitmap.h:77
Octet * main_image
Definition: OTAbitmap.h:78
Octet infofield
Definition: OTAbitmap.h:72
int width
Definition: OTAbitmap.h:75
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:726
unsigned char Octet
Definition: utils.h:75

◆ OTAbitmap_delete()

void OTAbitmap_delete ( OTAbitmap pic)

Definition at line 78 of file OTAbitmap.c.

References OTA_bitmap::animated_image, OTA_bitmap::animimg_count, OTA_bitmap::ext_fields, and OTA_bitmap::main_image.

79 {
80  gw_free(pic->ext_fields);
81  gw_free(pic->main_image);
82  if (pic->animated_image) {
83  int i;
84  for(i=0; i < pic->animimg_count; i++)
85  gw_free(pic->animated_image[i]);
86  gw_free(pic->animated_image);
87  }
88  gw_free(pic);
89 }
Octet * ext_fields
Definition: OTAbitmap.h:73
int animimg_count
Definition: OTAbitmap.h:80
Octet * main_image
Definition: OTAbitmap.h:78
Octet ** animated_image
Definition: OTAbitmap.h:79
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.