* fixed one potential leak

* truncated lines to 80 chars


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21271 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus
2007-05-29 19:49:23 +00:00
parent d7a45ca813
commit 13eaf8fa00
@@ -575,8 +575,10 @@ jas_stream_positionIOopen(BPositionIO *positionIO)
memset(stream, 0, sizeof(jas_stream_t)); memset(stream, 0, sizeof(jas_stream_t));
stream->rwlimit_ = -1; stream->rwlimit_ = -1;
stream->obj_=(jas_stream_obj_t *)malloc(sizeof(BPositionIO*)); stream->obj_=(jas_stream_obj_t *)malloc(sizeof(BPositionIO*));
if (stream->obj_ == (jas_stream_obj_t *)NULL) if (stream->obj_ == (jas_stream_obj_t *)NULL) {
free(stream);
return (jas_stream_t *)NULL; return (jas_stream_t *)NULL;
}
*((BPositionIO**)stream->obj_) = positionIO; *((BPositionIO**)stream->obj_) = positionIO;
stream->ops_ = (&positionIOops); stream->ops_ = (&positionIOops);
@@ -669,7 +671,8 @@ SSlider::UpdateText() const
} }
//! BSlider::ResizeToPreferred + Resize width if it's too small to show label and status //! BSlider::ResizeToPreferred + Resize width if it's too small to show label
// and status
void void
SSlider::ResizeToPreferred() SSlider::ResizeToPreferred()
{ {
@@ -857,7 +860,8 @@ TranslatorAboutView::TranslatorAboutView(const char *name, float x, float y)
strlcpy(text, current, sizeof(text)); strlcpy(text, current, sizeof(text));
current = NULL; current = NULL;
} else { } else {
strlcpy(text, current, min_c((int32)sizeof(text), newLine + 1 - current)); strlcpy(text, current, min_c((int32)sizeof(text),
newLine + 1 - current));
current = newLine + 1; current = newLine + 1;
} }
@@ -890,7 +894,8 @@ TranslatorView::TranslatorView(const char *name)
font_height fontHeight; font_height fontHeight;
GetFontHeight(&fontHeight); GetFontHeight(&fontHeight);
fTabHeight = (int32)ceilf(fontHeight.ascent + fontHeight.descent + fontHeight.leading) + 7; fTabHeight = (int32)ceilf(fontHeight.ascent + fontHeight.descent
+ fontHeight.leading) + 7;
// Add left and top margins // Add left and top margins
float top = fTabHeight + 20; float top = fTabHeight + 20;
float left = 0; float left = 0;
@@ -1072,12 +1077,15 @@ MakeConfig(BMessage *ioExtension, BView **outView, BRect *outExtent)
//! Determine whether or not we can handle this data //! Determine whether or not we can handle this data
status_t status_t
Identify(BPositionIO *inSource, const translation_format *inFormat, BMessage *ioExtension, translator_info *outInfo, uint32 outType) Identify(BPositionIO *inSource, const translation_format *inFormat,
BMessage *ioExtension, translator_info *outInfo, uint32 outType)
{ {
if ((outType != 0) && (outType != B_TRANSLATOR_BITMAP) && outType != JP2_FORMAT) if ((outType != 0) && (outType != B_TRANSLATOR_BITMAP)
&& outType != JP2_FORMAT)
return B_NO_TRANSLATOR; return B_NO_TRANSLATOR;
// !!! You might need to make this buffer bigger to test for your native format // !!! You might need to make this buffer bigger to test for your
// native format
off_t position = inSource->Position(); off_t position = inSource->Position();
uint8 header[sizeof(TranslatorBitmap)]; uint8 header[sizeof(TranslatorBitmap)];
status_t err = inSource->Read(header, sizeof(TranslatorBitmap)); status_t err = inSource->Read(header, sizeof(TranslatorBitmap));
@@ -1085,7 +1093,8 @@ Identify(BPositionIO *inSource, const translation_format *inFormat, BMessage *io
if (err < B_OK) if (err < B_OK)
return err; return err;
if (B_BENDIAN_TO_HOST_INT32(((TranslatorBitmap *)header)->magic) == B_TRANSLATOR_BITMAP) { if (B_BENDIAN_TO_HOST_INT32(((TranslatorBitmap *)header)->magic)
== B_TRANSLATOR_BITMAP) {
outInfo->type = inputFormats[1].type; outInfo->type = inputFormats[1].type;
outInfo->translator = 0; outInfo->translator = 0;
outInfo->group = inputFormats[1].group; outInfo->group = inputFormats[1].group;
@@ -1094,8 +1103,10 @@ Identify(BPositionIO *inSource, const translation_format *inFormat, BMessage *io
strcpy(outInfo->name, inputFormats[1].name); strcpy(outInfo->name, inputFormats[1].name);
strcpy(outInfo->MIME, inputFormats[1].MIME); strcpy(outInfo->MIME, inputFormats[1].MIME);
} else { } else {
if ((((header[4] << 24) | (header[5] << 16) | (header[6] << 8) | header[7]) == JP2_BOX_JP) || // JP2 if ((((header[4] << 24) | (header[5] << 16) | (header[6] << 8)
(header[0] == (JPC_MS_SOC >> 8) && header[1] == (JPC_MS_SOC & 0xff))) // JPC | header[7]) == JP2_BOX_JP) // JP2
|| (header[0] == (JPC_MS_SOC >> 8) && header[1]
== (JPC_MS_SOC & 0xff))) // JPC
{ {
outInfo->type = inputFormats[0].type; outInfo->type = inputFormats[0].type;
outInfo->translator = 0; outInfo->translator = 0;
@@ -1115,7 +1126,8 @@ Identify(BPositionIO *inSource, const translation_format *inFormat, BMessage *io
//! Arguably the most important method in the add-on //! Arguably the most important method in the add-on
status_t status_t
Translate(BPositionIO *inSource, const translator_info *inInfo, BMessage *ioExtension, uint32 outType, BPositionIO *outDestination) Translate(BPositionIO *inSource, const translator_info *inInfo,
BMessage *ioExtension, uint32 outType, BPositionIO *outDestination)
{ {
// If no specific type was requested, convert to the interchange format // If no specific type was requested, convert to the interchange format
if (outType == 0) if (outType == 0)
@@ -1199,7 +1211,8 @@ Compress(BPositionIO *in, BPositionIO *out)
// Function pointer to write function // Function pointer to write function
// It MUST point to proper function // It MUST point to proper function
void (*converter)(jas_matrix_t **pixels, jpr_uchar_t *inscanline, int width) = write_rgba32; void (*converter)(jas_matrix_t **pixels, jpr_uchar_t *inscanline,
int width) = write_rgba32;
// Default color info // Default color info
int out_color_space = JAS_IMAGE_CS_RGB; int out_color_space = JAS_IMAGE_CS_RGB;
@@ -1312,7 +1325,8 @@ Compress(BPositionIO *in, BPositionIO *out)
component_info[i].prec = (unsigned int)8; component_info[i].prec = (unsigned int)8;
} }
image = jas_image_create((short)out_color_components, component_info, out_color_space); image = jas_image_create((short)out_color_components, component_info,
out_color_space);
if (image == (jas_image_t *)NULL) if (image == (jas_image_t *)NULL)
return Error(outs, NULL, NULL, 0, NULL, B_ERROR); return Error(outs, NULL, NULL, 0, NULL, B_ERROR);
@@ -1329,19 +1343,28 @@ Compress(BPositionIO *in, BPositionIO *out)
int32 y = 0; int32 y = 0;
for (y = 0; y < (long)height; y++) { for (y = 0; y < (long)height; y++) {
err = in->Read(in_scanline, in_row_bytes); err = in->Read(in_scanline, in_row_bytes);
if (err < in_row_bytes) if (err < in_row_bytes) {
return (err < B_OK) ? Error(outs, image, pixels, out_color_components, in_scanline, err) : Error(outs, image, pixels, out_color_components, in_scanline, B_ERROR); return (err < B_OK) ?
Error(outs, image, pixels, out_color_components, in_scanline,
err)
: Error(outs, image, pixels, out_color_components, in_scanline,
B_ERROR);
}
converter(pixels, in_scanline, width); converter(pixels, in_scanline, width);
for (i = 0; i < (long)out_color_components; i++) for (i = 0; i < (long)out_color_components; i++) {
(void)jas_image_writecmpt(image, (short)i, 0, (unsigned int)y, (unsigned int)width, 1, pixels[i]); (void)jas_image_writecmpt(image, (short)i, 0, (unsigned int)y,
(unsigned int)width, 1, pixels[i]);
}
} }
char opts[16]; char opts[16];
sprintf(opts, "rate=%1f", (float)settings.Quality / 100.0); sprintf(opts, "rate=%1f", (float)settings.Quality / 100.0);
if (jas_image_encode(image, outs, jas_image_strtofmt(settings.JPC ? (char*)"jpc" : (char*)"jp2"), opts)) if (jas_image_encode(image, outs, jas_image_strtofmt(settings.JPC ?
(char*)"jpc" : (char*)"jp2"), opts)) {
return Error(outs, image, pixels, out_color_components, in_scanline, err); return Error(outs, image, pixels, out_color_components, in_scanline, err);
}
free(in_scanline); free(in_scanline);
@@ -1383,7 +1406,8 @@ Decompress(BPositionIO *in, BPositionIO *out)
// Function pointer to read function // Function pointer to read function
// It MUST point to proper function // It MUST point to proper function
void (*converter)(jas_matrix_t **pixels, jpr_uchar_t *outscanline, int width) = NULL; void (*converter)(jas_matrix_t **pixels, jpr_uchar_t *outscanline,
int width) = NULL;
switch (jas_image_colorspace(image)) { switch (jas_image_colorspace(image)) {
case JAS_IMAGE_CS_RGB: case JAS_IMAGE_CS_RGB:
@@ -1395,7 +1419,8 @@ Decompress(BPositionIO *in, BPositionIO *out)
out_color_space = B_RGBA32; out_color_space = B_RGBA32;
converter = read_rgba32; converter = read_rgba32;
} else { } else {
(new BAlert("Error", "Other than RGB with 3 or 4 color components not implemented.", "Quit"))->Go(); (new BAlert("Error", "Other than RGB with 3 or 4 color "
"components not implemented.", "Quit"))->Go();
return Error(ins, image, NULL, 0, NULL, B_ERROR); return Error(ins, image, NULL, 0, NULL, B_ERROR);
} }
break; break;
@@ -1411,7 +1436,8 @@ Decompress(BPositionIO *in, BPositionIO *out)
} }
break; break;
case JAS_IMAGE_CS_YCBCR: case JAS_IMAGE_CS_YCBCR:
(new BAlert("Error", "color space YCBCR not implemented yet.", "Quit"))->Go(); (new BAlert("Error", "color space YCBCR not implemented yet.",
"Quit"))->Go();
return Error(ins, image, NULL, 0, NULL, B_ERROR); return Error(ins, image, NULL, 0, NULL, B_ERROR);
break; break;
case JAS_IMAGE_CS_UNKNOWN: case JAS_IMAGE_CS_UNKNOWN:
@@ -1462,14 +1488,21 @@ Decompress(BPositionIO *in, BPositionIO *out)
int32 y = 0; int32 y = 0;
for (y = 0; y < (long)height; y++) { for (y = 0; y < (long)height; y++) {
for (i = 0; i < (long)in_color_components; i++) for (i = 0; i < (long)in_color_components; i++) {
(void)jas_image_readcmpt(image, (short)i, 0, (unsigned int)y, (unsigned int)width, 1, pixels[i]); (void)jas_image_readcmpt(image, (short)i, 0, (unsigned int)y,
(unsigned int)width, 1, pixels[i]);
}
converter(pixels, out_scanline, (int32)width); converter(pixels, out_scanline, (int32)width);
err = out->Write(out_scanline, out_row_bytes); err = out->Write(out_scanline, out_row_bytes);
if (err < out_row_bytes) if (err < out_row_bytes) {
return (err < B_OK) ? Error(ins, image, pixels, in_color_components, out_scanline, err) : Error(ins, image, pixels, in_color_components, out_scanline, B_ERROR); return (err < B_OK) ?
Error(ins, image, pixels, in_color_components, out_scanline,
err)
: Error(ins, image, pixels, in_color_components, out_scanline,
B_ERROR);
}
} }
free(out_scanline); free(out_scanline);
@@ -1490,7 +1523,8 @@ Decompress(BPositionIO *in, BPositionIO *out)
Returns given error (B_ERROR by default) Returns given error (B_ERROR by default)
*/ */
status_t status_t
Error(jas_stream_t *stream, jas_image_t *image, jas_matrix_t **pixels, int32 pixels_count, jpr_uchar_t *scanline, status_t error) Error(jas_stream_t *stream, jas_image_t *image, jas_matrix_t **pixels,
int32 pixels_count, jpr_uchar_t *scanline, status_t error)
{ {
if (pixels) { if (pixels) {
int32 i; int32 i;